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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://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: <http://www.gnu.org/licenses/>. *
  41. ****************************************************************************/
  42. #pragma once
  43. #include "../../inc/MarlinConfig.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 };
  50. enum extruder_t : uint8_t { E0, E1, E2, E3, E4, E5 };
  51. enum heater_t : uint8_t { H0, H1, H2, H3, H4, H5, BED, CHAMBER };
  52. enum fan_t : uint8_t { FAN0, FAN1, FAN2, FAN3, FAN4, FAN5 };
  53. constexpr uint8_t extruderCount = EXTRUDERS;
  54. constexpr uint8_t hotendCount = HOTENDS;
  55. constexpr uint8_t fanCount = FAN_COUNT;
  56. #if HAS_MESH
  57. typedef float (&bed_mesh_t)[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  58. #endif
  59. bool isMoving();
  60. bool isAxisPositionKnown(const axis_t);
  61. bool isPositionKnown(); // Axis position guaranteed, steppers active since homing
  62. bool isMachineHomed(); // Axis position most likely correct, steppers may have deactivated
  63. bool canMove(const axis_t);
  64. bool canMove(const extruder_t);
  65. void injectCommands_P(PGM_P const);
  66. bool commandsInQueue();
  67. bool isHeaterIdle(const heater_t);
  68. bool isHeaterIdle(const extruder_t);
  69. void enableHeater(const heater_t);
  70. void enableHeater(const extruder_t);
  71. /**
  72. * Getters and setters
  73. * Should be used by the EXTENSIBLE_UI to query or change Marlin's state.
  74. */
  75. PGM_P getFirmwareName_str();
  76. #if HAS_SOFTWARE_ENDSTOPS
  77. bool getSoftEndstopState();
  78. void setSoftEndstopState(const bool);
  79. #endif
  80. #if HAS_TRINAMIC
  81. float getAxisCurrent_mA(const axis_t);
  82. float getAxisCurrent_mA(const extruder_t);
  83. void setAxisCurrent_mA(const float, const axis_t);
  84. void setAxisCurrent_mA(const float, const extruder_t);
  85. int getTMCBumpSensitivity(const axis_t);
  86. void setTMCBumpSensitivity(const float, const axis_t);
  87. #endif
  88. float getActualTemp_celsius(const heater_t);
  89. float getActualTemp_celsius(const extruder_t);
  90. float getTargetTemp_celsius(const heater_t);
  91. float getTargetTemp_celsius(const extruder_t);
  92. float getTargetFan_percent(const fan_t);
  93. float getActualFan_percent(const fan_t);
  94. float getAxisPosition_mm(const axis_t);
  95. float getAxisPosition_mm(const extruder_t);
  96. float getAxisSteps_per_mm(const axis_t);
  97. float getAxisSteps_per_mm(const extruder_t);
  98. float getAxisMaxFeedrate_mm_s(const axis_t);
  99. float getAxisMaxFeedrate_mm_s(const extruder_t);
  100. float getAxisMaxAcceleration_mm_s2(const axis_t);
  101. float getAxisMaxAcceleration_mm_s2(const extruder_t);
  102. float getMinFeedrate_mm_s();
  103. float getMinTravelFeedrate_mm_s();
  104. float getPrintingAcceleration_mm_s2();
  105. float getRetractAcceleration_mm_s2();
  106. float getTravelAcceleration_mm_s2();
  107. float getFeedrate_percent();
  108. uint8_t getProgress_percent();
  109. uint32_t getProgress_seconds_elapsed();
  110. #if HAS_LEVELING
  111. bool getLevelingActive();
  112. void setLevelingActive(const bool);
  113. bool getMeshValid();
  114. #if HAS_MESH
  115. bed_mesh_t getMeshArray();
  116. float getMeshPoint(const uint8_t xpos, const uint8_t ypos);
  117. void setMeshPoint(const uint8_t xpos, const uint8_t ypos, const float zval);
  118. void onMeshUpdate(const uint8_t xpos, const uint8_t ypos, const float zval);
  119. #endif
  120. #endif
  121. #if ENABLED(HOST_PROMPT_SUPPORT)
  122. void setHostResponse(const uint8_t);
  123. #endif
  124. #if ENABLED(PRINTCOUNTER)
  125. char* getTotalPrints_str(char buffer[21]);
  126. char* getFinishedPrints_str(char buffer[21]);
  127. char* getTotalPrintTime_str(char buffer[21]);
  128. char* getLongestPrint_str(char buffer[21]);
  129. char* getFilamentUsed_str(char buffer[21]);
  130. #endif
  131. void setTargetTemp_celsius(const float, const heater_t);
  132. void setTargetTemp_celsius(const float, const extruder_t);
  133. void setTargetFan_percent(const float, const fan_t);
  134. void setAxisPosition_mm(const float, const axis_t);
  135. void setAxisPosition_mm(const float, const extruder_t);
  136. void setAxisSteps_per_mm(const float, const axis_t);
  137. void setAxisSteps_per_mm(const float, const extruder_t);
  138. void setAxisMaxFeedrate_mm_s(const float, const axis_t);
  139. void setAxisMaxFeedrate_mm_s(const float, const extruder_t);
  140. void setAxisMaxAcceleration_mm_s2(const float, const axis_t);
  141. void setAxisMaxAcceleration_mm_s2(const float, const extruder_t);
  142. void setFeedrate_mm_s(const float);
  143. void setMinFeedrate_mm_s(const float);
  144. void setMinTravelFeedrate_mm_s(const float);
  145. void setPrintingAcceleration_mm_s2(const float);
  146. void setRetractAcceleration_mm_s2(const float);
  147. void setTravelAcceleration_mm_s2(const float);
  148. void setFeedrate_percent(const float);
  149. void setUserConfirmed(void);
  150. #if ENABLED(LIN_ADVANCE)
  151. float getLinearAdvance_mm_mm_s(const extruder_t);
  152. void setLinearAdvance_mm_mm_s(const float, const extruder_t);
  153. #endif
  154. #if ENABLED(JUNCTION_DEVIATION)
  155. float getJunctionDeviation_mm();
  156. void setJunctionDeviation_mm(const float);
  157. #else
  158. float getAxisMaxJerk_mm_s(const axis_t);
  159. float getAxisMaxJerk_mm_s(const extruder_t);
  160. void setAxisMaxJerk_mm_s(const float, const axis_t);
  161. void setAxisMaxJerk_mm_s(const float, const extruder_t);
  162. #endif
  163. extruder_t getActiveTool();
  164. void setActiveTool(const extruder_t, bool no_move);
  165. #if ENABLED(BABYSTEPPING)
  166. int16_t mmToWholeSteps(const float mm, const axis_t axis);
  167. bool babystepAxis_steps(const int16_t steps, const axis_t axis);
  168. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles);
  169. #endif
  170. #if HAS_HOTEND_OFFSET
  171. float getNozzleOffset_mm(const axis_t, const extruder_t);
  172. void setNozzleOffset_mm(const float, const axis_t, const extruder_t);
  173. void normalizeNozzleOffset(const axis_t axis);
  174. #endif
  175. #if HAS_BED_PROBE
  176. float getZOffset_mm();
  177. void setZOffset_mm(const float);
  178. #endif
  179. #if ENABLED(BACKLASH_GCODE)
  180. float getAxisBacklash_mm(const axis_t);
  181. void setAxisBacklash_mm(const float, const axis_t);
  182. float getBacklashCorrection_percent();
  183. void setBacklashCorrection_percent(const float);
  184. #ifdef BACKLASH_SMOOTHING_MM
  185. float getBacklashSmoothing_mm();
  186. void setBacklashSmoothing_mm(const float);
  187. #endif
  188. #endif
  189. #if HAS_FILAMENT_SENSOR
  190. bool getFilamentRunoutEnabled();
  191. void setFilamentRunoutEnabled(const bool);
  192. #ifdef FILAMENT_RUNOUT_DISTANCE_MM
  193. float getFilamentRunoutDistance_mm();
  194. void setFilamentRunoutDistance_mm(const float);
  195. #endif
  196. #endif
  197. /**
  198. * Delay and timing routines
  199. * Should be used by the EXTENSIBLE_UI to safely pause or measure time
  200. * safe_millis must be called at least every 1 sec to guarantee time
  201. * yield should be called within lengthy loops
  202. */
  203. #ifdef __SAM3X8E__
  204. uint32_t safe_millis();
  205. #else
  206. FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
  207. #endif
  208. void delay_us(unsigned long us);
  209. void delay_ms(unsigned long ms);
  210. void yield();
  211. /**
  212. * Media access routines
  213. *
  214. * Should be used by the EXTENSIBLE_UI to operate on files
  215. */
  216. bool isMediaInserted();
  217. bool isPrintingFromMediaPaused();
  218. bool isPrintingFromMedia();
  219. bool isPrinting();
  220. void printFile(const char *filename);
  221. void stopPrint();
  222. void pausePrint();
  223. void resumePrint();
  224. class FileList {
  225. private:
  226. uint16_t num_files;
  227. public:
  228. FileList();
  229. void refresh();
  230. bool seek(const uint16_t, const bool skip_range_check = false);
  231. const char *longFilename();
  232. const char *shortFilename();
  233. const char *filename();
  234. bool isDir();
  235. void changeDir(const char * const dirname);
  236. void upDir();
  237. bool isAtRootDir();
  238. uint16_t count();
  239. };
  240. /**
  241. * Event callback routines
  242. *
  243. * Should be declared by EXTENSIBLE_UI and will be called by Marlin
  244. */
  245. void onStartup();
  246. void onIdle();
  247. void onMediaInserted();
  248. void onMediaError();
  249. void onMediaRemoved();
  250. void onPlayTone(const uint16_t frequency, const uint16_t duration);
  251. void onPrinterKilled(PGM_P const msg);
  252. void onPrintTimerStarted();
  253. void onPrintTimerPaused();
  254. void onPrintTimerStopped();
  255. void onFilamentRunout(const extruder_t extruder);
  256. void onUserConfirmRequired(const char * const msg);
  257. void onStatusChanged(const char * const msg);
  258. void onFactoryReset();
  259. void onStoreSettings(char *);
  260. void onLoadSettings(const char *);
  261. void onConfigurationStoreWritten(bool success);
  262. void onConfigurationStoreRead(bool success);
  263. };
  264. /**
  265. * Helper macros to increment or decrement a value. For example:
  266. *
  267. * UI_INCREMENT_BY(TargetTemp_celsius, 10, E0)
  268. *
  269. * Expands to:
  270. *
  271. * setTargetTemp_celsius(getTargetTemp_celsius(E0) + 10, E0);
  272. *
  273. * Or, in the case where a constant increment is desired:
  274. *
  275. * constexpr float increment = 10;
  276. *
  277. * UI_INCREMENT(TargetTemp_celsius, E0)
  278. *
  279. */
  280. #define UI_INCREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) + inc, ##__VA_ARGS__)
  281. #define UI_DECREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) - inc, ##__VA_ARGS__)
  282. #define UI_INCREMENT(method, ...) UI_INCREMENT_BY(method, increment, ##__VA_ARGS__)
  283. #define UI_DECREMENT(method, ...) UI_DECREMENT_BY(method, increment, ##__VA_ARGS__)