My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. #include "../ultralcd.h"
  24. #include "../../inc/MarlinConfig.h"
  25. extern int8_t encoderLine, encoderTopLine, screen_items;
  26. extern bool screen_changed;
  27. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  28. void scroll_screen(const uint8_t limit, const bool is_menu);
  29. bool printer_busy();
  30. ////////////////////////////////////////////
  31. ////////// Menu Item Numeric Types /////////
  32. ////////////////////////////////////////////
  33. #define DECLARE_MENU_EDIT_TYPE(TYPE, NAME, STRFUNC, SCALE) \
  34. struct MenuItemInfo_##NAME { \
  35. typedef TYPE type_t; \
  36. static constexpr float scale = SCALE; \
  37. static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
  38. };
  39. DECLARE_MENU_EDIT_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified
  40. DECLARE_MENU_EDIT_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified
  41. DECLARE_MENU_EDIT_TYPE(int8_t, int8, i8tostr3, 1 ); // 123, -12 right-justified
  42. DECLARE_MENU_EDIT_TYPE(uint8_t, uint8, ui8tostr3, 1 ); // 123 right-justified
  43. DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_3, ui16tostr3, 1 ); // 123, -12 right-justified
  44. DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_4, ui16tostr4, 0.1 ); // 1234, -123 right-justified
  45. DECLARE_MENU_EDIT_TYPE(float, float3, ftostr3, 1 ); // 123 right-justified
  46. DECLARE_MENU_EDIT_TYPE(float, float52, ftostr52, 100 ); // 123.45
  47. DECLARE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000 ); // 1.234
  48. DECLARE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f ); // 12345 right-justified
  49. DECLARE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10 ); // +1234.5
  50. DECLARE_MENU_EDIT_TYPE(float, float52sign, ftostr52sign, 100 ); // +123.45
  51. DECLARE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100 ); // 1234.56 right-justified
  52. DECLARE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f ); // 12345 right-justified
  53. ////////////////////////////////////////////
  54. ///////// Menu Item Draw Functions /////////
  55. ////////////////////////////////////////////
  56. void draw_edit_screen(PGM_P const pstr, const char* const value=NULL);
  57. void draw_menu_item(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
  58. void draw_menu_item_static(const uint8_t row, PGM_P const pstr, const bool center=true, const bool invert=false, const char *valstr=NULL);
  59. void _draw_menu_item_edit(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm);
  60. FORCE_INLINE void draw_menu_item_back(const bool sel, const uint8_t row, PGM_P const pstr) { draw_menu_item(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]); }
  61. FORCE_INLINE void draw_menu_item_edit(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data) { _draw_menu_item_edit(sel, row, pstr, data, false); }
  62. FORCE_INLINE void draw_menu_item_edit_P(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data) { _draw_menu_item_edit(sel, row, pstr, data, true); }
  63. #define draw_menu_item_submenu(sel, row, pstr, data) draw_menu_item(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  64. #define draw_menu_item_gcode(sel, row, pstr, gcode) draw_menu_item(sel, row, pstr, '>', ' ')
  65. #define draw_menu_item_function(sel, row, pstr, data) draw_menu_item(sel, row, pstr, '>', ' ')
  66. #define DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(VAL) draw_menu_item_edit(sel, row, pstr, VAL)
  67. #define DRAW_BOOL_SETTING(sel, row, pstr, data) draw_menu_item_edit_P(sel, row, pstr, (*(data))?PSTR(MSG_LCD_ON):PSTR(MSG_LCD_OFF))
  68. #if ENABLED(SDSUPPORT)
  69. class CardReader;
  70. void draw_sd_menu_item(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard, const bool isDir);
  71. FORCE_INLINE void draw_menu_item_sdfile(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) { draw_sd_menu_item(sel, row, pstr, theCard, false); }
  72. FORCE_INLINE void draw_menu_item_sdfolder(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard) { draw_sd_menu_item(sel, row, pstr, theCard, true); }
  73. #endif
  74. #if HAS_GRAPHICAL_LCD && EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  75. void _lcd_zoffset_overlay_gfx(const float zvalue);
  76. #endif
  77. ////////////////////////////////////////////
  78. /////// Edit Setting Draw Functions ////////
  79. ////////////////////////////////////////////
  80. #define _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(TYPE, NAME, STRFUNC) \
  81. FORCE_INLINE void draw_menu_item_edit_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const pstr2, TYPE * const data, ...) { \
  82. UNUSED(pstr2); \
  83. DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(*(data))); \
  84. } \
  85. FORCE_INLINE void draw_menu_item_edit_accessor_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const pstr2, TYPE (*pget)(), void (*pset)(TYPE), ...) { \
  86. UNUSED(pstr2); UNUSED(pset); \
  87. DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(pget())); \
  88. } \
  89. typedef void NAME##_void
  90. #define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuItemInfo_##NAME::type_t, NAME, MenuItemInfo_##NAME::strfunc)
  91. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int3); // 123, -12 right-justified
  92. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int4); // 1234, -123 right-justified
  93. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int8); // 123, -12 right-justified
  94. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint8); // 123 right-justified
  95. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_3); // 123, -12 right-justified
  96. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_4); // 1234, -123 right-justified
  97. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float3); // 123 right-justified
  98. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52); // 123.45
  99. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float43); // 1.234
  100. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5); // 12345 right-justified
  101. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51); // +1234.5
  102. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52sign); // +123.45
  103. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float62); // 1234.56 right-justified
  104. DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5); // 12345 right-justified
  105. #define draw_menu_item_edit_bool(sel, row, pstr, pstr2, data, ...) DRAW_BOOL_SETTING(sel, row, pstr, data)
  106. #define draw_menu_item_edit_accessor_bool(sel, row, pstr, pstr2, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
  107. ////////////////////////////////////////////
  108. /////////////// Menu Actions ///////////////
  109. ////////////////////////////////////////////
  110. class MenuItem_back {
  111. public:
  112. static inline void action() { ui.goto_previous_screen(); }
  113. };
  114. class MenuItem_submenu {
  115. public:
  116. static inline void action(const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
  117. };
  118. class MenuItem_gcode {
  119. public:
  120. static void action(const char * const pgcode);
  121. };
  122. class MenuItem_function {
  123. public:
  124. static inline void action(const menuAction_t func) { (*func)(); };
  125. };
  126. ////////////////////////////////////////////
  127. /////////// Menu Editing Actions ///////////
  128. ////////////////////////////////////////////
  129. class MenuItemBase {
  130. protected:
  131. typedef char* (*strfunc_t)(const int32_t);
  132. typedef void (*loadfunc_t)(void *, const int32_t);
  133. static void init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint32_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
  134. static void edit(strfunc_t, loadfunc_t);
  135. };
  136. template<typename NAME>
  137. class TMenuItem : MenuItemBase {
  138. private:
  139. typedef typename NAME::type_t type_t;
  140. static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
  141. static inline float scale(const float value) { return value * NAME::scale; }
  142. static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
  143. static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
  144. public:
  145. static void action_edit(PGM_P const pstr, type_t * const ptr, const type_t minValue, const type_t maxValue, const screenFunc_t callback=NULL, const bool live=false) {
  146. const int32_t minv = scale(minValue);
  147. init(pstr, ptr, minv, int32_t(scale(maxValue)) - minv, int32_t(scale(*ptr)) - minv, edit, callback, live);
  148. }
  149. static void edit() { MenuItemBase::edit(to_string, load); }
  150. };
  151. #define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuItem<MenuItemInfo_##NAME> MenuItem_##NAME;
  152. DECLARE_MENU_EDIT_ITEM(int3);
  153. DECLARE_MENU_EDIT_ITEM(int4);
  154. DECLARE_MENU_EDIT_ITEM(int8);
  155. DECLARE_MENU_EDIT_ITEM(uint8);
  156. DECLARE_MENU_EDIT_ITEM(uint16_3);
  157. DECLARE_MENU_EDIT_ITEM(uint16_4);
  158. DECLARE_MENU_EDIT_ITEM(float3);
  159. DECLARE_MENU_EDIT_ITEM(float52);
  160. DECLARE_MENU_EDIT_ITEM(float43);
  161. DECLARE_MENU_EDIT_ITEM(float5);
  162. DECLARE_MENU_EDIT_ITEM(float51);
  163. DECLARE_MENU_EDIT_ITEM(float52sign);
  164. DECLARE_MENU_EDIT_ITEM(float62);
  165. DECLARE_MENU_EDIT_ITEM(long5);
  166. class MenuItem_bool {
  167. public:
  168. static void action_edit(PGM_P const pstr, bool* ptr, const screenFunc_t callbackFunc=NULL);
  169. };
  170. ////////////////////////////////////////////
  171. //////////// Menu System Macros ////////////
  172. ////////////////////////////////////////////
  173. /**
  174. * SCREEN_OR_MENU_LOOP generates init code for a screen or menu
  175. *
  176. * encoderTopLine is the top menu line to display
  177. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  178. * _menuLineNr is the menu item to draw and process
  179. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  180. */
  181. #define SCREEN_OR_MENU_LOOP() \
  182. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  183. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  184. _thisItemNr = 0
  185. /**
  186. * START_SCREEN Opening code for a screen having only static items.
  187. * Do simplified scrolling of the entire screen.
  188. *
  189. * START_MENU Opening code for a screen with menu items.
  190. * Scroll as-needed to keep the selected line in view.
  191. */
  192. #define START_SCREEN() \
  193. scroll_screen(LCD_HEIGHT, false); \
  194. bool _skipStatic = false; \
  195. SCREEN_OR_MENU_LOOP()
  196. #define START_MENU() \
  197. scroll_screen(1, true); \
  198. bool _skipStatic = true; \
  199. SCREEN_OR_MENU_LOOP()
  200. #define END_SCREEN() \
  201. } \
  202. screen_items = _thisItemNr
  203. #define END_MENU() \
  204. } \
  205. screen_items = _thisItemNr; \
  206. UNUSED(_skipStatic)
  207. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  208. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  209. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER) do{ if (USE_MULTIPLIER) ui.enable_encoder_multiplier(true); }while(0)
  210. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  211. #else
  212. #define ENCODER_RATE_MULTIPLY(F) NOOP
  213. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER)
  214. #endif
  215. /**
  216. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  217. *
  218. * draw_menu_item_<type>[_variant](sel, row, label, arg3...)
  219. * MenuItem_<type>::action[_variant](arg3...)
  220. *
  221. * Examples:
  222. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  223. * or
  224. * MENU_BACK(MSG_WATCH)
  225. * draw_menu_item_back(sel, row, PSTR(MSG_WATCH))
  226. * MenuItem_back::action()
  227. *
  228. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  229. * draw_menu_item_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  230. * MenuItem_function::action(lcd_sdcard_pause)
  231. *
  232. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  233. * draw_menu_item_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  234. * MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  235. *
  236. */
  237. #define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, ...) do { \
  238. _skipStatic = false; \
  239. if (_menuLineNr == _thisItemNr) { \
  240. if (encoderLine == _thisItemNr && ui.use_click()) { \
  241. _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
  242. MenuItem_##TYPE ::action ## VARIANT(__VA_ARGS__); \
  243. if (screen_changed) return; \
  244. } \
  245. if (ui.should_draw()) \
  246. draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ## __VA_ARGS__); \
  247. } \
  248. ++_thisItemNr; \
  249. }while(0)
  250. // Used to print static text with no visible cursor.
  251. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  252. #define STATIC_ITEM_P(PLABEL, ...) do{ \
  253. if (_menuLineNr == _thisItemNr) { \
  254. if (_skipStatic && encoderLine <= _thisItemNr) { \
  255. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  256. ++encoderLine; \
  257. } \
  258. if (ui.should_draw()) \
  259. draw_menu_item_static(_lcdLineNr, PLABEL, ## __VA_ARGS__); \
  260. } \
  261. ++_thisItemNr; \
  262. } while(0)
  263. #define MENU_ITEM_ADDON_START(X) do{ \
  264. if (ui.should_draw() && _menuLineNr == _thisItemNr - 1) { \
  265. SETCURSOR(X, _lcdLineNr)
  266. #define MENU_ITEM_ADDON_END() } }while(0)
  267. #define STATIC_ITEM(LABEL, ...) STATIC_ITEM_P(PSTR(LABEL), ## __VA_ARGS__)
  268. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
  269. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  270. #define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__)
  271. #define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__)
  272. #define MENU_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
  273. #define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
  274. #define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
  275. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
  276. ////////////////////////////////////////////
  277. /////////////// Menu Screens ///////////////
  278. ////////////////////////////////////////////
  279. void menu_main();
  280. void menu_move();
  281. #if ENABLED(SDSUPPORT)
  282. void menu_sdcard();
  283. #endif
  284. // First Fan Speed title in "Tune" and "Control>Temperature" menus
  285. #if FAN_COUNT > 0 && HAS_FAN0
  286. #if FAN_COUNT > 1
  287. #define FAN_SPEED_1_SUFFIX " 1"
  288. #else
  289. #define FAN_SPEED_1_SUFFIX ""
  290. #endif
  291. #endif
  292. ////////////////////////////////////////////
  293. //////// Menu Item Helper Functions ////////
  294. ////////////////////////////////////////////
  295. void lcd_move_z();
  296. void _lcd_draw_homing();
  297. #define HAS_LINE_TO_Z ANY(DELTA, PROBE_MANUALLY, MESH_BED_LEVELING, LEVEL_BED_CORNERS)
  298. #if HAS_LINE_TO_Z
  299. void line_to_z(const float &z);
  300. #endif
  301. #if ANY(AUTO_BED_LEVELING_UBL, PID_AUTOTUNE_MENU, ADVANCED_PAUSE_FEATURE)
  302. void lcd_enqueue_command(const char * const cmd);
  303. void lcd_enqueue_commands_P(PGM_P const cmd);
  304. #endif
  305. #if ENABLED(LEVEL_BED_CORNERS)
  306. void _lcd_level_bed_corners();
  307. #endif
  308. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  309. extern float lcd_z_fade_height;
  310. void _lcd_set_z_fade_height();
  311. #endif
  312. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  313. void _lcd_toggle_bed_leveling();
  314. #endif
  315. #if ENABLED(BABYSTEPPING)
  316. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  317. void lcd_babystep_zoffset();
  318. #else
  319. void lcd_babystep_z();
  320. #endif
  321. #endif
  322. #if ENABLED(EEPROM_SETTINGS)
  323. void lcd_store_settings();
  324. void lcd_load_settings();
  325. #endif
  326. #if ENABLED(POWER_LOSS_RECOVERY)
  327. void menu_job_recovery();
  328. #endif