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

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