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

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