My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ui_api.h 11KB

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