My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_api.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /************
  24. * ui_api.h *
  25. ************/
  26. /****************************************************************************
  27. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  28. * *
  29. * This program is free software: you can redistribute it and/or modify *
  30. * it under the terms of the GNU General Public License as published by *
  31. * the Free Software Foundation, either version 3 of the License, or *
  32. * (at your option) any later version. *
  33. * *
  34. * This program is distributed in the hope that it will be useful, *
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  37. * GNU General Public License for more details. *
  38. * *
  39. * To view a copy of the GNU General Public License, go to the following *
  40. * location: <https://www.gnu.org/licenses/>. *
  41. ****************************************************************************/
  42. #include "../../inc/MarlinConfig.h"
  43. namespace ExtUI {
  44. // The ExtUI implementation can store up to this many bytes
  45. // in the EEPROM when the methods onStoreSettings and
  46. // onLoadSettings are called.
  47. static constexpr size_t eeprom_data_size = 48;
  48. enum axis_t : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4 };
  49. enum extruder_t : uint8_t { E0, E1, E2, E3, E4, E5, E6, E7 };
  50. enum heater_t : uint8_t { H0, H1, H2, H3, H4, H5, BED, CHAMBER };
  51. enum fan_t : uint8_t { FAN0, FAN1, FAN2, FAN3, FAN4, FAN5, FAN6, FAN7 };
  52. enum result_t : uint8_t { PID_BAD_EXTRUDER_NUM, PID_TEMP_TOO_HIGH, PID_TUNING_TIMEOUT, PID_DONE };
  53. constexpr uint8_t extruderCount = EXTRUDERS;
  54. constexpr uint8_t hotendCount = HOTENDS;
  55. constexpr uint8_t fanCount = FAN_COUNT;
  56. #if HAS_MESH
  57. typedef float bed_mesh_t[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  58. #endif
  59. bool isMoving();
  60. bool isAxisPositionKnown(const axis_t);
  61. bool isAxisPositionKnown(const extruder_t);
  62. bool isPositionKnown(); // Axis position guaranteed, steppers active since homing
  63. bool isMachineHomed(); // Axis position most likely correct, steppers may have deactivated
  64. bool canMove(const axis_t);
  65. bool canMove(const extruder_t);
  66. void injectCommands_P(PGM_P const);
  67. void injectCommands(char * const);
  68. bool commandsInQueue();
  69. bool isHeaterIdle(const heater_t);
  70. bool isHeaterIdle(const extruder_t);
  71. void enableHeater(const heater_t);
  72. void enableHeater(const extruder_t);
  73. #if ENABLED(JOYSTICK)
  74. void jog(const xyz_float_t &dir);
  75. void _joystick_update(xyz_float_t &norm_jog);
  76. #endif
  77. /**
  78. * Getters and setters
  79. * Should be used by the EXTENSIBLE_UI to query or change Marlin's state.
  80. */
  81. PGM_P getFirmwareName_str();
  82. #if HAS_SOFTWARE_ENDSTOPS
  83. bool getSoftEndstopState();
  84. void setSoftEndstopState(const bool);
  85. #endif
  86. #if HAS_TRINAMIC_CONFIG
  87. float getAxisCurrent_mA(const axis_t);
  88. float getAxisCurrent_mA(const extruder_t);
  89. void setAxisCurrent_mA(const float, const axis_t);
  90. void setAxisCurrent_mA(const float, const extruder_t);
  91. int getTMCBumpSensitivity(const axis_t);
  92. void setTMCBumpSensitivity(const float, const axis_t);
  93. #endif
  94. float getActualTemp_celsius(const heater_t);
  95. float getActualTemp_celsius(const extruder_t);
  96. float getTargetTemp_celsius(const heater_t);
  97. float getTargetTemp_celsius(const extruder_t);
  98. float getTargetFan_percent(const fan_t);
  99. float getActualFan_percent(const fan_t);
  100. float getAxisPosition_mm(const axis_t);
  101. float getAxisPosition_mm(const extruder_t);
  102. float getAxisSteps_per_mm(const axis_t);
  103. float getAxisSteps_per_mm(const extruder_t);
  104. feedRate_t getAxisMaxFeedrate_mm_s(const axis_t);
  105. feedRate_t getAxisMaxFeedrate_mm_s(const extruder_t);
  106. float getAxisMaxAcceleration_mm_s2(const axis_t);
  107. float getAxisMaxAcceleration_mm_s2(const extruder_t);
  108. feedRate_t getMinFeedrate_mm_s();
  109. feedRate_t getMinTravelFeedrate_mm_s();
  110. float getPrintingAcceleration_mm_s2();
  111. float getRetractAcceleration_mm_s2();
  112. float getTravelAcceleration_mm_s2();
  113. float getFeedrate_percent();
  114. int16_t getFlowPercentage(const extruder_t);
  115. uint8_t getProgress_percent();
  116. uint32_t getProgress_seconds_elapsed();
  117. #if HAS_LEVELING
  118. bool getLevelingActive();
  119. void setLevelingActive(const bool);
  120. bool getMeshValid();
  121. #if HAS_MESH
  122. bed_mesh_t& getMeshArray();
  123. float getMeshPoint(const xy_uint8_t &pos);
  124. void setMeshPoint(const xy_uint8_t &pos, const float zval);
  125. void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
  126. inline void onMeshUpdate(const xy_int8_t &pos, const float zval) { onMeshUpdate(pos.x, pos.y, zval); }
  127. typedef enum : unsigned char {
  128. MESH_START, // Prior to start of probe
  129. MESH_FINISH, // Following probe of all points
  130. PROBE_START, // Beginning probe of grid location
  131. PROBE_FINISH // Finished probe of grid location
  132. } probe_state_t;
  133. void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state);
  134. inline void onMeshUpdate(const xy_int8_t &pos, probe_state_t state) { onMeshUpdate(pos.x, pos.y, state); }
  135. #endif
  136. #endif
  137. #if ENABLED(HOST_PROMPT_SUPPORT)
  138. void setHostResponse(const uint8_t);
  139. #endif
  140. #if ENABLED(PRINTCOUNTER)
  141. char* getTotalPrints_str(char buffer[21]);
  142. char* getFinishedPrints_str(char buffer[21]);
  143. char* getTotalPrintTime_str(char buffer[21]);
  144. char* getLongestPrint_str(char buffer[21]);
  145. char* getFilamentUsed_str(char buffer[21]);
  146. #endif
  147. void setTargetTemp_celsius(const float, const heater_t);
  148. void setTargetTemp_celsius(const float, const extruder_t);
  149. void setTargetFan_percent(const float, const fan_t);
  150. void setAxisPosition_mm(const float, const axis_t, const feedRate_t=0);
  151. void setAxisPosition_mm(const float, const extruder_t, const feedRate_t=0);
  152. void setAxisSteps_per_mm(const float, const axis_t);
  153. void setAxisSteps_per_mm(const float, const extruder_t);
  154. void setAxisMaxFeedrate_mm_s(const feedRate_t, const axis_t);
  155. void setAxisMaxFeedrate_mm_s(const feedRate_t, const extruder_t);
  156. void setAxisMaxAcceleration_mm_s2(const float, const axis_t);
  157. void setAxisMaxAcceleration_mm_s2(const float, const extruder_t);
  158. void setFeedrate_mm_s(const feedRate_t);
  159. void setMinFeedrate_mm_s(const feedRate_t);
  160. void setMinTravelFeedrate_mm_s(const feedRate_t);
  161. void setPrintingAcceleration_mm_s2(const float);
  162. void setRetractAcceleration_mm_s2(const float);
  163. void setTravelAcceleration_mm_s2(const float);
  164. void setFeedrate_percent(const float);
  165. void setFlow_percent(const int16_t, const extruder_t);
  166. void setUserConfirmed();
  167. #if ENABLED(LIN_ADVANCE)
  168. float getLinearAdvance_mm_mm_s(const extruder_t);
  169. void setLinearAdvance_mm_mm_s(const float, const extruder_t);
  170. #endif
  171. #if HAS_JUNCTION_DEVIATION
  172. float getJunctionDeviation_mm();
  173. void setJunctionDeviation_mm(const float);
  174. #else
  175. float getAxisMaxJerk_mm_s(const axis_t);
  176. float getAxisMaxJerk_mm_s(const extruder_t);
  177. void setAxisMaxJerk_mm_s(const float, const axis_t);
  178. void setAxisMaxJerk_mm_s(const float, const extruder_t);
  179. #endif
  180. extruder_t getActiveTool();
  181. void setActiveTool(const extruder_t, bool no_move);
  182. #if ENABLED(BABYSTEPPING)
  183. int16_t mmToWholeSteps(const float mm, const axis_t axis);
  184. bool babystepAxis_steps(const int16_t steps, const axis_t axis);
  185. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles);
  186. #endif
  187. #if HAS_HOTEND_OFFSET
  188. float getNozzleOffset_mm(const axis_t, const extruder_t);
  189. void setNozzleOffset_mm(const float, const axis_t, const extruder_t);
  190. void normalizeNozzleOffset(const axis_t axis);
  191. #endif
  192. float getZOffset_mm();
  193. void setZOffset_mm(const float);
  194. #if HAS_BED_PROBE
  195. float getProbeOffset_mm(const axis_t);
  196. void setProbeOffset_mm(const float, const axis_t);
  197. #endif
  198. #if ENABLED(BACKLASH_GCODE)
  199. float getAxisBacklash_mm(const axis_t);
  200. void setAxisBacklash_mm(const float, const axis_t);
  201. float getBacklashCorrection_percent();
  202. void setBacklashCorrection_percent(const float);
  203. #ifdef BACKLASH_SMOOTHING_MM
  204. float getBacklashSmoothing_mm();
  205. void setBacklashSmoothing_mm(const float);
  206. #endif
  207. #endif
  208. #if HAS_FILAMENT_SENSOR
  209. bool getFilamentRunoutEnabled();
  210. void setFilamentRunoutEnabled(const bool);
  211. bool getFilamentRunoutState();
  212. void setFilamentRunoutState(const bool);
  213. #if HAS_FILAMENT_RUNOUT_DISTANCE
  214. float getFilamentRunoutDistance_mm();
  215. void setFilamentRunoutDistance_mm(const float);
  216. #endif
  217. #endif
  218. #if ENABLED(CASE_LIGHT_ENABLE)
  219. bool getCaseLightState();
  220. void setCaseLightState(const bool);
  221. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  222. float getCaseLightBrightness_percent();
  223. void setCaseLightBrightness_percent(const float);
  224. #endif
  225. #endif
  226. #if ENABLED(PIDTEMP)
  227. float getPIDValues_Kp(const extruder_t);
  228. float getPIDValues_Ki(const extruder_t);
  229. float getPIDValues_Kd(const extruder_t);
  230. void setPIDValues(const float, const float, const float, extruder_t);
  231. void startPIDTune(const float, extruder_t);
  232. #endif
  233. #if ENABLED(PIDTEMPBED)
  234. float getBedPIDValues_Kp();
  235. float getBedPIDValues_Ki();
  236. float getBedPIDValues_Kd();
  237. void setBedPIDValues(const float, const float, const float);
  238. void startBedPIDTune(const float);
  239. #endif
  240. /**
  241. * Delay and timing routines
  242. * Should be used by the EXTENSIBLE_UI to safely pause or measure time
  243. * safe_millis must be called at least every 1 sec to guarantee time
  244. * yield should be called within lengthy loops
  245. */
  246. #ifdef __SAM3X8E__
  247. uint32_t safe_millis();
  248. #else
  249. FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
  250. #endif
  251. void delay_us(unsigned long us);
  252. void delay_ms(unsigned long ms);
  253. void yield();
  254. /**
  255. * Media access routines
  256. *
  257. * Should be used by the EXTENSIBLE_UI to operate on files
  258. */
  259. bool isMediaInserted();
  260. bool isPrintingFromMediaPaused();
  261. bool isPrintingFromMedia();
  262. bool isPrinting();
  263. void printFile(const char *filename);
  264. void stopPrint();
  265. void pausePrint();
  266. void resumePrint();
  267. class FileList {
  268. private:
  269. uint16_t num_files;
  270. public:
  271. FileList();
  272. void refresh();
  273. bool seek(const uint16_t, const bool skip_range_check = false);
  274. const char *longFilename();
  275. const char *shortFilename();
  276. const char *filename();
  277. bool isDir();
  278. void changeDir(const char * const dirname);
  279. void upDir();
  280. bool isAtRootDir();
  281. uint16_t count();
  282. };
  283. /**
  284. * Event callback routines
  285. *
  286. * Should be declared by EXTENSIBLE_UI and will be called by Marlin
  287. */
  288. void onStartup();
  289. void onIdle();
  290. void onMediaInserted();
  291. void onMediaError();
  292. void onMediaRemoved();
  293. void onPlayTone(const uint16_t frequency, const uint16_t duration);
  294. void onPrinterKilled(PGM_P const error, PGM_P const component);
  295. void onPrintTimerStarted();
  296. void onPrintTimerPaused();
  297. void onPrintTimerStopped();
  298. void onFilamentRunout(const extruder_t extruder);
  299. void onUserConfirmRequired(const char * const msg);
  300. void onUserConfirmRequired_P(PGM_P const pstr);
  301. void onStatusChanged(const char * const msg);
  302. void onStatusChanged_P(PGM_P const pstr);
  303. void onFactoryReset();
  304. void onStoreSettings(char *);
  305. void onLoadSettings(const char *);
  306. void onConfigurationStoreWritten(bool success);
  307. void onConfigurationStoreRead(bool success);
  308. #if ENABLED(POWER_LOSS_RECOVERY)
  309. void onPowerLossResume();
  310. #endif
  311. #if HAS_PID_HEATING
  312. void onPidTuning(const result_t rst);
  313. #endif
  314. };
  315. /**
  316. * Helper macros to increment or decrement a value. For example:
  317. *
  318. * UI_INCREMENT_BY(TargetTemp_celsius, 10, E0)
  319. *
  320. * Expands to:
  321. *
  322. * setTargetTemp_celsius(getTargetTemp_celsius(E0) + 10, E0);
  323. *
  324. * Or, in the case where a constant increment is desired:
  325. *
  326. * constexpr float increment = 10;
  327. *
  328. * UI_INCREMENT(TargetTemp_celsius, E0)
  329. */
  330. #define UI_INCREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) + inc, ##__VA_ARGS__)
  331. #define UI_DECREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) - inc, ##__VA_ARGS__)
  332. #define UI_INCREMENT(method, ...) UI_INCREMENT_BY(method, increment, ##__VA_ARGS__)
  333. #define UI_DECREMENT(method, ...) UI_DECREMENT_BY(method, increment, ##__VA_ARGS__)