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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. #include "../marlinui.h"
  44. #include "../../gcode/gcode.h"
  45. #if M600_PURGE_MORE_RESUMABLE
  46. #include "../../feature/pause.h"
  47. #endif
  48. namespace ExtUI {
  49. // The ExtUI implementation can store up to this many bytes
  50. // in the EEPROM when the methods onStoreSettings and
  51. // onLoadSettings are called.
  52. static constexpr size_t eeprom_data_size = 48;
  53. enum axis_t : uint8_t { X, Y, Z, I, J, K, X2, Y2, Z2, Z3, Z4 };
  54. enum extruder_t : uint8_t { E0, E1, E2, E3, E4, E5, E6, E7 };
  55. enum heater_t : uint8_t { H0, H1, H2, H3, H4, H5, BED, CHAMBER, COOLER };
  56. enum fan_t : uint8_t { FAN0, FAN1, FAN2, FAN3, FAN4, FAN5, FAN6, FAN7 };
  57. enum result_t : uint8_t { PID_STARTED, PID_BAD_EXTRUDER_NUM, PID_TEMP_TOO_HIGH, PID_TUNING_TIMEOUT, PID_DONE };
  58. constexpr uint8_t extruderCount = EXTRUDERS;
  59. constexpr uint8_t hotendCount = HOTENDS;
  60. constexpr uint8_t fanCount = FAN_COUNT;
  61. #if HAS_MESH
  62. typedef float bed_mesh_t[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  63. #endif
  64. bool isMoving();
  65. bool isAxisPositionKnown(const axis_t);
  66. bool isAxisPositionKnown(const extruder_t);
  67. bool isPositionKnown(); // Axis position guaranteed, steppers active since homing
  68. bool isMachineHomed(); // Axis position most likely correct, steppers may have deactivated
  69. bool canMove(const axis_t);
  70. bool canMove(const extruder_t);
  71. void injectCommands_P(PGM_P const);
  72. inline void injectCommands(FSTR_P const fstr) { injectCommands_P(FTOP(fstr)); }
  73. void injectCommands(char * const);
  74. bool commandsInQueue();
  75. GcodeSuite::MarlinBusyState getHostKeepaliveState();
  76. bool getHostKeepaliveIsPaused();
  77. bool isHeaterIdle(const heater_t);
  78. bool isHeaterIdle(const extruder_t);
  79. void enableHeater(const heater_t);
  80. void enableHeater(const extruder_t);
  81. #if ENABLED(JOYSTICK)
  82. void jog(const xyz_float_t &dir);
  83. void _joystick_update(xyz_float_t &norm_jog);
  84. #endif
  85. /**
  86. * Getters and setters
  87. * Should be used by the EXTENSIBLE_UI to query or change Marlin's state.
  88. */
  89. PGM_P getFirmwareName_str();
  90. #if HAS_SOFTWARE_ENDSTOPS
  91. bool getSoftEndstopState();
  92. void setSoftEndstopState(const bool);
  93. #endif
  94. #if HAS_TRINAMIC_CONFIG
  95. float getAxisCurrent_mA(const axis_t);
  96. float getAxisCurrent_mA(const extruder_t);
  97. void setAxisCurrent_mA(const_float_t, const axis_t);
  98. void setAxisCurrent_mA(const_float_t, const extruder_t);
  99. int getTMCBumpSensitivity(const axis_t);
  100. void setTMCBumpSensitivity(const_float_t, const axis_t);
  101. #endif
  102. celsius_float_t getActualTemp_celsius(const heater_t);
  103. celsius_float_t getActualTemp_celsius(const extruder_t);
  104. celsius_float_t getTargetTemp_celsius(const heater_t);
  105. celsius_float_t getTargetTemp_celsius(const extruder_t);
  106. float getTargetFan_percent(const fan_t);
  107. float getActualFan_percent(const fan_t);
  108. float getAxisPosition_mm(const axis_t);
  109. float getAxisPosition_mm(const extruder_t);
  110. float getAxisSteps_per_mm(const axis_t);
  111. float getAxisSteps_per_mm(const extruder_t);
  112. feedRate_t getAxisMaxFeedrate_mm_s(const axis_t);
  113. feedRate_t getAxisMaxFeedrate_mm_s(const extruder_t);
  114. float getAxisMaxAcceleration_mm_s2(const axis_t);
  115. float getAxisMaxAcceleration_mm_s2(const extruder_t);
  116. feedRate_t getMinFeedrate_mm_s();
  117. feedRate_t getMinTravelFeedrate_mm_s();
  118. feedRate_t getFeedrate_mm_s();
  119. float getPrintingAcceleration_mm_s2();
  120. float getRetractAcceleration_mm_s2();
  121. float getTravelAcceleration_mm_s2();
  122. float getFeedrate_percent();
  123. int16_t getFlow_percent(const extruder_t);
  124. inline uint8_t getProgress_percent() { return ui.get_progress_percent(); }
  125. #if HAS_PRINT_PROGRESS_PERMYRIAD
  126. inline uint16_t getProgress_permyriad() { return ui.get_progress_permyriad(); }
  127. #endif
  128. uint32_t getProgress_seconds_elapsed();
  129. #if HAS_PREHEAT
  130. uint16_t getMaterial_preset_E(const uint16_t);
  131. #if HAS_HEATED_BED
  132. uint16_t getMaterial_preset_B(const uint16_t);
  133. #endif
  134. #endif
  135. #if ENABLED(DUAL_X_CARRIAGE)
  136. uint8_t getIDEX_Mode();
  137. #endif
  138. #if ENABLED(SHOW_REMAINING_TIME)
  139. inline uint32_t getProgress_seconds_remaining() { return ui.get_remaining_time(); }
  140. #endif
  141. #if HAS_LEVELING
  142. bool getLevelingActive();
  143. void setLevelingActive(const bool);
  144. bool getMeshValid();
  145. #if HAS_MESH
  146. bed_mesh_t& getMeshArray();
  147. float getMeshPoint(const xy_uint8_t &pos);
  148. void setMeshPoint(const xy_uint8_t &pos, const_float_t zval);
  149. void moveToMeshPoint(const xy_uint8_t &pos, const_float_t z);
  150. void onMeshLevelingStart();
  151. void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval);
  152. inline void onMeshUpdate(const xy_int8_t &pos, const_float_t zval) { onMeshUpdate(pos.x, pos.y, zval); }
  153. typedef enum : uint8_t {
  154. G29_START, // Prior to start of probe
  155. G29_FINISH, // Following probe of all points
  156. G29_POINT_START, // Beginning probe of grid location
  157. G29_POINT_FINISH, // Finished probe of grid location
  158. G26_START,
  159. G26_FINISH,
  160. G26_POINT_START,
  161. G26_POINT_FINISH
  162. } probe_state_t;
  163. void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state);
  164. inline void onMeshUpdate(const xy_int8_t &pos, probe_state_t state) { onMeshUpdate(pos.x, pos.y, state); }
  165. #endif
  166. #endif
  167. #if ENABLED(HOST_PROMPT_SUPPORT)
  168. void setHostResponse(const uint8_t);
  169. #endif
  170. inline void simulateUserClick() {
  171. #if ANY(HAS_MARLINUI_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
  172. ui.lcd_clicked = true;
  173. #endif
  174. }
  175. #if ENABLED(PRINTCOUNTER)
  176. char* getFailedPrints_str(char buffer[21]);
  177. char* getTotalPrints_str(char buffer[21]);
  178. char* getFinishedPrints_str(char buffer[21]);
  179. char* getTotalPrintTime_str(char buffer[21]);
  180. char* getLongestPrint_str(char buffer[21]);
  181. char* getFilamentUsed_str(char buffer[21]);
  182. #endif
  183. void setTargetTemp_celsius(const_float_t, const heater_t);
  184. void setTargetTemp_celsius(const_float_t, const extruder_t);
  185. void setTargetFan_percent(const_float_t, const fan_t);
  186. void coolDown();
  187. void setAxisPosition_mm(const_float_t, const axis_t, const feedRate_t=0);
  188. void setAxisPosition_mm(const_float_t, const extruder_t, const feedRate_t=0);
  189. void setAxisSteps_per_mm(const_float_t, const axis_t);
  190. void setAxisSteps_per_mm(const_float_t, const extruder_t);
  191. void setAxisMaxFeedrate_mm_s(const feedRate_t, const axis_t);
  192. void setAxisMaxFeedrate_mm_s(const feedRate_t, const extruder_t);
  193. void setAxisMaxAcceleration_mm_s2(const_float_t, const axis_t);
  194. void setAxisMaxAcceleration_mm_s2(const_float_t, const extruder_t);
  195. void setFeedrate_mm_s(const feedRate_t);
  196. void setMinFeedrate_mm_s(const feedRate_t);
  197. void setMinTravelFeedrate_mm_s(const feedRate_t);
  198. void setPrintingAcceleration_mm_s2(const_float_t);
  199. void setRetractAcceleration_mm_s2(const_float_t);
  200. void setTravelAcceleration_mm_s2(const_float_t);
  201. void setFeedrate_percent(const_float_t);
  202. void setFlow_percent(const int16_t, const extruder_t);
  203. bool awaitingUserConfirm();
  204. void setUserConfirmed();
  205. #if M600_PURGE_MORE_RESUMABLE
  206. void setPauseMenuResponse(PauseMenuResponse);
  207. extern PauseMessage pauseModeStatus;
  208. PauseMode getPauseMode();
  209. #endif
  210. #if ENABLED(LIN_ADVANCE)
  211. float getLinearAdvance_mm_mm_s(const extruder_t);
  212. void setLinearAdvance_mm_mm_s(const_float_t, const extruder_t);
  213. #endif
  214. #if HAS_JUNCTION_DEVIATION
  215. float getJunctionDeviation_mm();
  216. void setJunctionDeviation_mm(const_float_t);
  217. #else
  218. float getAxisMaxJerk_mm_s(const axis_t);
  219. float getAxisMaxJerk_mm_s(const extruder_t);
  220. void setAxisMaxJerk_mm_s(const_float_t, const axis_t);
  221. void setAxisMaxJerk_mm_s(const_float_t, const extruder_t);
  222. #endif
  223. extruder_t getTool(const uint8_t extruder);
  224. extruder_t getActiveTool();
  225. void setActiveTool(const extruder_t, bool no_move);
  226. #if ENABLED(BABYSTEPPING)
  227. int16_t mmToWholeSteps(const_float_t mm, const axis_t axis);
  228. float mmFromWholeSteps(int16_t steps, const axis_t axis);
  229. bool babystepAxis_steps(const int16_t steps, const axis_t axis);
  230. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles);
  231. #endif
  232. #if HAS_HOTEND_OFFSET
  233. float getNozzleOffset_mm(const axis_t, const extruder_t);
  234. void setNozzleOffset_mm(const_float_t, const axis_t, const extruder_t);
  235. void normalizeNozzleOffset(const axis_t axis);
  236. #endif
  237. float getZOffset_mm();
  238. void setZOffset_mm(const_float_t);
  239. #if HAS_BED_PROBE
  240. float getProbeOffset_mm(const axis_t);
  241. void setProbeOffset_mm(const_float_t, const axis_t);
  242. #endif
  243. #if ENABLED(BACKLASH_GCODE)
  244. float getAxisBacklash_mm(const axis_t);
  245. void setAxisBacklash_mm(const_float_t, const axis_t);
  246. float getBacklashCorrection_percent();
  247. void setBacklashCorrection_percent(const_float_t);
  248. #ifdef BACKLASH_SMOOTHING_MM
  249. float getBacklashSmoothing_mm();
  250. void setBacklashSmoothing_mm(const_float_t);
  251. #endif
  252. #endif
  253. #if HAS_FILAMENT_SENSOR
  254. bool getFilamentRunoutEnabled();
  255. void setFilamentRunoutEnabled(const bool);
  256. bool getFilamentRunoutState();
  257. void setFilamentRunoutState(const bool);
  258. #if HAS_FILAMENT_RUNOUT_DISTANCE
  259. float getFilamentRunoutDistance_mm();
  260. void setFilamentRunoutDistance_mm(const_float_t);
  261. #endif
  262. #endif
  263. #if ENABLED(CASE_LIGHT_ENABLE)
  264. bool getCaseLightState();
  265. void setCaseLightState(const bool);
  266. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  267. float getCaseLightBrightness_percent();
  268. void setCaseLightBrightness_percent(const_float_t);
  269. #endif
  270. #endif
  271. #if ENABLED(PIDTEMP)
  272. float getPIDValues_Kp(const extruder_t);
  273. float getPIDValues_Ki(const extruder_t);
  274. float getPIDValues_Kd(const extruder_t);
  275. void setPIDValues(const_float_t, const_float_t , const_float_t , extruder_t);
  276. void startPIDTune(const celsius_t, extruder_t);
  277. #endif
  278. #if ENABLED(PIDTEMPBED)
  279. float getBedPIDValues_Kp();
  280. float getBedPIDValues_Ki();
  281. float getBedPIDValues_Kd();
  282. void setBedPIDValues(const_float_t, const_float_t , const_float_t);
  283. void startBedPIDTune(const celsius_t);
  284. #endif
  285. /**
  286. * Delay and timing routines
  287. * Should be used by the EXTENSIBLE_UI to safely pause or measure time
  288. * safe_millis must be called at least every 1 sec to guarantee time
  289. * yield should be called within lengthy loops
  290. */
  291. #ifdef __SAM3X8E__
  292. uint32_t safe_millis();
  293. #else
  294. FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
  295. #endif
  296. void delay_us(uint32_t us);
  297. void delay_ms(uint32_t ms);
  298. void yield();
  299. /**
  300. * Media access routines
  301. *
  302. * Should be used by the EXTENSIBLE_UI to operate on files
  303. */
  304. bool isMediaInserted();
  305. bool isPrintingFromMediaPaused();
  306. bool isPrintingFromMedia();
  307. bool isPrinting();
  308. bool isPrintingPaused();
  309. void printFile(const char *filename);
  310. void stopPrint();
  311. void pausePrint();
  312. void resumePrint();
  313. class FileList {
  314. private:
  315. uint16_t num_files;
  316. public:
  317. FileList();
  318. void refresh();
  319. bool seek(const uint16_t, const bool skip_range_check = false);
  320. const char *longFilename();
  321. const char *shortFilename();
  322. const char *filename();
  323. bool isDir();
  324. void changeDir(const char * const dirname);
  325. void upDir();
  326. bool isAtRootDir();
  327. uint16_t count();
  328. };
  329. /**
  330. * Event callback routines
  331. *
  332. * Should be declared by EXTENSIBLE_UI and will be called by Marlin
  333. */
  334. void onStartup();
  335. void onIdle();
  336. void onMediaInserted();
  337. void onMediaError();
  338. void onMediaRemoved();
  339. void onPlayTone(const uint16_t frequency, const uint16_t duration);
  340. void onPrinterKilled(FSTR_P const error, FSTR_P const component);
  341. void onPrintTimerStarted();
  342. void onPrintTimerPaused();
  343. void onPrintTimerStopped();
  344. void onPrintFinished();
  345. void onFilamentRunout(const extruder_t extruder);
  346. void onUserConfirmRequired(const char * const msg);
  347. void onUserConfirmRequired(FSTR_P const fstr);
  348. void onStatusChanged(const char * const msg);
  349. void onStatusChanged(FSTR_P const fstr);
  350. void onHomingStart();
  351. void onHomingComplete();
  352. void onSteppersDisabled();
  353. void onSteppersEnabled();
  354. void onFactoryReset();
  355. void onStoreSettings(char *);
  356. void onLoadSettings(const char *);
  357. void onPostprocessSettings();
  358. void onConfigurationStoreWritten(bool success);
  359. void onConfigurationStoreRead(bool success);
  360. #if ENABLED(POWER_LOSS_RECOVERY)
  361. void onPowerLossResume();
  362. #endif
  363. #if HAS_PID_HEATING
  364. void onPidTuning(const result_t rst);
  365. #endif
  366. };
  367. /**
  368. * Helper macros to increment or decrement a value. For example:
  369. *
  370. * UI_INCREMENT_BY(TargetTemp_celsius, 10, E0)
  371. *
  372. * Expands to:
  373. *
  374. * setTargetTemp_celsius(getTargetTemp_celsius(E0) + 10, E0);
  375. *
  376. * Or, in the case where a constant increment is desired:
  377. *
  378. * constexpr float increment = 10;
  379. *
  380. * UI_INCREMENT(TargetTemp_celsius, E0)
  381. */
  382. #define UI_INCREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) + inc, ##__VA_ARGS__)
  383. #define UI_DECREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) - inc, ##__VA_ARGS__)
  384. #define UI_INCREMENT(method, ...) UI_INCREMENT_BY(method, increment, ##__VA_ARGS__)
  385. #define UI_DECREMENT(method, ...) UI_DECREMENT_BY(method, increment, ##__VA_ARGS__)