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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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 onLevelingStart();
  151. void onLevelingDone();
  152. void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval);
  153. inline void onMeshUpdate(const xy_int8_t &pos, const_float_t zval) { onMeshUpdate(pos.x, pos.y, zval); }
  154. typedef enum : uint8_t {
  155. G29_START, // Prior to start of probe
  156. G29_FINISH, // Following probe of all points
  157. G29_POINT_START, // Beginning probe of grid location
  158. G29_POINT_FINISH, // Finished probe of grid location
  159. G26_START,
  160. G26_FINISH,
  161. G26_POINT_START,
  162. G26_POINT_FINISH
  163. } probe_state_t;
  164. void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state);
  165. inline void onMeshUpdate(const xy_int8_t &pos, probe_state_t state) { onMeshUpdate(pos.x, pos.y, state); }
  166. #endif
  167. #endif
  168. #if ENABLED(HOST_PROMPT_SUPPORT)
  169. void setHostResponse(const uint8_t);
  170. #endif
  171. inline void simulateUserClick() {
  172. #if ANY(HAS_MARLINUI_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
  173. ui.lcd_clicked = true;
  174. #endif
  175. }
  176. #if ENABLED(PRINTCOUNTER)
  177. char* getFailedPrints_str(char buffer[21]);
  178. char* getTotalPrints_str(char buffer[21]);
  179. char* getFinishedPrints_str(char buffer[21]);
  180. char* getTotalPrintTime_str(char buffer[21]);
  181. char* getLongestPrint_str(char buffer[21]);
  182. char* getFilamentUsed_str(char buffer[21]);
  183. #endif
  184. void setTargetTemp_celsius(const_float_t, const heater_t);
  185. void setTargetTemp_celsius(const_float_t, const extruder_t);
  186. void setTargetFan_percent(const_float_t, const fan_t);
  187. void coolDown();
  188. void setAxisPosition_mm(const_float_t, const axis_t, const feedRate_t=0);
  189. void setAxisPosition_mm(const_float_t, const extruder_t, const feedRate_t=0);
  190. void setAxisSteps_per_mm(const_float_t, const axis_t);
  191. void setAxisSteps_per_mm(const_float_t, const extruder_t);
  192. void setAxisMaxFeedrate_mm_s(const feedRate_t, const axis_t);
  193. void setAxisMaxFeedrate_mm_s(const feedRate_t, const extruder_t);
  194. void setAxisMaxAcceleration_mm_s2(const_float_t, const axis_t);
  195. void setAxisMaxAcceleration_mm_s2(const_float_t, const extruder_t);
  196. void setFeedrate_mm_s(const feedRate_t);
  197. void setMinFeedrate_mm_s(const feedRate_t);
  198. void setMinTravelFeedrate_mm_s(const feedRate_t);
  199. void setPrintingAcceleration_mm_s2(const_float_t);
  200. void setRetractAcceleration_mm_s2(const_float_t);
  201. void setTravelAcceleration_mm_s2(const_float_t);
  202. void setFeedrate_percent(const_float_t);
  203. void setFlow_percent(const int16_t, const extruder_t);
  204. bool awaitingUserConfirm();
  205. void setUserConfirmed();
  206. #if M600_PURGE_MORE_RESUMABLE
  207. void setPauseMenuResponse(PauseMenuResponse);
  208. extern PauseMessage pauseModeStatus;
  209. PauseMode getPauseMode();
  210. #endif
  211. #if ENABLED(LIN_ADVANCE)
  212. float getLinearAdvance_mm_mm_s(const extruder_t);
  213. void setLinearAdvance_mm_mm_s(const_float_t, const extruder_t);
  214. #endif
  215. #if HAS_JUNCTION_DEVIATION
  216. float getJunctionDeviation_mm();
  217. void setJunctionDeviation_mm(const_float_t);
  218. #else
  219. float getAxisMaxJerk_mm_s(const axis_t);
  220. float getAxisMaxJerk_mm_s(const extruder_t);
  221. void setAxisMaxJerk_mm_s(const_float_t, const axis_t);
  222. void setAxisMaxJerk_mm_s(const_float_t, const extruder_t);
  223. #endif
  224. extruder_t getTool(const uint8_t extruder);
  225. extruder_t getActiveTool();
  226. void setActiveTool(const extruder_t, bool no_move);
  227. #if ENABLED(BABYSTEPPING)
  228. int16_t mmToWholeSteps(const_float_t mm, const axis_t axis);
  229. float mmFromWholeSteps(int16_t steps, const axis_t axis);
  230. bool babystepAxis_steps(const int16_t steps, const axis_t axis);
  231. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles);
  232. #endif
  233. #if HAS_HOTEND_OFFSET
  234. float getNozzleOffset_mm(const axis_t, const extruder_t);
  235. void setNozzleOffset_mm(const_float_t, const axis_t, const extruder_t);
  236. void normalizeNozzleOffset(const axis_t axis);
  237. #endif
  238. float getZOffset_mm();
  239. void setZOffset_mm(const_float_t);
  240. #if HAS_BED_PROBE
  241. float getProbeOffset_mm(const axis_t);
  242. void setProbeOffset_mm(const_float_t, const axis_t);
  243. #endif
  244. #if ENABLED(BACKLASH_GCODE)
  245. float getAxisBacklash_mm(const axis_t);
  246. void setAxisBacklash_mm(const_float_t, const axis_t);
  247. float getBacklashCorrection_percent();
  248. void setBacklashCorrection_percent(const_float_t);
  249. #ifdef BACKLASH_SMOOTHING_MM
  250. float getBacklashSmoothing_mm();
  251. void setBacklashSmoothing_mm(const_float_t);
  252. #endif
  253. #endif
  254. #if HAS_FILAMENT_SENSOR
  255. bool getFilamentRunoutEnabled();
  256. void setFilamentRunoutEnabled(const bool);
  257. bool getFilamentRunoutState();
  258. void setFilamentRunoutState(const bool);
  259. #if HAS_FILAMENT_RUNOUT_DISTANCE
  260. float getFilamentRunoutDistance_mm();
  261. void setFilamentRunoutDistance_mm(const_float_t);
  262. #endif
  263. #endif
  264. #if ENABLED(CASE_LIGHT_ENABLE)
  265. bool getCaseLightState();
  266. void setCaseLightState(const bool);
  267. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  268. float getCaseLightBrightness_percent();
  269. void setCaseLightBrightness_percent(const_float_t);
  270. #endif
  271. #endif
  272. #if ENABLED(POWER_LOSS_RECOVERY)
  273. bool getPowerLossRecoveryEnabled();
  274. void setPowerLossRecoveryEnabled(const bool);
  275. #endif
  276. #if ENABLED(PIDTEMP)
  277. float getPIDValues_Kp(const extruder_t);
  278. float getPIDValues_Ki(const extruder_t);
  279. float getPIDValues_Kd(const extruder_t);
  280. void setPIDValues(const_float_t, const_float_t , const_float_t , extruder_t);
  281. void startPIDTune(const celsius_t, extruder_t);
  282. #endif
  283. #if ENABLED(PIDTEMPBED)
  284. float getBedPIDValues_Kp();
  285. float getBedPIDValues_Ki();
  286. float getBedPIDValues_Kd();
  287. void setBedPIDValues(const_float_t, const_float_t , const_float_t);
  288. void startBedPIDTune(const celsius_t);
  289. #endif
  290. /**
  291. * Delay and timing routines
  292. * Should be used by the EXTENSIBLE_UI to safely pause or measure time
  293. * safe_millis must be called at least every 1 sec to guarantee time
  294. * yield should be called within lengthy loops
  295. */
  296. #ifdef __SAM3X8E__
  297. uint32_t safe_millis();
  298. #else
  299. FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
  300. #endif
  301. void delay_us(uint32_t us);
  302. void delay_ms(uint32_t ms);
  303. void yield();
  304. /**
  305. * Media access routines
  306. *
  307. * Should be used by the EXTENSIBLE_UI to operate on files
  308. */
  309. bool isMediaInserted();
  310. bool isPrintingFromMediaPaused();
  311. bool isPrintingFromMedia();
  312. bool isPrinting();
  313. bool isPrintingPaused();
  314. void printFile(const char *filename);
  315. void stopPrint();
  316. void pausePrint();
  317. void resumePrint();
  318. class FileList {
  319. private:
  320. uint16_t num_files;
  321. public:
  322. FileList();
  323. void refresh();
  324. bool seek(const uint16_t, const bool skip_range_check = false);
  325. const char *longFilename();
  326. const char *shortFilename();
  327. const char *filename();
  328. bool isDir();
  329. void changeDir(const char * const dirname);
  330. void upDir();
  331. bool isAtRootDir();
  332. uint16_t count();
  333. };
  334. /**
  335. * Event callback routines
  336. *
  337. * Should be declared by EXTENSIBLE_UI and will be called by Marlin
  338. */
  339. void onStartup();
  340. void onIdle();
  341. void onMediaInserted();
  342. void onMediaError();
  343. void onMediaRemoved();
  344. void onPlayTone(const uint16_t frequency, const uint16_t duration);
  345. void onPrinterKilled(FSTR_P const error, FSTR_P const component);
  346. void onPrintTimerStarted();
  347. void onPrintTimerPaused();
  348. void onPrintTimerStopped();
  349. void onPrintDone();
  350. void onFilamentRunout(const extruder_t extruder);
  351. void onUserConfirmRequired(const char * const msg);
  352. void onUserConfirmRequired(FSTR_P const fstr);
  353. void onStatusChanged(const char * const msg);
  354. void onStatusChanged(FSTR_P const fstr);
  355. void onHomingStart();
  356. void onHomingDone();
  357. void onSteppersDisabled();
  358. void onSteppersEnabled();
  359. void onFactoryReset();
  360. void onStoreSettings(char *);
  361. void onLoadSettings(const char *);
  362. void onPostprocessSettings();
  363. void onConfigurationStoreWritten(bool success);
  364. void onConfigurationStoreRead(bool success);
  365. #if ENABLED(POWER_LOSS_RECOVERY)
  366. void onPowerLossResume();
  367. #endif
  368. #if HAS_PID_HEATING
  369. void onPidTuning(const result_t rst);
  370. #endif
  371. };
  372. /**
  373. * Helper macros to increment or decrement a value. For example:
  374. *
  375. * UI_INCREMENT_BY(TargetTemp_celsius, 10, E0)
  376. *
  377. * Expands to:
  378. *
  379. * setTargetTemp_celsius(getTargetTemp_celsius(E0) + 10, E0);
  380. *
  381. * Or, in the case where a constant increment is desired:
  382. *
  383. * constexpr float increment = 10;
  384. *
  385. * UI_INCREMENT(TargetTemp_celsius, E0)
  386. */
  387. #define UI_INCREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) + inc, ##__VA_ARGS__)
  388. #define UI_DECREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) - inc, ##__VA_ARGS__)
  389. #define UI_INCREMENT(method, ...) UI_INCREMENT_BY(method, increment, ##__VA_ARGS__)
  390. #define UI_DECREMENT(method, ...) UI_DECREMENT_BY(method, increment, ##__VA_ARGS__)