My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ui_api.h 12KB

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