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

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