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.

menu.h 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 "../../libs/numtostr.h"
  25. #include "../../inc/MarlinConfig.h"
  26. #include "limits.h"
  27. extern int8_t encoderLine, encoderTopLine, screen_items;
  28. #if HOTENDS
  29. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP);
  30. #endif
  31. void scroll_screen(const uint8_t limit, const bool is_menu);
  32. bool printer_busy();
  33. typedef void (*selectFunc_t)();
  34. #define SS_LEFT 0x00
  35. #define SS_CENTER 0x01
  36. #define SS_INVERT 0x02
  37. #define SS_DEFAULT SS_CENTER
  38. #if HAS_GRAPHICAL_LCD && EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  39. void _lcd_zoffset_overlay_gfx(const float zvalue);
  40. #endif
  41. #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
  42. #define LCD_Z_OFFSET_FUNC(N) ftostr54sign(N)
  43. #define LCD_Z_OFFSET_TYPE float43
  44. #else
  45. #define LCD_Z_OFFSET_FUNC(N) ftostr52sign(N)
  46. #define LCD_Z_OFFSET_TYPE float52
  47. #endif
  48. ////////////////////////////////////////////
  49. ///////////// Base Menu Items //////////////
  50. ////////////////////////////////////////////
  51. class MenuItemBase {
  52. public:
  53. // An index to interject in the item label and for
  54. // use by the action
  55. static uint8_t itemIndex;
  56. // Store the index of the item ahead of use by indexed items
  57. FORCE_INLINE static void init(const uint8_t ind) { itemIndex = ind; }
  58. // Draw an item either selected (pre_char) or not (space) with post_char
  59. static void _draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
  60. // Draw an item either selected ('>') or not (space) with post_char
  61. FORCE_INLINE static void _draw(const bool sel, const uint8_t row, PGM_P const pstr, const char post_char) {
  62. _draw(sel, row, pstr, '>', post_char);
  63. }
  64. };
  65. class MenuItem_static : public MenuItemBase {
  66. public:
  67. static void draw(const uint8_t row, PGM_P const pstr, const uint8_t style=SS_DEFAULT, const char * const valstr=nullptr);
  68. };
  69. // CONFIRM_ITEM(LABEL,Y,N,FY,FN,V...),
  70. // YESNO_ITEM(LABEL,FY,FN,V...)
  71. class MenuItem_confirm : public MenuItemBase {
  72. public:
  73. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  74. _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
  75. }
  76. // Implemented for HD44780 and DOGM
  77. // Draw the prompt, buttons, and state
  78. static void draw_select_screen(
  79. PGM_P const yes, // Right option label
  80. PGM_P const no, // Left option label
  81. const bool yesno, // Is "yes" selected?
  82. PGM_P const pref, // Prompt prefix
  83. const char * const string, // Prompt runtime string
  84. PGM_P const suff // Prompt suffix
  85. );
  86. static void select_screen(
  87. PGM_P const yes, PGM_P const no,
  88. selectFunc_t yesFunc, selectFunc_t noFunc,
  89. PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr
  90. );
  91. static inline void select_screen(
  92. PGM_P const yes, PGM_P const no,
  93. selectFunc_t yesFunc, selectFunc_t noFunc,
  94. PGM_P const pref, const progmem_str string, PGM_P const suff=nullptr
  95. ) {
  96. char str[strlen_P((PGM_P)string) + 1];
  97. strcpy_P(str, (PGM_P)string);
  98. select_screen(yes, no, yesFunc, noFunc, pref, str, suff);
  99. }
  100. // Shortcut for prompt with "NO"/ "YES" labels
  101. FORCE_INLINE static void confirm_screen(selectFunc_t yesFunc, selectFunc_t noFunc, PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr) {
  102. select_screen(GET_TEXT(MSG_YES), GET_TEXT(MSG_NO), yesFunc, noFunc, pref, string, suff);
  103. }
  104. };
  105. // BACK_ITEM(LABEL)
  106. class MenuItem_back : public MenuItemBase {
  107. public:
  108. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr) {
  109. _draw(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]);
  110. }
  111. // Back Item action goes back one step in history
  112. FORCE_INLINE static void action(PGM_P const=nullptr) { ui.go_back(); }
  113. };
  114. // SUBMENU(LABEL, screen_handler)
  115. class MenuItem_submenu : public MenuItemBase {
  116. public:
  117. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  118. _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
  119. }
  120. static inline void action(PGM_P const, const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
  121. };
  122. // Any menu item that invokes an immediate action
  123. class MenuItem_button : public MenuItemBase {
  124. public:
  125. // Button-y Items are selectable lines with no other indicator
  126. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  127. _draw(sel, row, pstr, '>', ' ');
  128. }
  129. };
  130. // GCODES_ITEM(LABEL, GCODES)
  131. class MenuItem_gcode : public MenuItem_button {
  132. public:
  133. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  134. _draw(sel, row, pstr, '>', ' ');
  135. }
  136. static void action(PGM_P const, const char * const pgcode);
  137. static inline void action(PGM_P const pstr, const uint8_t, const char * const pgcode) { action(pstr, pgcode); }
  138. };
  139. // ACTION_ITEM(LABEL, FUNC)
  140. class MenuItem_function : public MenuItem_button {
  141. public:
  142. //static inline void action(PGM_P const, const uint8_t, const menuAction_t func) { (*func)(); };
  143. static inline void action(PGM_P const, const menuAction_t func) { (*func)(); };
  144. };
  145. #if ENABLED(SDSUPPORT)
  146. class CardReader;
  147. class MenuItem_sdbase {
  148. public:
  149. // Implemented for HD44780 and DOGM
  150. static void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard, const bool isDir);
  151. };
  152. #endif
  153. ////////////////////////////////////////////
  154. ///////////// Edit Menu Items //////////////
  155. ////////////////////////////////////////////
  156. // The Menu Edit shadow value
  157. typedef union {
  158. bool state;
  159. float decimal;
  160. int8_t int8;
  161. int16_t int16;
  162. int32_t int32;
  163. uint8_t uint8;
  164. uint16_t uint16;
  165. uint32_t uint32;
  166. } chimera_t;
  167. extern chimera_t editable;
  168. // Base class for Menu Edit Items
  169. class MenuEditItemBase : public MenuItemBase {
  170. private:
  171. // These values are statically constructed by init() via action()
  172. // The action() method acts like the instantiator. The entire lifespan
  173. // of a menu item is within its declaration, so all these values decompose
  174. // into behavior and unused items get optimized out.
  175. static PGM_P editLabel;
  176. static void *editValue;
  177. static int32_t minEditValue, maxEditValue; // Encoder value range
  178. static screenFunc_t callbackFunc;
  179. static bool liveEdit;
  180. protected:
  181. typedef const char* (*strfunc_t)(const int32_t);
  182. typedef void (*loadfunc_t)(void *, const int32_t);
  183. static void goto_edit_screen(
  184. PGM_P const el, // Edit label
  185. void * const ev, // Edit value pointer
  186. const int32_t minv, // Encoder minimum
  187. const int32_t maxv, // Encoder maximum
  188. const uint16_t ep, // Initial encoder value
  189. const screenFunc_t cs, // MenuItem_type::draw_edit_screen => MenuEditItemBase::edit()
  190. const screenFunc_t cb, // Callback after edit
  191. const bool le // Flag to call cb() during editing
  192. );
  193. static void edit_screen(strfunc_t, loadfunc_t); // Edit value handler
  194. public:
  195. // Implemented for HD44780 and DOGM
  196. // Draw the current item at specified row with edit data
  197. static void draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm=false);
  198. // Implemented for HD44780 and DOGM
  199. // This low-level method is good to draw from anywhere
  200. static void draw_edit_screen(PGM_P const pstr, const char* const value);
  201. // This method is for the current menu item
  202. static inline void draw_edit_screen(const char* const value) { draw_edit_screen(editLabel, value); }
  203. };
  204. // Template for specific Menu Edit Item Types
  205. template<typename NAME>
  206. class TMenuEditItem : MenuEditItemBase {
  207. private:
  208. typedef typename NAME::type_t type_t;
  209. static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
  210. static inline float scale(const float value) { return value * NAME::scale; }
  211. static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
  212. static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
  213. public:
  214. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t * const data, ...) {
  215. MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(*(data)));
  216. }
  217. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t (*pget)(), ...) {
  218. MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(pget()));
  219. }
  220. // Edit screen for this type of item
  221. static void edit_screen() { MenuEditItemBase::edit_screen(to_string, load); }
  222. static void action(
  223. PGM_P const pstr, // Edit label
  224. type_t * const ptr, // Value pointer
  225. const type_t minValue, // Value range
  226. const type_t maxValue,
  227. const screenFunc_t callback=nullptr, // Value update callback
  228. const bool live=false // Callback during editing
  229. ) {
  230. // Make sure minv and maxv fit within int32_t
  231. const int32_t minv = _MAX(scale(minValue), INT32_MIN),
  232. maxv = _MIN(scale(maxValue), INT32_MAX);
  233. goto_edit_screen(pstr, ptr, minv, maxv - minv, scale(*ptr) - minv,
  234. edit_screen, callback, live);
  235. }
  236. };
  237. // Provide a set of Edit Item Types which encompass a primitive
  238. // type, a string function, and a scale factor for edit and display.
  239. // These items call the Edit Item draw method passing the prepared string.
  240. #define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, STRFUNC, SCALE) \
  241. struct MenuEditItemInfo_##NAME { \
  242. typedef TYPE type_t; \
  243. static constexpr float scale = SCALE; \
  244. static inline const char* strfunc(const float value) { return STRFUNC((TYPE)value); } \
  245. }; \
  246. typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
  247. // TYPE NAME STRFUNC SCALE
  248. DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, percent, ui8tostr4pct, 100.0/255); // 100% right-justified
  249. DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified
  250. DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified
  251. DEFINE_MENU_EDIT_ITEM_TYPE(int8_t, int8, i8tostr3, 1 ); // 123, -12 right-justified
  252. DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, uint8, ui8tostr3, 1 ); // 123 right-justified
  253. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_3, ui16tostr3, 1 ); // 123 right-justified
  254. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_4, ui16tostr4, 0.1 ); // 1234 right-justified
  255. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_t, uint16_5, ui16tostr5, 0.01 ); // 12345 right-justified
  256. DEFINE_MENU_EDIT_ITEM_TYPE(float, float3, ftostr3, 1 ); // 123 right-justified
  257. DEFINE_MENU_EDIT_ITEM_TYPE(float, float52, ftostr42_52, 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45
  258. DEFINE_MENU_EDIT_ITEM_TYPE(float, float43, ftostr43sign, 1000 ); // 1.234
  259. DEFINE_MENU_EDIT_ITEM_TYPE(float, float5, ftostr5rj, 1 ); // 12345 right-justified
  260. DEFINE_MENU_EDIT_ITEM_TYPE(float, float5_25, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment)
  261. DEFINE_MENU_EDIT_ITEM_TYPE(float, float51, ftostr51rj, 10 ); // 1234.5 right-justified
  262. DEFINE_MENU_EDIT_ITEM_TYPE(float, float41sign, ftostr41sign, 10 ); // +123.4
  263. DEFINE_MENU_EDIT_ITEM_TYPE(float, float51sign, ftostr51sign, 10 ); // +1234.5
  264. DEFINE_MENU_EDIT_ITEM_TYPE(float, float52sign, ftostr52sign, 100 ); // +123.45
  265. DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5, ftostr5rj, 0.01f ); // 12345 right-justified
  266. DEFINE_MENU_EDIT_ITEM_TYPE(uint32_t, long5_25, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment)
  267. class MenuItem_bool : public MenuEditItemBase {
  268. public:
  269. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, const bool onoff) {
  270. MenuEditItemBase::draw(sel, row, pstr, onoff ? GET_TEXT(MSG_LCD_ON) : GET_TEXT(MSG_LCD_OFF), true);
  271. }
  272. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, bool * const data, ...) {
  273. draw(sel, row, pstr, *data);
  274. }
  275. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const, bool (*pget)(), ...) {
  276. draw(sel, row, pstr, pget());
  277. }
  278. static void action(PGM_P const pstr, bool * const ptr, const screenFunc_t callbackFunc=nullptr);
  279. };
  280. ////////////////////////////////////////////
  281. //////////// Menu System Macros ////////////
  282. ////////////////////////////////////////////
  283. /**
  284. * SCREEN_OR_MENU_LOOP generates init code for a screen or menu
  285. *
  286. * encoderTopLine is the top menu line to display
  287. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  288. * _menuLineNr is the menu item to draw and process
  289. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  290. */
  291. #define SCREEN_OR_MENU_LOOP(IS_MENU) \
  292. scroll_screen(IS_MENU ? 1 : LCD_HEIGHT, IS_MENU); \
  293. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  294. bool _skipStatic = IS_MENU; \
  295. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  296. _thisItemNr = 0
  297. /**
  298. * START_SCREEN Opening code for a screen having only static items.
  299. * Do simplified scrolling of the entire screen.
  300. *
  301. * START_MENU Opening code for a screen with menu items.
  302. * Scroll as-needed to keep the selected line in view.
  303. */
  304. #define START_SCREEN() SCREEN_OR_MENU_LOOP(false)
  305. #define START_MENU() SCREEN_OR_MENU_LOOP(true)
  306. #define NEXT_ITEM() (++_thisItemNr)
  307. #define SKIP_ITEM() NEXT_ITEM()
  308. #define END_SCREEN() } screen_items = _thisItemNr
  309. #define END_MENU() END_SCREEN(); UNUSED(_skipStatic)
  310. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  311. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  312. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER) do{ if (USE_MULTIPLIER) ui.enable_encoder_multiplier(true); }while(0)
  313. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  314. #else
  315. #define ENCODER_RATE_MULTIPLY(F) NOOP
  316. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER)
  317. #endif
  318. /**
  319. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  320. *
  321. * MenuItem_<type>::draw(sel, row, label, arg3...)
  322. * MenuItem_<type>::action(arg3...)
  323. *
  324. * Examples:
  325. * BACK_ITEM(MSG_INFO_SCREEN)
  326. * MenuItem_back::action(plabel, ...)
  327. * MenuItem_back::draw(sel, row, plabel, ...)
  328. *
  329. * ACTION_ITEM(MSG_PAUSE_PRINT, lcd_sdcard_pause)
  330. * MenuItem_function::action(plabel, lcd_sdcard_pause)
  331. * MenuItem_function::draw(sel, row, plabel, lcd_sdcard_pause)
  332. *
  333. * EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  334. * MenuItem_int3::action(plabel, &feedrate_percentage, 10, 999)
  335. * MenuItem_int3::draw(sel, row, plabel, &feedrate_percentage, 10, 999)
  336. */
  337. #define _MENU_INNER_P(TYPE, USE_MULTIPLIER, PLABEL, V...) do { \
  338. PGM_P const plabel = PLABEL; \
  339. if (encoderLine == _thisItemNr && ui.use_click()) { \
  340. _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
  341. MenuItem_##TYPE::action(plabel, ##V); \
  342. if (ui.screen_changed) return; \
  343. } \
  344. if (ui.should_draw()) \
  345. MenuItem_##TYPE::draw \
  346. (encoderLine == _thisItemNr, _lcdLineNr, plabel, ##V); \
  347. }while(0)
  348. #define _MENU_ITEM_P(TYPE, V...) do { \
  349. _skipStatic = false; \
  350. if (_menuLineNr == _thisItemNr) \
  351. _MENU_INNER_P(TYPE, ##V); \
  352. NEXT_ITEM(); \
  353. }while(0)
  354. // Indexed items set a global index value
  355. #define _MENU_ITEM_N_P(TYPE, N, V...) do{ \
  356. _skipStatic = false; \
  357. if (_menuLineNr == _thisItemNr) { \
  358. MenuItemBase::init(N); \
  359. _MENU_INNER_P(TYPE, ##V); \
  360. } \
  361. NEXT_ITEM(); \
  362. }while(0)
  363. // STATIC_ITEM draws a styled string with no highlight.
  364. // Parameters: label [, style [, char *value] ]
  365. #define STATIC_ITEM_INNER_P(PLABEL, V...) do{ \
  366. if (_skipStatic && encoderLine <= _thisItemNr) { \
  367. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  368. ++encoderLine; \
  369. } \
  370. if (ui.should_draw()) \
  371. MenuItem_static::draw(_lcdLineNr, PLABEL, ##V); \
  372. } while(0)
  373. #define STATIC_ITEM_P(PLABEL, V...) do{ \
  374. if (_menuLineNr == _thisItemNr) \
  375. STATIC_ITEM_INNER_P(PLABEL, ##V); \
  376. NEXT_ITEM(); \
  377. } while(0)
  378. #define STATIC_ITEM_N_P(PLABEL, N, V...) do{ \
  379. if (_menuLineNr == _thisItemNr) { \
  380. MenuItemBase::init(N); \
  381. STATIC_ITEM_INNER_P(PLABEL, ##V); \
  382. } \
  383. NEXT_ITEM(); \
  384. }while(0)
  385. #define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P( GET_TEXT(LABEL), ##V)
  386. #define STATIC_ITEM_N(LABEL, N, V...) STATIC_ITEM_N_P(GET_TEXT(LABEL), ##V)
  387. #define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, false, PLABEL, ##V)
  388. #define MENU_ITEM(TYPE, LABEL, V...) MENU_ITEM_P(TYPE, GET_TEXT(LABEL), ##V)
  389. #define MENU_ITEM_N_P(TYPE, N, PLABEL, V...) _MENU_ITEM_N_P(TYPE, N, false, PLABEL, ##V)
  390. #define MENU_ITEM_N(TYPE, N, LABEL, V...) MENU_ITEM_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  391. #define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)
  392. #define ACTION_ITEM_P(PLABEL, ACTION) MENU_ITEM_P(function, PLABEL, ACTION)
  393. #define ACTION_ITEM(LABEL, ACTION) ACTION_ITEM_P(GET_TEXT(LABEL), ACTION)
  394. #define ACTION_ITEM_N_P(N, PLABEL, ACTION) MENU_ITEM_N_P(function, N, PLABEL, ACTION)
  395. #define ACTION_ITEM_N(N, LABEL, ACTION) ACTION_ITEM_N_P(N, GET_TEXT(LABEL), ACTION)
  396. #define GCODES_ITEM_P(PLABEL, GCODES) MENU_ITEM_P(gcode, PLABEL, GCODES)
  397. #define GCODES_ITEM(LABEL, GCODES) GCODES_ITEM_P(GET_TEXT(LABEL), GCODES)
  398. #define GCODES_ITEM_N_P(N, PLABEL, GCODES) MENU_ITEM_N_P(gcode, N, PLABEL, GCODES)
  399. #define GCODES_ITEM_N(N, LABEL, GCODES) GCODES_ITEM_N_P(N, GET_TEXT(LABEL), GCODES)
  400. #define SUBMENU_P(PLABEL, DEST) MENU_ITEM_P(submenu, PLABEL, DEST)
  401. #define SUBMENU(LABEL, DEST) SUBMENU_P(GET_TEXT(LABEL), DEST)
  402. #define SUBMENU_N_P(N, PLABEL, DEST) MENU_ITEM_N_P(submenu, N, PLABEL, DEST)
  403. #define SUBMENU_N(N, LABEL, DEST) SUBMENU_N_P(N, GET_TEXT(LABEL), DEST)
  404. #define EDIT_ITEM_P(TYPE, PLABEL, V...) MENU_ITEM_P(TYPE, PLABEL, ##V)
  405. #define EDIT_ITEM(TYPE, LABEL, V...) EDIT_ITEM_P(TYPE, GET_TEXT(LABEL), ##V)
  406. #define EDIT_ITEM_N_P(TYPE, N, PLABEL, V...) MENU_ITEM_N_P(TYPE, N, PLABEL, ##V)
  407. #define EDIT_ITEM_N(TYPE, N, LABEL, V...) EDIT_ITEM_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  408. #define EDIT_ITEM_FAST_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, true, PLABEL, ##V)
  409. #define EDIT_ITEM_FAST(TYPE, LABEL, V...) EDIT_ITEM_FAST_P(TYPE, GET_TEXT(LABEL), ##V)
  410. #define EDIT_ITEM_FAST_N_P(TYPE, N, PLABEL, V...) _MENU_ITEM_N_P(TYPE, N, true, PLABEL, ##V)
  411. #define EDIT_ITEM_FAST_N(TYPE, N, LABEL, V...) EDIT_ITEM_FAST_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  412. #define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
  413. if (encoderLine == _thisItemNr && ui.use_click()) { \
  414. ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
  415. return; \
  416. } \
  417. if (ui.should_draw()) MenuItem_confirm::draw \
  418. (encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ##V); \
  419. }while(0)
  420. #define _CONFIRM_ITEM_P(PLABEL, V...) do { \
  421. _skipStatic = false; \
  422. if (_menuLineNr == _thisItemNr) \
  423. _CONFIRM_ITEM_INNER_P(PLABEL, ##V); \
  424. NEXT_ITEM(); \
  425. }while(0)
  426. // Indexed items set a global index value
  427. #define _CONFIRM_ITEM_N_P(N, V...) do{ \
  428. _skipStatic = false; \
  429. if (_menuLineNr == _thisItemNr) { \
  430. MenuItemBase::init(N); \
  431. _CONFIRM_ITEM_INNER_P(TYPE, ##V); \
  432. } \
  433. NEXT_ITEM(); \
  434. }while(0)
  435. #define CONFIRM_ITEM_P(PLABEL,A,B,V...) _CONFIRM_ITEM_P(PLABEL, GET_TEXT(A), GET_TEXT(B), ##V)
  436. #define CONFIRM_ITEM(LABEL, V...) CONFIRM_ITEM_P(GET_TEXT(LABEL), ##V)
  437. #define YESNO_ITEM_P(PLABEL, V...) _CONFIRM_ITEM_P(PLABEL, ##V)
  438. #define YESNO_ITEM(LABEL, V...) YESNO_ITEM_P(GET_TEXT(LABEL), ##V)
  439. #define CONFIRM_ITEM_N_P(N,PLABEL,A,B,V...) _CONFIRM_ITEM_N_P(N, PLABEL, GET_TEXT(A), GET_TEXT(B), ##V)
  440. #define CONFIRM_ITEM_N(N,LABEL, V...) CONFIRM_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
  441. #define YESNO_ITEM_N_P(N,PLABEL, V...) _CONFIRM_ITEM_N_P(N, PLABEL, ##V)
  442. #define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
  443. ////////////////////////////////////////////
  444. /////////////// Menu Screens ///////////////
  445. ////////////////////////////////////////////
  446. void menu_main();
  447. void menu_move();
  448. #if ENABLED(SDSUPPORT)
  449. void menu_media();
  450. #endif
  451. // First Fan Speed title in "Tune" and "Control>Temperature" menus
  452. #if FAN_COUNT > 0 && HAS_FAN0
  453. #if FAN_COUNT > 1
  454. #define FAN_SPEED_1_SUFFIX " 1"
  455. #else
  456. #define FAN_SPEED_1_SUFFIX ""
  457. #endif
  458. #endif
  459. ////////////////////////////////////////////
  460. //////// Menu Item Helper Functions ////////
  461. ////////////////////////////////////////////
  462. void lcd_move_z();
  463. void _lcd_draw_homing();
  464. #define HAS_LINE_TO_Z ANY(DELTA, PROBE_MANUALLY, MESH_BED_LEVELING, LEVEL_BED_CORNERS)
  465. #if HAS_LINE_TO_Z
  466. void line_to_z(const float &z);
  467. #endif
  468. #if ANY(AUTO_BED_LEVELING_UBL, PID_AUTOTUNE_MENU, ADVANCED_PAUSE_FEATURE)
  469. void lcd_enqueue_one_now(const char * const cmd);
  470. void lcd_enqueue_one_now_P(PGM_P const cmd);
  471. #endif
  472. #if HAS_GRAPHICAL_LCD && EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  473. void _lcd_zoffset_overlay_gfx(const float zvalue);
  474. #endif
  475. #if ENABLED(LEVEL_BED_CORNERS)
  476. void _lcd_level_bed_corners();
  477. #endif
  478. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  479. void _lcd_toggle_bed_leveling();
  480. #endif
  481. #if ENABLED(BABYSTEPPING)
  482. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  483. void lcd_babystep_zoffset();
  484. #else
  485. void lcd_babystep_z();
  486. #endif
  487. #endif
  488. #if ENABLED(EEPROM_SETTINGS)
  489. void lcd_store_settings();
  490. void lcd_load_settings();
  491. #endif
  492. #if ENABLED(POWER_LOSS_RECOVERY)
  493. void menu_job_recovery();
  494. #endif