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 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. #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. void scroll_screen(const uint8_t limit, const bool is_menu);
  29. bool printer_busy();
  30. typedef void (*selectFunc_t)();
  31. #define SS_LEFT 0x00
  32. #define SS_CENTER 0x01
  33. #define SS_INVERT 0x02
  34. #define SS_DEFAULT SS_CENTER
  35. #if HAS_GRAPHICAL_LCD && EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  36. void _lcd_zoffset_overlay_gfx(const float zvalue);
  37. #endif
  38. #if HAS_BED_PROBE
  39. #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
  40. #define LCD_Z_OFFSET_TYPE float43 // Values from -9.000 to +9.000
  41. #else
  42. #define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
  43. #endif
  44. #endif
  45. #if ENABLED(BABYSTEP_ZPROBE_OFFSET) && Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
  46. #define BABYSTEP_TO_STR(N) ftostr43sign(N)
  47. #elif ENABLED(BABYSTEPPING)
  48. #define BABYSTEP_TO_STR(N) ftostr53sign(N)
  49. #endif
  50. ////////////////////////////////////////////
  51. ///////////// Base Menu Items //////////////
  52. ////////////////////////////////////////////
  53. class MenuItemBase {
  54. public:
  55. // Index to interject in the item label and/or for use by its action.
  56. static int8_t itemIndex;
  57. // An optional pointer for use in display or by the action
  58. static PGM_P itemString;
  59. // Store the index of the item ahead of use by indexed items
  60. FORCE_INLINE static void init(const int8_t ind=0, PGM_P const pstr=nullptr) { itemIndex = ind; itemString = pstr; }
  61. // Draw an item either selected (pre_char) or not (space) with post_char
  62. static void _draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
  63. // Draw an item either selected ('>') or not (space) with post_char
  64. FORCE_INLINE static void _draw(const bool sel, const uint8_t row, PGM_P const pstr, const char post_char) {
  65. _draw(sel, row, pstr, '>', post_char);
  66. }
  67. };
  68. class MenuItem_static : public MenuItemBase {
  69. public:
  70. static void draw(const uint8_t row, PGM_P const pstr, const uint8_t style=SS_DEFAULT, const char * const vstr=nullptr);
  71. };
  72. // CONFIRM_ITEM(LABEL,Y,N,FY,FN,V...),
  73. // YESNO_ITEM(LABEL,FY,FN,V...)
  74. class MenuItem_confirm : public MenuItemBase {
  75. public:
  76. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  77. _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
  78. }
  79. // Implemented for HD44780 and DOGM
  80. // Draw the prompt, buttons, and state
  81. static void draw_select_screen(
  82. PGM_P const yes, // Right option label
  83. PGM_P const no, // Left option label
  84. const bool yesno, // Is "yes" selected?
  85. PGM_P const pref, // Prompt prefix
  86. const char * const string, // Prompt runtime string
  87. PGM_P const suff // Prompt suffix
  88. );
  89. static void select_screen(
  90. PGM_P const yes, PGM_P const no,
  91. selectFunc_t yesFunc, selectFunc_t noFunc,
  92. PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr
  93. );
  94. static inline void select_screen(
  95. PGM_P const yes, PGM_P const no,
  96. selectFunc_t yesFunc, selectFunc_t noFunc,
  97. PGM_P const pref, const progmem_str string, PGM_P const suff=nullptr
  98. ) {
  99. char str[strlen_P((PGM_P)string) + 1];
  100. strcpy_P(str, (PGM_P)string);
  101. select_screen(yes, no, yesFunc, noFunc, pref, str, suff);
  102. }
  103. // Shortcut for prompt with "NO"/ "YES" labels
  104. 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) {
  105. select_screen(GET_TEXT(MSG_YES), GET_TEXT(MSG_NO), yesFunc, noFunc, pref, string, suff);
  106. }
  107. };
  108. // BACK_ITEM(LABEL)
  109. class MenuItem_back : public MenuItemBase {
  110. public:
  111. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr) {
  112. _draw(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]);
  113. }
  114. // Back Item action goes back one step in history
  115. FORCE_INLINE static void action(PGM_P const=nullptr) { ui.go_back(); }
  116. };
  117. // SUBMENU(LABEL, screen_handler)
  118. class MenuItem_submenu : public MenuItemBase {
  119. public:
  120. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  121. _draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
  122. }
  123. static inline void action(PGM_P const, const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
  124. };
  125. // Any menu item that invokes an immediate action
  126. class MenuItem_button : public MenuItemBase {
  127. public:
  128. // Button-y Items are selectable lines with no other indicator
  129. static inline void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  130. _draw(sel, row, pstr, '>', ' ');
  131. }
  132. };
  133. // GCODES_ITEM(LABEL, GCODES)
  134. class MenuItem_gcode : public MenuItem_button {
  135. public:
  136. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
  137. _draw(sel, row, pstr, '>', ' ');
  138. }
  139. static void action(PGM_P const, const char * const pgcode);
  140. static inline void action(PGM_P const pstr, const uint8_t, const char * const pgcode) { action(pstr, pgcode); }
  141. };
  142. // ACTION_ITEM(LABEL, FUNC)
  143. class MenuItem_function : public MenuItem_button {
  144. public:
  145. //static inline void action(PGM_P const, const uint8_t, const menuAction_t func) { (*func)(); };
  146. static inline void action(PGM_P const, const menuAction_t func) { (*func)(); };
  147. };
  148. #if ENABLED(SDSUPPORT)
  149. class CardReader;
  150. class MenuItem_sdbase {
  151. public:
  152. // Implemented for HD44780 and DOGM
  153. static void draw(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard, const bool isDir);
  154. };
  155. #endif
  156. ////////////////////////////////////////////
  157. ///////////// Edit Menu Items //////////////
  158. ////////////////////////////////////////////
  159. // The Menu Edit shadow value
  160. typedef union {
  161. bool state;
  162. float decimal;
  163. int8_t int8;
  164. int16_t int16;
  165. int32_t int32;
  166. uint8_t uint8;
  167. uint16_t uint16;
  168. uint32_t uint32;
  169. } chimera_t;
  170. extern chimera_t editable;
  171. // Base class for Menu Edit Items
  172. class MenuEditItemBase : public MenuItemBase {
  173. private:
  174. // These values are statically constructed by init() via action()
  175. // The action() method acts like the instantiator. The entire lifespan
  176. // of a menu item is within its declaration, so all these values decompose
  177. // into behavior and unused items get optimized out.
  178. static PGM_P editLabel;
  179. static void *editValue;
  180. static int32_t minEditValue, maxEditValue; // Encoder value range
  181. static screenFunc_t callbackFunc;
  182. static bool liveEdit;
  183. protected:
  184. typedef const char* (*strfunc_t)(const int32_t);
  185. typedef void (*loadfunc_t)(void *, const int32_t);
  186. static void goto_edit_screen(
  187. PGM_P const el, // Edit label
  188. void * const ev, // Edit value pointer
  189. const int32_t minv, // Encoder minimum
  190. const int32_t maxv, // Encoder maximum
  191. const uint16_t ep, // Initial encoder value
  192. const screenFunc_t cs, // MenuItem_type::draw_edit_screen => MenuEditItemBase::edit()
  193. const screenFunc_t cb, // Callback after edit
  194. const bool le // Flag to call cb() during editing
  195. );
  196. static void edit_screen(strfunc_t, loadfunc_t); // Edit value handler
  197. public:
  198. // Implemented for HD44780 and DOGM
  199. // Draw the current item at specified row with edit data
  200. static void draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const inStr, const bool pgm=false);
  201. // Implemented for HD44780 and DOGM
  202. // This low-level method is good to draw from anywhere
  203. static void draw_edit_screen(PGM_P const pstr, const char* const value);
  204. // This method is for the current menu item
  205. static inline void draw_edit_screen(const char* const value) { draw_edit_screen(editLabel, value); }
  206. };
  207. // Template for specific Menu Edit Item Types
  208. template<typename NAME>
  209. class TMenuEditItem : MenuEditItemBase {
  210. private:
  211. typedef typename NAME::type_t type_t;
  212. static inline float scale(const float value) { return NAME::scale(value); }
  213. static inline float unscale(const float value) { return NAME::unscale(value); }
  214. static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
  215. static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
  216. public:
  217. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t * const data, ...) {
  218. MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(*(data)));
  219. }
  220. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t (*pget)(), ...) {
  221. MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(pget()));
  222. }
  223. // Edit screen for this type of item
  224. static void edit_screen() { MenuEditItemBase::edit_screen(to_string, load); }
  225. static void action(
  226. PGM_P const pstr, // Edit label
  227. type_t * const ptr, // Value pointer
  228. const type_t minValue, // Value range
  229. const type_t maxValue,
  230. const screenFunc_t callback=nullptr, // Value update callback
  231. const bool live=false // Callback during editing
  232. ) {
  233. // Make sure minv and maxv fit within int32_t
  234. const int32_t minv = _MAX(scale(minValue), INT32_MIN),
  235. maxv = _MIN(scale(maxValue), INT32_MAX);
  236. goto_edit_screen(pstr, ptr, minv, maxv - minv, scale(*ptr) - minv,
  237. edit_screen, callback, live);
  238. }
  239. };
  240. // Provide a set of Edit Item Types which encompass a primitive
  241. // type, a string function, and a scale factor for edit and display.
  242. // These items call the Edit Item draw method passing the prepared string.
  243. #define __DOFIXfloat PROBE()
  244. #define _DOFIX(TYPE,V) TYPE(TERN(IS_PROBE(__DOFIX##TYPE),FIXFLOAT(V),(V)))
  245. #define DEFINE_MENU_EDIT_ITEM_TYPE(NAME, TYPE, STRFUNC, SCALE, V...) \
  246. struct MenuEditItemInfo_##NAME { \
  247. typedef TYPE type_t; \
  248. static inline float scale(const float value) { return value * (SCALE) + (V+0); } \
  249. static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \
  250. static inline const char* strfunc(const float value) { return STRFUNC(_DOFIX(TYPE,value)); } \
  251. }; \
  252. typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
  253. // NAME TYPE STRFUNC SCALE +ROUND
  254. DEFINE_MENU_EDIT_ITEM_TYPE(percent ,uint8_t ,ui8tostr4pctrj , 100.f/255.f, 0.5f); // 100% right-justified
  255. DEFINE_MENU_EDIT_ITEM_TYPE(int3 ,int16_t ,i16tostr3rj , 1 ); // 123, -12 right-justified
  256. DEFINE_MENU_EDIT_ITEM_TYPE(int4 ,int16_t ,i16tostr4signrj , 1 ); // 1234, -123 right-justified
  257. DEFINE_MENU_EDIT_ITEM_TYPE(int8 ,int8_t ,i8tostr3rj , 1 ); // 123, -12 right-justified
  258. DEFINE_MENU_EDIT_ITEM_TYPE(uint8 ,uint8_t ,ui8tostr3rj , 1 ); // 123 right-justified
  259. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_3 ,uint16_t ,ui16tostr3rj , 1 ); // 123 right-justified
  260. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_4 ,uint16_t ,ui16tostr4rj , 0.1f ); // 1234 right-justified
  261. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_5 ,uint16_t ,ui16tostr5rj , 0.01f ); // 12345 right-justified
  262. DEFINE_MENU_EDIT_ITEM_TYPE(float3 ,float ,ftostr3 , 1 ); // 123 right-justified
  263. DEFINE_MENU_EDIT_ITEM_TYPE(float42_52 ,float ,ftostr42_52 , 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45
  264. DEFINE_MENU_EDIT_ITEM_TYPE(float43 ,float ,ftostr43sign ,1000 ); // -1.234, _1.234, +1.234
  265. DEFINE_MENU_EDIT_ITEM_TYPE(float5 ,float ,ftostr5rj , 1 ); // 12345 right-justified
  266. DEFINE_MENU_EDIT_ITEM_TYPE(float5_25 ,float ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
  267. DEFINE_MENU_EDIT_ITEM_TYPE(float51 ,float ,ftostr51rj , 10 ); // 1234.5 right-justified
  268. DEFINE_MENU_EDIT_ITEM_TYPE(float31sign ,float ,ftostr31sign , 10 ); // +12.3
  269. DEFINE_MENU_EDIT_ITEM_TYPE(float41sign ,float ,ftostr41sign , 10 ); // +123.4
  270. DEFINE_MENU_EDIT_ITEM_TYPE(float51sign ,float ,ftostr51sign , 10 ); // +1234.5
  271. DEFINE_MENU_EDIT_ITEM_TYPE(float52sign ,float ,ftostr52sign , 100 ); // +123.45
  272. DEFINE_MENU_EDIT_ITEM_TYPE(long5 ,uint32_t ,ftostr5rj , 0.01f ); // 12345 right-justified
  273. DEFINE_MENU_EDIT_ITEM_TYPE(long5_25 ,uint32_t ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
  274. class MenuItem_bool : public MenuEditItemBase {
  275. public:
  276. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, const bool onoff) {
  277. MenuEditItemBase::draw(sel, row, pstr, onoff ? GET_TEXT(MSG_LCD_ON) : GET_TEXT(MSG_LCD_OFF), true);
  278. }
  279. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, bool * const data, ...) {
  280. draw(sel, row, pstr, *data);
  281. }
  282. FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const, bool (*pget)(), ...) {
  283. draw(sel, row, pstr, pget());
  284. }
  285. static void action(PGM_P const pstr, bool * const ptr, const screenFunc_t callbackFunc=nullptr);
  286. };
  287. ////////////////////////////////////////////
  288. //////////// Menu System Macros ////////////
  289. ////////////////////////////////////////////
  290. /**
  291. * Marlin's native menu screens work by running a loop from the top visible line index
  292. * to the bottom visible line index (according to how much the screen has been scrolled).
  293. * This complete loop is done on every menu screen call.
  294. *
  295. * The menu system is highly dynamic, so it doesn't know ahead of any menu loop which
  296. * items will be visible or hidden, so menu items don't have a fixed index number.
  297. *
  298. * During the loop, each menu item checks to see if its line is the current one. If it is,
  299. * then it checks to see if a click has arrived so it can run its action. If the action
  300. * doesn't redirect to another screen then the menu item calls its draw method.
  301. *
  302. * Menu item add-ons can do whatever they like.
  303. *
  304. * This mixture of drawing and processing inside a loop has the advantage that a single
  305. * line can be used to represent a menu item, and that is the rationale for this design.
  306. *
  307. * One of the pitfalls of this method is that DOGM displays call the screen handler 2x,
  308. * 4x, or 8x per screen update to draw just one segment of the screen. As a result, any
  309. * menu item that exists in two screen segments is drawn and processed twice per screen
  310. * update. With each item processed 5, 10, 20, or 40 times the logic has to be simple.
  311. *
  312. * To avoid repetition and side-effects, function calls for testing menu item conditions
  313. * should be done before the menu loop (START_MENU / START_SCREEN).
  314. */
  315. /**
  316. * SCREEN_OR_MENU_LOOP generates header code for a screen or menu
  317. *
  318. * encoderTopLine is the top menu line to display
  319. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  320. * _menuLineNr is the menu item to draw and process
  321. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  322. */
  323. #define SCREEN_OR_MENU_LOOP(IS_MENU) \
  324. scroll_screen(IS_MENU ? 1 : LCD_HEIGHT, IS_MENU); \
  325. int8_t _menuLineNr = encoderTopLine, _thisItemNr = 0; \
  326. bool _skipStatic = IS_MENU; UNUSED(_thisItemNr); \
  327. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  328. _thisItemNr = 0
  329. /**
  330. * START_SCREEN Opening code for a screen having only static items.
  331. * Do simplified scrolling of the entire screen.
  332. *
  333. * START_MENU Opening code for a screen with menu items.
  334. * Scroll as-needed to keep the selected line in view.
  335. */
  336. #define START_SCREEN() SCREEN_OR_MENU_LOOP(false)
  337. #define START_MENU() SCREEN_OR_MENU_LOOP(true)
  338. #define NEXT_ITEM() (++_thisItemNr)
  339. #define SKIP_ITEM() NEXT_ITEM()
  340. #define END_SCREEN() } screen_items = _thisItemNr
  341. #define END_MENU() END_SCREEN(); UNUSED(_skipStatic)
  342. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  343. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  344. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER) do{ if (USE_MULTIPLIER) ui.enable_encoder_multiplier(true); }while(0)
  345. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  346. #else
  347. #define ENCODER_RATE_MULTIPLY(F) NOOP
  348. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER)
  349. #endif
  350. /**
  351. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  352. *
  353. * MenuItem_<type>::draw(sel, row, label, arg3...)
  354. * MenuItem_<type>::action(arg3...)
  355. *
  356. * Examples:
  357. * BACK_ITEM(MSG_INFO_SCREEN)
  358. * MenuItem_back::action(plabel, ...)
  359. * MenuItem_back::draw(sel, row, plabel, ...)
  360. *
  361. * ACTION_ITEM(MSG_PAUSE_PRINT, lcd_sdcard_pause)
  362. * MenuItem_function::action(plabel, lcd_sdcard_pause)
  363. * MenuItem_function::draw(sel, row, plabel, lcd_sdcard_pause)
  364. *
  365. * EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  366. * MenuItem_int3::action(plabel, &feedrate_percentage, 10, 999)
  367. * MenuItem_int3::draw(sel, row, plabel, &feedrate_percentage, 10, 999)
  368. */
  369. #define _MENU_INNER_P(TYPE, USE_MULTIPLIER, PLABEL, V...) do { \
  370. PGM_P const plabel = PLABEL; \
  371. if (encoderLine == _thisItemNr && ui.use_click()) { \
  372. _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
  373. MenuItem_##TYPE::action(plabel, ##V); \
  374. if (ui.screen_changed) return; \
  375. } \
  376. if (ui.should_draw()) \
  377. MenuItem_##TYPE::draw \
  378. (encoderLine == _thisItemNr, _lcdLineNr, plabel, ##V); \
  379. }while(0)
  380. #define _MENU_ITEM_P(TYPE, V...) do { \
  381. if (_menuLineNr == _thisItemNr) { \
  382. _skipStatic = false; \
  383. _MENU_INNER_P(TYPE, ##V); \
  384. } \
  385. NEXT_ITEM(); \
  386. }while(0)
  387. // Indexed items set a global index value and optional data
  388. #define _MENU_ITEM_N_S_P(TYPE, N, S, V...) do{ \
  389. if (_menuLineNr == _thisItemNr) { \
  390. _skipStatic = false; \
  391. MenuItemBase::init(N, S); \
  392. _MENU_INNER_P(TYPE, ##V); \
  393. } \
  394. NEXT_ITEM(); \
  395. }while(0)
  396. // Indexed items set a global index value
  397. #define _MENU_ITEM_N_P(TYPE, N, V...) do{ \
  398. if (_menuLineNr == _thisItemNr) { \
  399. _skipStatic = false; \
  400. MenuItemBase::itemIndex = N; \
  401. _MENU_INNER_P(TYPE, ##V); \
  402. } \
  403. NEXT_ITEM(); \
  404. }while(0)
  405. // Items with a unique string
  406. #define _MENU_ITEM_S_P(TYPE, S, V...) do{ \
  407. if (_menuLineNr == _thisItemNr) { \
  408. _skipStatic = false; \
  409. MenuItemBase::itemString = S; \
  410. _MENU_INNER_P(TYPE, ##V); \
  411. } \
  412. NEXT_ITEM(); \
  413. }while(0)
  414. // STATIC_ITEM draws a styled string with no highlight.
  415. // Parameters: label [, style [, char *value] ]
  416. #define STATIC_ITEM_INNER_P(PLABEL, V...) do{ \
  417. if (_skipStatic && encoderLine <= _thisItemNr) { \
  418. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  419. ++encoderLine; \
  420. } \
  421. if (ui.should_draw()) \
  422. MenuItem_static::draw(_lcdLineNr, PLABEL, ##V); \
  423. } while(0)
  424. #define STATIC_ITEM_P(PLABEL, V...) do{ \
  425. if (_menuLineNr == _thisItemNr) \
  426. STATIC_ITEM_INNER_P(PLABEL, ##V); \
  427. NEXT_ITEM(); \
  428. } while(0)
  429. #define STATIC_ITEM_N_P(PLABEL, N, V...) do{ \
  430. if (_menuLineNr == _thisItemNr) { \
  431. MenuItemBase::init(N); \
  432. STATIC_ITEM_INNER_P(PLABEL, ##V); \
  433. } \
  434. NEXT_ITEM(); \
  435. }while(0)
  436. #define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(GET_TEXT(LABEL), ##V)
  437. #define STATIC_ITEM_N(LABEL, N, V...) STATIC_ITEM_N_P(GET_TEXT(LABEL), ##V)
  438. #define MENU_ITEM_N_S_P(TYPE, N, S, PLABEL, V...) _MENU_ITEM_N_S_P(TYPE, N, S, false, PLABEL, ##V)
  439. #define MENU_ITEM_N_S(TYPE, N, S, LABEL, V...) MENU_ITEM_N_S_P(TYPE, N, S, GET_TEXT(LABEL), ##V)
  440. #define MENU_ITEM_S_P(TYPE, S, PLABEL, V...) _MENU_ITEM_S_P(TYPE, S, false, PLABEL, ##V)
  441. #define MENU_ITEM_S(TYPE, S, LABEL, V...) MENU_ITEM_S_P(TYPE, S, GET_TEXT(LABEL), ##V)
  442. #define MENU_ITEM_N_P(TYPE, N, PLABEL, V...) _MENU_ITEM_N_P(TYPE, N, false, PLABEL, ##V)
  443. #define MENU_ITEM_N(TYPE, N, LABEL, V...) MENU_ITEM_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  444. #define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, false, PLABEL, ##V)
  445. #define MENU_ITEM(TYPE, LABEL, V...) MENU_ITEM_P(TYPE, GET_TEXT(LABEL), ##V)
  446. #define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)
  447. #define ACTION_ITEM_N_S_P(N, S, PLABEL, ACTION) MENU_ITEM_N_S_P(function, N, S, PLABEL, ACTION)
  448. #define ACTION_ITEM_N_S(N, S, LABEL, ACTION) ACTION_ITEM_N_S_P(N, S, GET_TEXT(LABEL), ACTION)
  449. #define ACTION_ITEM_S_P(S, PLABEL, ACTION) MENU_ITEM_S_P(function, S, PLABEL, ACTION)
  450. #define ACTION_ITEM_S(S, LABEL, ACTION) ACTION_ITEM_S_P(S, GET_TEXT(LABEL), ACTION)
  451. #define ACTION_ITEM_N_P(N, PLABEL, ACTION) MENU_ITEM_N_P(function, N, PLABEL, ACTION)
  452. #define ACTION_ITEM_N(N, LABEL, ACTION) ACTION_ITEM_N_P(N, GET_TEXT(LABEL), ACTION)
  453. #define ACTION_ITEM_P(PLABEL, ACTION) MENU_ITEM_P(function, PLABEL, ACTION)
  454. #define ACTION_ITEM(LABEL, ACTION) ACTION_ITEM_P(GET_TEXT(LABEL), ACTION)
  455. #define GCODES_ITEM_N_S_P(N, S, PLABEL, GCODES) MENU_ITEM_N_S_P(gcode, N, S, PLABEL, GCODES)
  456. #define GCODES_ITEM_N_S(N, S, LABEL, GCODES) GCODES_ITEM_N_S_P(N, S, GET_TEXT(LABEL), GCODES)
  457. #define GCODES_ITEM_S_P(S, PLABEL, GCODES) MENU_ITEM_S_P(gcode, S, PLABEL, GCODES)
  458. #define GCODES_ITEM_S(S, LABEL, GCODES) GCODES_ITEM_S_P(S, GET_TEXT(LABEL), GCODES)
  459. #define GCODES_ITEM_N_P(N, PLABEL, GCODES) MENU_ITEM_N_P(gcode, N, PLABEL, GCODES)
  460. #define GCODES_ITEM_N(N, LABEL, GCODES) GCODES_ITEM_N_P(N, GET_TEXT(LABEL), GCODES)
  461. #define GCODES_ITEM_P(PLABEL, GCODES) MENU_ITEM_P(gcode, PLABEL, GCODES)
  462. #define GCODES_ITEM(LABEL, GCODES) GCODES_ITEM_P(GET_TEXT(LABEL), GCODES)
  463. #define SUBMENU_N_S_P(N, S, PLABEL, DEST) MENU_ITEM_N_S_P(submenu, N, S, PLABEL, DEST)
  464. #define SUBMENU_N_S(N, S, LABEL, DEST) SUBMENU_N_S_P(N, S, GET_TEXT(LABEL), DEST)
  465. #define SUBMENU_S_P(S, PLABEL, DEST) MENU_ITEM_S_P(submenu, S, PLABEL, DEST)
  466. #define SUBMENU_S(S, LABEL, DEST) SUBMENU_S_P(S, GET_TEXT(LABEL), DEST)
  467. #define SUBMENU_N_P(N, PLABEL, DEST) MENU_ITEM_N_P(submenu, N, PLABEL, DEST)
  468. #define SUBMENU_N(N, LABEL, DEST) SUBMENU_N_P(N, GET_TEXT(LABEL), DEST)
  469. #define SUBMENU_P(PLABEL, DEST) MENU_ITEM_P(submenu, PLABEL, DEST)
  470. #define SUBMENU(LABEL, DEST) SUBMENU_P(GET_TEXT(LABEL), DEST)
  471. #define EDIT_ITEM_N_S_P(TYPE, N, S, PLABEL, V...) MENU_ITEM_N_S_P(TYPE, N, S, PLABEL, ##V)
  472. #define EDIT_ITEM_N_S(TYPE, N, S, LABEL, V...) EDIT_ITEM_N_S_P(TYPE, N, S, GET_TEXT(LABEL), ##V)
  473. #define EDIT_ITEM_S_P(TYPE, S, PLABEL, V...) MENU_ITEM_S_P(TYPE, S, PLABEL, ##V)
  474. #define EDIT_ITEM_S(TYPE, S, LABEL, V...) EDIT_ITEM_S_P(TYPE, S, GET_TEXT(LABEL), ##V)
  475. #define EDIT_ITEM_N_P(TYPE, N, PLABEL, V...) MENU_ITEM_N_P(TYPE, N, PLABEL, ##V)
  476. #define EDIT_ITEM_N(TYPE, N, LABEL, V...) EDIT_ITEM_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  477. #define EDIT_ITEM_P(TYPE, PLABEL, V...) MENU_ITEM_P(TYPE, PLABEL, ##V)
  478. #define EDIT_ITEM(TYPE, LABEL, V...) EDIT_ITEM_P(TYPE, GET_TEXT(LABEL), ##V)
  479. #define EDIT_ITEM_FAST_N_S_P(TYPE, N, S, PLABEL, V...) _MENU_ITEM_N_S_P(TYPE, N, S, true, PLABEL, ##V)
  480. #define EDIT_ITEM_FAST_N_S(TYPE, N, S, LABEL, V...) EDIT_ITEM_FAST_N_S_P(TYPE, N, S, true, GET_TEXT(LABEL), ##V)
  481. #define EDIT_ITEM_FAST_S_P(TYPE, S, PLABEL, V...) _MENU_ITEM_S_P(TYPE, S, true, PLABEL, ##V)
  482. #define EDIT_ITEM_FAST_S(TYPE, S, LABEL, V...) EDIT_ITEM_FAST_S_P(TYPE, S, GET_TEXT(LABEL), ##V)
  483. #define EDIT_ITEM_FAST_N_P(TYPE, N, PLABEL, V...) _MENU_ITEM_N_P(TYPE, N, true, PLABEL, ##V)
  484. #define EDIT_ITEM_FAST_N(TYPE, N, LABEL, V...) EDIT_ITEM_FAST_N_P(TYPE, N, GET_TEXT(LABEL), ##V)
  485. #define EDIT_ITEM_FAST_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, true, PLABEL, ##V)
  486. #define EDIT_ITEM_FAST(TYPE, LABEL, V...) EDIT_ITEM_FAST_P(TYPE, GET_TEXT(LABEL), ##V)
  487. #define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
  488. if (encoderLine == _thisItemNr && ui.use_click()) { \
  489. ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
  490. return; \
  491. } \
  492. if (ui.should_draw()) MenuItem_confirm::draw \
  493. (encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ##V); \
  494. }while(0)
  495. // Indexed items set a global index value and optional data
  496. #define _CONFIRM_ITEM_P(PLABEL, V...) do { \
  497. if (_menuLineNr == _thisItemNr) { \
  498. _skipStatic = false; \
  499. _CONFIRM_ITEM_INNER_P(PLABEL, ##V); \
  500. } \
  501. NEXT_ITEM(); \
  502. }while(0)
  503. // Indexed items set a global index value
  504. #define _CONFIRM_ITEM_N_S_P(N, S, V...) do{ \
  505. if (_menuLineNr == _thisItemNr) { \
  506. _skipStatic = false; \
  507. MenuItemBase::init(N, S); \
  508. _CONFIRM_ITEM_INNER_P(TYPE, ##V); \
  509. } \
  510. NEXT_ITEM(); \
  511. }while(0)
  512. // Indexed items set a global index value
  513. #define _CONFIRM_ITEM_N_P(N, V...) _CONFIRM_ITEM_N_S_P(N, nullptr, V)
  514. #define CONFIRM_ITEM_P(PLABEL,A,B,V...) _CONFIRM_ITEM_P(PLABEL, GET_TEXT(A), GET_TEXT(B), ##V)
  515. #define CONFIRM_ITEM(LABEL, V...) CONFIRM_ITEM_P(GET_TEXT(LABEL), ##V)
  516. #define YESNO_ITEM_P(PLABEL, V...) _CONFIRM_ITEM_P(PLABEL, ##V)
  517. #define YESNO_ITEM(LABEL, V...) YESNO_ITEM_P(GET_TEXT(LABEL), ##V)
  518. #define CONFIRM_ITEM_N_S_P(N,S,PLABEL,A,B,V...) _CONFIRM_ITEM_N_S_P(N, S, PLABEL, GET_TEXT(A), GET_TEXT(B), ##V)
  519. #define CONFIRM_ITEM_N_S(N,S,LABEL,V...) CONFIRM_ITEM_N_S_P(N, S, GET_TEXT(LABEL), ##V)
  520. #define CONFIRM_ITEM_N_P(N,PLABEL,A,B,V...) _CONFIRM_ITEM_N_P(N, PLABEL, GET_TEXT(A), GET_TEXT(B), ##V)
  521. #define CONFIRM_ITEM_N(N,LABEL, V...) CONFIRM_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
  522. #define YESNO_ITEM_N_S_P(N,S,PLABEL, V...) _CONFIRM_ITEM_N_S_P(N, S, PLABEL, ##V)
  523. #define YESNO_ITEM_N_S(N,S,LABEL, V...) YESNO_ITEM_N_S_P(N, S, GET_TEXT(LABEL), ##V)
  524. #define YESNO_ITEM_N_P(N,PLABEL, V...) _CONFIRM_ITEM_N_P(N, PLABEL, ##V)
  525. #define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
  526. ////////////////////////////////////////////
  527. /////////////// Menu Screens ///////////////
  528. ////////////////////////////////////////////
  529. void menu_main();
  530. void menu_move();
  531. #if ENABLED(SDSUPPORT)
  532. void menu_media();
  533. #endif
  534. // First Fan Speed title in "Tune" and "Control>Temperature" menus
  535. #if HAS_FAN && HAS_FAN0
  536. #if FAN_COUNT > 1
  537. #define FAN_SPEED_1_SUFFIX " 1"
  538. #else
  539. #define FAN_SPEED_1_SUFFIX ""
  540. #endif
  541. #endif
  542. ////////////////////////////////////////////
  543. //////// Menu Item Helper Functions ////////
  544. ////////////////////////////////////////////
  545. void lcd_move_z();
  546. void _lcd_draw_homing();
  547. #define HAS_LINE_TO_Z ANY(DELTA, PROBE_MANUALLY, MESH_BED_LEVELING, LEVEL_BED_CORNERS)
  548. #if HAS_LINE_TO_Z
  549. void line_to_z(const float &z);
  550. #endif
  551. #if HAS_GRAPHICAL_LCD && EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  552. void _lcd_zoffset_overlay_gfx(const float zvalue);
  553. #endif
  554. #if ENABLED(LEVEL_BED_CORNERS)
  555. void _lcd_level_bed_corners();
  556. #endif
  557. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  558. void _lcd_toggle_bed_leveling();
  559. #endif
  560. #if ENABLED(BABYSTEPPING)
  561. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  562. void lcd_babystep_zoffset();
  563. #else
  564. void lcd_babystep_z();
  565. #endif
  566. #if ENABLED(BABYSTEP_MILLIMETER_UNITS)
  567. #define BABYSTEP_SIZE_X int32_t((BABYSTEP_MULTIPLICATOR_XY) * planner.settings.axis_steps_per_mm[X_AXIS])
  568. #define BABYSTEP_SIZE_Y int32_t((BABYSTEP_MULTIPLICATOR_XY) * planner.settings.axis_steps_per_mm[Y_AXIS])
  569. #define BABYSTEP_SIZE_Z int32_t((BABYSTEP_MULTIPLICATOR_Z) * planner.settings.axis_steps_per_mm[Z_AXIS])
  570. #else
  571. #define BABYSTEP_SIZE_X BABYSTEP_MULTIPLICATOR_XY
  572. #define BABYSTEP_SIZE_Y BABYSTEP_MULTIPLICATOR_XY
  573. #define BABYSTEP_SIZE_Z BABYSTEP_MULTIPLICATOR_Z
  574. #endif
  575. #endif
  576. #if ENABLED(POWER_LOSS_RECOVERY)
  577. void menu_job_recovery();
  578. #endif
  579. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  580. void touch_screen_calibration();
  581. #endif