My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ui_api.h 15KB

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