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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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_t , const axis_t);
  91. void setAxisCurrent_mA(const_float_t , const extruder_t);
  92. int getTMCBumpSensitivity(const axis_t);
  93. void setTMCBumpSensitivity(const_float_t , 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_t zval);
  141. void moveToMeshPoint(const xy_uint8_t &pos, const_float_t z);
  142. void onMeshLevelingStart();
  143. void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval);
  144. inline void onMeshUpdate(const xy_int8_t &pos, const_float_t zval) { onMeshUpdate(pos.x, pos.y, zval); }
  145. typedef enum : uint8_t {
  146. MESH_START, // Prior to start of probe
  147. MESH_FINISH, // Following probe of all points
  148. PROBE_START, // Beginning probe of grid location
  149. PROBE_FINISH // Finished probe of grid location
  150. } probe_state_t;
  151. void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state);
  152. inline void onMeshUpdate(const xy_int8_t &pos, probe_state_t state) { onMeshUpdate(pos.x, pos.y, state); }
  153. #endif
  154. #endif
  155. #if ENABLED(HOST_PROMPT_SUPPORT)
  156. void setHostResponse(const uint8_t);
  157. #endif
  158. #if ENABLED(PRINTCOUNTER)
  159. char* getFailedPrints_str(char buffer[21]);
  160. char* getTotalPrints_str(char buffer[21]);
  161. char* getFinishedPrints_str(char buffer[21]);
  162. char* getTotalPrintTime_str(char buffer[21]);
  163. char* getLongestPrint_str(char buffer[21]);
  164. char* getFilamentUsed_str(char buffer[21]);
  165. #endif
  166. void setTargetTemp_celsius(const_float_t , const heater_t);
  167. void setTargetTemp_celsius(const_float_t , const extruder_t);
  168. void setTargetFan_percent(const_float_t , const fan_t);
  169. void coolDown();
  170. void setAxisPosition_mm(const_float_t , const axis_t, const feedRate_t=0);
  171. void setAxisPosition_mm(const_float_t , const extruder_t, const feedRate_t=0);
  172. void setAxisSteps_per_mm(const_float_t , const axis_t);
  173. void setAxisSteps_per_mm(const_float_t , const extruder_t);
  174. void setAxisMaxFeedrate_mm_s(const feedRate_t, const axis_t);
  175. void setAxisMaxFeedrate_mm_s(const feedRate_t, const extruder_t);
  176. void setAxisMaxAcceleration_mm_s2(const_float_t , const axis_t);
  177. void setAxisMaxAcceleration_mm_s2(const_float_t , const extruder_t);
  178. void setFeedrate_mm_s(const feedRate_t);
  179. void setMinFeedrate_mm_s(const feedRate_t);
  180. void setMinTravelFeedrate_mm_s(const feedRate_t);
  181. void setPrintingAcceleration_mm_s2(const_float_t );
  182. void setRetractAcceleration_mm_s2(const_float_t );
  183. void setTravelAcceleration_mm_s2(const_float_t );
  184. void setFeedrate_percent(const_float_t );
  185. void setFlow_percent(const int16_t, const extruder_t);
  186. bool awaitingUserConfirm();
  187. void setUserConfirmed();
  188. #if ENABLED(LIN_ADVANCE)
  189. float getLinearAdvance_mm_mm_s(const extruder_t);
  190. void setLinearAdvance_mm_mm_s(const_float_t , const extruder_t);
  191. #endif
  192. #if HAS_JUNCTION_DEVIATION
  193. float getJunctionDeviation_mm();
  194. void setJunctionDeviation_mm(const_float_t );
  195. #else
  196. float getAxisMaxJerk_mm_s(const axis_t);
  197. float getAxisMaxJerk_mm_s(const extruder_t);
  198. void setAxisMaxJerk_mm_s(const_float_t , const axis_t);
  199. void setAxisMaxJerk_mm_s(const_float_t , const extruder_t);
  200. #endif
  201. extruder_t getTool(const uint8_t extruder);
  202. extruder_t getActiveTool();
  203. void setActiveTool(const extruder_t, bool no_move);
  204. #if ENABLED(BABYSTEPPING)
  205. int16_t mmToWholeSteps(const_float_t mm, const axis_t axis);
  206. bool babystepAxis_steps(const int16_t steps, const axis_t axis);
  207. void smartAdjustAxis_steps(const int16_t steps, const axis_t axis, bool linked_nozzles);
  208. #endif
  209. #if HAS_HOTEND_OFFSET
  210. float getNozzleOffset_mm(const axis_t, const extruder_t);
  211. void setNozzleOffset_mm(const_float_t , const axis_t, const extruder_t);
  212. void normalizeNozzleOffset(const axis_t axis);
  213. #endif
  214. float getZOffset_mm();
  215. void setZOffset_mm(const_float_t );
  216. #if HAS_BED_PROBE
  217. float getProbeOffset_mm(const axis_t);
  218. void setProbeOffset_mm(const_float_t , const axis_t);
  219. #endif
  220. #if ENABLED(BACKLASH_GCODE)
  221. float getAxisBacklash_mm(const axis_t);
  222. void setAxisBacklash_mm(const_float_t , const axis_t);
  223. float getBacklashCorrection_percent();
  224. void setBacklashCorrection_percent(const_float_t );
  225. #ifdef BACKLASH_SMOOTHING_MM
  226. float getBacklashSmoothing_mm();
  227. void setBacklashSmoothing_mm(const_float_t );
  228. #endif
  229. #endif
  230. #if HAS_FILAMENT_SENSOR
  231. bool getFilamentRunoutEnabled();
  232. void setFilamentRunoutEnabled(const bool);
  233. bool getFilamentRunoutState();
  234. void setFilamentRunoutState(const bool);
  235. #if HAS_FILAMENT_RUNOUT_DISTANCE
  236. float getFilamentRunoutDistance_mm();
  237. void setFilamentRunoutDistance_mm(const_float_t );
  238. #endif
  239. #endif
  240. #if ENABLED(CASE_LIGHT_ENABLE)
  241. bool getCaseLightState();
  242. void setCaseLightState(const bool);
  243. #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
  244. float getCaseLightBrightness_percent();
  245. void setCaseLightBrightness_percent(const_float_t );
  246. #endif
  247. #endif
  248. #if ENABLED(PIDTEMP)
  249. float getPIDValues_Kp(const extruder_t);
  250. float getPIDValues_Ki(const extruder_t);
  251. float getPIDValues_Kd(const extruder_t);
  252. void setPIDValues(const_float_t , const_float_t , const_float_t , extruder_t);
  253. void startPIDTune(const_float_t , extruder_t);
  254. #endif
  255. #if ENABLED(PIDTEMPBED)
  256. float getBedPIDValues_Kp();
  257. float getBedPIDValues_Ki();
  258. float getBedPIDValues_Kd();
  259. void setBedPIDValues(const_float_t , const_float_t , const_float_t );
  260. void startBedPIDTune(const_float_t );
  261. #endif
  262. /**
  263. * Delay and timing routines
  264. * Should be used by the EXTENSIBLE_UI to safely pause or measure time
  265. * safe_millis must be called at least every 1 sec to guarantee time
  266. * yield should be called within lengthy loops
  267. */
  268. #ifdef __SAM3X8E__
  269. uint32_t safe_millis();
  270. #else
  271. FORCE_INLINE uint32_t safe_millis() { return millis(); } // TODO: Implement for AVR
  272. #endif
  273. void delay_us(uint32_t us);
  274. void delay_ms(uint32_t ms);
  275. void yield();
  276. /**
  277. * Media access routines
  278. *
  279. * Should be used by the EXTENSIBLE_UI to operate on files
  280. */
  281. bool isMediaInserted();
  282. bool isPrintingFromMediaPaused();
  283. bool isPrintingFromMedia();
  284. bool isPrinting();
  285. bool isPrintingPaused();
  286. void printFile(const char *filename);
  287. void stopPrint();
  288. void pausePrint();
  289. void resumePrint();
  290. class FileList {
  291. private:
  292. uint16_t num_files;
  293. public:
  294. FileList();
  295. void refresh();
  296. bool seek(const uint16_t, const bool skip_range_check = false);
  297. const char *longFilename();
  298. const char *shortFilename();
  299. const char *filename();
  300. bool isDir();
  301. void changeDir(const char * const dirname);
  302. void upDir();
  303. bool isAtRootDir();
  304. uint16_t count();
  305. };
  306. /**
  307. * Event callback routines
  308. *
  309. * Should be declared by EXTENSIBLE_UI and will be called by Marlin
  310. */
  311. void onStartup();
  312. void onIdle();
  313. void onMediaInserted();
  314. void onMediaError();
  315. void onMediaRemoved();
  316. void onPlayTone(const uint16_t frequency, const uint16_t duration);
  317. void onPrinterKilled(PGM_P const error, PGM_P const component);
  318. void onPrintTimerStarted();
  319. void onPrintTimerPaused();
  320. void onPrintTimerStopped();
  321. void onPrintFinished();
  322. void onFilamentRunout(const extruder_t extruder);
  323. void onUserConfirmRequired(const char * const msg);
  324. void onUserConfirmRequired_P(PGM_P const pstr);
  325. void onStatusChanged(const char * const msg);
  326. void onStatusChanged_P(PGM_P const pstr);
  327. void onHomingStart();
  328. void onHomingComplete();
  329. void onSteppersDisabled();
  330. void onSteppersEnabled();
  331. void onFactoryReset();
  332. void onStoreSettings(char *);
  333. void onLoadSettings(const char *);
  334. void onConfigurationStoreWritten(bool success);
  335. void onConfigurationStoreRead(bool success);
  336. #if ENABLED(POWER_LOSS_RECOVERY)
  337. void onPowerLossResume();
  338. #endif
  339. #if HAS_PID_HEATING
  340. void onPidTuning(const result_t rst);
  341. #endif
  342. };
  343. /**
  344. * Helper macros to increment or decrement a value. For example:
  345. *
  346. * UI_INCREMENT_BY(TargetTemp_celsius, 10, E0)
  347. *
  348. * Expands to:
  349. *
  350. * setTargetTemp_celsius(getTargetTemp_celsius(E0) + 10, E0);
  351. *
  352. * Or, in the case where a constant increment is desired:
  353. *
  354. * constexpr float increment = 10;
  355. *
  356. * UI_INCREMENT(TargetTemp_celsius, E0)
  357. */
  358. #define UI_INCREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) + inc, ##__VA_ARGS__)
  359. #define UI_DECREMENT_BY(method, inc, ...) ExtUI::set ## method(ExtUI::get ## method (__VA_ARGS__) - inc, ##__VA_ARGS__)
  360. #define UI_INCREMENT(method, ...) UI_INCREMENT_BY(method, increment, ##__VA_ARGS__)
  361. #define UI_DECREMENT(method, ...) UI_DECREMENT_BY(method, increment, ##__VA_ARGS__)