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_item.h 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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 "menu.h"
  24. #include "../marlinui.h"
  25. #include "../../gcode/queue.h" // for inject
  26. #include "../../inc/MarlinConfigPre.h"
  27. #if ENABLED(LASER_SYNCHRONOUS_M106_M107)
  28. #include "../../module/planner.h"
  29. #endif
  30. ////////////////////////////////////////////
  31. ///////////// Base Menu Items //////////////
  32. ////////////////////////////////////////////
  33. // SUBMENU(LABEL, screen_handler)
  34. class MenuItem_submenu : public MenuItemBase {
  35. public:
  36. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, ...) {
  37. _draw(sel, row, fstr, '>', LCD_STR_ARROW_RIGHT[0]);
  38. }
  39. static void action(FSTR_P const, const screenFunc_t func) { ui.push_current_screen(); ui.goto_screen(func); }
  40. };
  41. // Any menu item that invokes an immediate action
  42. class MenuItem_button : public MenuItemBase {
  43. public:
  44. // Button-y Items are selectable lines with no other indicator
  45. static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, ...) {
  46. _draw(sel, row, fstr, '>', ' ');
  47. }
  48. };
  49. // ACTION_ITEM(LABEL, FUNC)
  50. class MenuItem_function : public MenuItem_button {
  51. public:
  52. //static void action(FSTR_P const, const uint8_t, const menuAction_t func) { (*func)(); };
  53. static void action(FSTR_P const, const menuAction_t func) { if (func) (*func)(); };
  54. };
  55. // GCODES_ITEM(LABEL, GCODES)
  56. class MenuItem_gcode : public MenuItem_button {
  57. public:
  58. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, ...) {
  59. _draw(sel, row, fstr, '>', ' ');
  60. }
  61. static void action(FSTR_P const, FSTR_P const fgcode) { queue.inject(fgcode); }
  62. static void action(FSTR_P const fstr, const uint8_t, FSTR_P const fgcode) { action(fstr, fgcode); }
  63. };
  64. ////////////////////////////////////////////
  65. ///////////// Edit Menu Items //////////////
  66. ////////////////////////////////////////////
  67. // Template for specific Menu Edit Item Types
  68. template<typename NAME>
  69. class TMenuEditItem : MenuEditItemBase {
  70. private:
  71. typedef typename NAME::type_t type_t;
  72. static float scale(const_float_t value) { return NAME::scale(value); }
  73. static float unscale(const_float_t value) { return NAME::unscale(value); }
  74. static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
  75. static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
  76. public:
  77. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, type_t * const data, ...) {
  78. MenuEditItemBase::draw(sel, row, fstr, NAME::strfunc(*(data)));
  79. }
  80. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, type_t (*pget)(), ...) {
  81. MenuEditItemBase::draw(sel, row, fstr, NAME::strfunc(pget()));
  82. }
  83. // Edit screen for this type of item
  84. static void edit_screen() { MenuEditItemBase::edit_screen(to_string, load); }
  85. static void action(
  86. FSTR_P const fstr, // Edit label
  87. type_t * const ptr, // Value pointer
  88. const type_t minValue, // Value range
  89. const type_t maxValue,
  90. const screenFunc_t callback=nullptr, // Value update callback
  91. const bool live=false // Callback during editing
  92. ) {
  93. // Make sure minv and maxv fit within int32_t
  94. const int32_t minv = _MAX(scale(minValue), INT32_MIN),
  95. maxv = _MIN(scale(maxValue), INT32_MAX);
  96. goto_edit_screen(fstr, ptr, minv, maxv - minv, scale(*ptr) - minv,
  97. edit_screen, callback, live);
  98. }
  99. };
  100. /**
  101. * DEFINE_MENU_EDIT_ITEM_TYPE(int3, int16_t, i16tostr3rj, 1)
  102. *
  103. * Define struct types for use by EDIT_ITEM(...) macros, which encompass
  104. * a primitive storage type, a string function, and a scale factor for edit / display.
  105. * The EDIT_ITEM macros take care of calling action and draw methods as needed.
  106. *
  107. * For example, DEFINE_MENU_EDIT_ITEM_TYPE(percent, uint8_t, ui8tostr4pctrj, 100.f/255.f, +0.5f) expands into:
  108. *
  109. * struct MenuEditItemInfo_percent {
  110. * typedef uint8_t type_t;
  111. * static float scale(const_float_t value) { return value * (100.f/255.f) +0.5f; }
  112. * static float unscale(const_float_t value) { return value / (100.f/255.f) +0.5f; }
  113. * static const char* strfunc(const_float_t value) { return ui8tostr4pctrj(_DOFIX(uint8_t,value)); }
  114. * };
  115. * typedef TMenuEditItem<MenuEditItemInfo_percent> MenuItem_percent
  116. */
  117. #define __DOFIXfloat PROBE()
  118. #define _DOFIX(TYPE,V) TYPE(TERN(IS_PROBE(__DOFIX##TYPE),FIXFLOAT(V),(V)))
  119. #define DEFINE_MENU_EDIT_ITEM_TYPE(NAME, TYPE, STRFUNC, SCALE, ETC...) \
  120. struct MenuEditItemInfo_##NAME { \
  121. typedef TYPE type_t; \
  122. static float scale(const_float_t value) { return value * (SCALE) ETC; } \
  123. static float unscale(const_float_t value) { return value / (SCALE) ETC; } \
  124. static const char* strfunc(const_float_t value) { return STRFUNC(_DOFIX(TYPE,value)); } \
  125. }; \
  126. typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
  127. // NAME TYPE STRFUNC SCALE ROUND
  128. DEFINE_MENU_EDIT_ITEM_TYPE(percent ,uint8_t ,ui8tostr4pctrj , 100.f/255.f, +0.5f); // 100% right-justified
  129. DEFINE_MENU_EDIT_ITEM_TYPE(percent_3 ,uint8_t ,pcttostrpctrj , 1 ); // 100% right-justified
  130. DEFINE_MENU_EDIT_ITEM_TYPE(int3 ,int16_t ,i16tostr3rj , 1 ); // 123, -12 right-justified
  131. DEFINE_MENU_EDIT_ITEM_TYPE(int4 ,int16_t ,i16tostr4signrj , 1 ); // 1234, -123 right-justified
  132. DEFINE_MENU_EDIT_ITEM_TYPE(int8 ,int8_t ,i8tostr3rj , 1 ); // 123, -12 right-justified
  133. DEFINE_MENU_EDIT_ITEM_TYPE(uint8 ,uint8_t ,ui8tostr3rj , 1 ); // 123 right-justified
  134. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_3 ,uint16_t ,ui16tostr3rj , 1 ); // 123 right-justified
  135. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_4 ,uint16_t ,ui16tostr4rj , 0.1f ); // 1234 right-justified
  136. DEFINE_MENU_EDIT_ITEM_TYPE(uint16_5 ,uint16_t ,ui16tostr5rj , 0.01f ); // 12345 right-justified
  137. DEFINE_MENU_EDIT_ITEM_TYPE(float3 ,float ,ftostr3 , 1 ); // 123 right-justified
  138. DEFINE_MENU_EDIT_ITEM_TYPE(float42_52 ,float ,ftostr42_52 , 100 ); // _2.34, 12.34, -2.34 or 123.45, -23.45
  139. DEFINE_MENU_EDIT_ITEM_TYPE(float43 ,float ,ftostr43sign ,1000 ); // -1.234, _1.234, +1.234
  140. DEFINE_MENU_EDIT_ITEM_TYPE(float4 ,float ,ftostr4sign , 1 ); // 1234 right-justified
  141. DEFINE_MENU_EDIT_ITEM_TYPE(float5 ,float ,ftostr5rj , 1 ); // 12345 right-justified
  142. DEFINE_MENU_EDIT_ITEM_TYPE(float5_25 ,float ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
  143. DEFINE_MENU_EDIT_ITEM_TYPE(float61 ,float ,ftostr61rj , 10 ); // 12345.6 right-justified
  144. DEFINE_MENU_EDIT_ITEM_TYPE(float31sign ,float ,ftostr31sign , 10 ); // +12.3
  145. DEFINE_MENU_EDIT_ITEM_TYPE(float41sign ,float ,ftostr41sign , 10 ); // +123.4
  146. DEFINE_MENU_EDIT_ITEM_TYPE(float51sign ,float ,ftostr51sign , 10 ); // +1234.5
  147. DEFINE_MENU_EDIT_ITEM_TYPE(float52sign ,float ,ftostr52sign , 100 ); // +123.45
  148. DEFINE_MENU_EDIT_ITEM_TYPE(long5 ,uint32_t ,ftostr5rj , 0.01f ); // 12345 right-justified
  149. DEFINE_MENU_EDIT_ITEM_TYPE(long5_25 ,uint32_t ,ftostr5rj , 0.04f ); // 12345 right-justified (25 increment)
  150. #if HAS_BED_PROBE
  151. #if Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
  152. #define LCD_Z_OFFSET_TYPE float43 // Values from -9.000 to +9.000
  153. #else
  154. #define LCD_Z_OFFSET_TYPE float42_52 // Values from -99.99 to 99.99
  155. #endif
  156. #endif
  157. class MenuItem_bool : public MenuEditItemBase {
  158. public:
  159. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, const bool onoff) {
  160. MenuEditItemBase::draw(sel, row, fstr, onoff ? GET_TEXT_F(MSG_LCD_ON) : GET_TEXT_F(MSG_LCD_OFF));
  161. }
  162. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, bool * const data, ...) {
  163. draw(sel, row, fstr, *data);
  164. }
  165. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, FSTR_P const, bool (*pget)(), ...) {
  166. draw(sel, row, fstr, pget());
  167. }
  168. static void action(FSTR_P const fstr, bool * const ptr, const screenFunc_t callbackFunc=nullptr) {
  169. *ptr ^= true; ui.refresh();
  170. if (callbackFunc) (*callbackFunc)();
  171. }
  172. };
  173. /**
  174. * ////////////////////////////////////////////
  175. * //////////// Menu System Macros ////////////
  176. * ////////////////////////////////////////////
  177. *
  178. * Marlin's native menu screens work by running a loop from the top visible line index
  179. * to the bottom visible line index (according to how much the screen has been scrolled).
  180. * This complete loop is done on every menu screen call.
  181. *
  182. * The menu system is highly dynamic, so it doesn't know ahead of any menu loop which
  183. * items will be visible or hidden, so menu items don't have a fixed index number.
  184. *
  185. * During the loop, each menu item checks to see if its line is the current one. If it is,
  186. * then it checks to see if a click has arrived so it can run its action. If the action
  187. * doesn't redirect to another screen then the menu item calls its draw method.
  188. *
  189. * Menu item add-ons can do whatever they like.
  190. *
  191. * This mixture of drawing and processing inside a loop has the advantage that a single
  192. * line can be used to represent a menu item, and that is the rationale for this design.
  193. *
  194. * One of the pitfalls of this method is that DOGM displays call the screen handler 2x,
  195. * 4x, or 8x per screen update to draw just one segment of the screen. As a result, any
  196. * menu item that exists in two screen segments is drawn and processed twice per screen
  197. * update. With each item processed 5, 10, 20, or 40 times the logic has to be simple.
  198. *
  199. * To avoid repetition and side-effects, function calls for testing menu item conditions
  200. * should be done before the menu loop (START_MENU / START_SCREEN).
  201. */
  202. /**
  203. * SCREEN_OR_MENU_LOOP generates header code for a screen or menu
  204. *
  205. * encoderTopLine is the top menu line to display
  206. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  207. * _menuLineNr is the menu item to draw and process
  208. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  209. */
  210. #define SCREEN_OR_MENU_LOOP(IS_MENU) \
  211. scroll_screen(IS_MENU ? 1 : LCD_HEIGHT, IS_MENU); \
  212. int8_t _menuLineNr = encoderTopLine, _thisItemNr = 0; \
  213. bool _skipStatic = IS_MENU; UNUSED(_thisItemNr); \
  214. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  215. _thisItemNr = 0
  216. /**
  217. * START_SCREEN Opening code for a screen having only static items.
  218. * Do simplified scrolling of the entire screen.
  219. *
  220. * START_MENU Opening code for a screen with menu items.
  221. * Scroll as-needed to keep the selected line in view.
  222. */
  223. #define START_SCREEN() SCREEN_OR_MENU_LOOP(false)
  224. #define START_MENU() SCREEN_OR_MENU_LOOP(true)
  225. #define NEXT_ITEM() (++_thisItemNr)
  226. #define SKIP_ITEM() NEXT_ITEM()
  227. #define END_SCREEN() } screen_items = _thisItemNr
  228. #define END_MENU() END_SCREEN(); UNUSED(_skipStatic)
  229. /**
  230. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  231. *
  232. * MenuItem_<type>::draw(sel, row, label, arg3...)
  233. * MenuItem_<type>::action(arg3...)
  234. *
  235. * Examples:
  236. * BACK_ITEM(MSG_INFO_SCREEN)
  237. * MenuItem_back::action(flabel, ...)
  238. * MenuItem_back::draw(sel, row, flabel, ...)
  239. *
  240. * ACTION_ITEM(MSG_PAUSE_PRINT, lcd_sdcard_pause)
  241. * MenuItem_function::action(flabel, lcd_sdcard_pause)
  242. * MenuItem_function::draw(sel, row, flabel, lcd_sdcard_pause)
  243. *
  244. * EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  245. * MenuItem_int3::action(flabel, &feedrate_percentage, 10, 999)
  246. * MenuItem_int3::draw(sel, row, flabel, &feedrate_percentage, 10, 999)
  247. */
  248. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  249. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER) do{ if (USE_MULTIPLIER) ui.enable_encoder_multiplier(true); }while(0)
  250. #else
  251. #define _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER)
  252. #endif
  253. #define _MENU_INNER_F(TYPE, USE_MULTIPLIER, FLABEL, V...) do { \
  254. FSTR_P const flabel = FLABEL; \
  255. if (encoderLine == _thisItemNr && ui.use_click()) { \
  256. _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
  257. MenuItem_##TYPE::action(flabel, ##V); \
  258. if (ui.screen_changed) return; \
  259. } \
  260. if (ui.should_draw()) \
  261. MenuItem_##TYPE::draw \
  262. (encoderLine == _thisItemNr, _lcdLineNr, flabel, ##V); \
  263. }while(0)
  264. // Item with optional data
  265. #define _MENU_ITEM_F(TYPE, V...) do { \
  266. if (_menuLineNr == _thisItemNr) { \
  267. _skipStatic = false; \
  268. _MENU_INNER_F(TYPE, ##V); \
  269. } \
  270. NEXT_ITEM(); \
  271. }while(0)
  272. // Item with index value, C-string, and optional data
  273. #define _MENU_ITEM_N_S_F(TYPE, N, S, V...) do{ \
  274. if (_menuLineNr == _thisItemNr) { \
  275. _skipStatic = false; \
  276. MenuItemBase::init(N, S); \
  277. _MENU_INNER_F(TYPE, ##V); \
  278. } \
  279. NEXT_ITEM(); \
  280. }while(0)
  281. // Item with index value and F-string
  282. #define _MENU_ITEM_N_f_F(TYPE, N, f, V...) do{ \
  283. if (_menuLineNr == _thisItemNr) { \
  284. _skipStatic = false; \
  285. MenuItemBase::init(N, f); \
  286. _MENU_INNER_F(TYPE, ##V); \
  287. } \
  288. NEXT_ITEM(); \
  289. }while(0)
  290. // Item with index value
  291. #define _MENU_ITEM_N_F(TYPE, N, V...) do{ \
  292. if (_menuLineNr == _thisItemNr) { \
  293. _skipStatic = false; \
  294. MenuItemBase::init(N); \
  295. _MENU_INNER_F(TYPE, ##V); \
  296. } \
  297. NEXT_ITEM(); \
  298. }while(0)
  299. // Items with a unique string
  300. #define _MENU_ITEM_S_F(TYPE, S, V...) do{ \
  301. if (_menuLineNr == _thisItemNr) { \
  302. _skipStatic = false; \
  303. MenuItemBase::init(0, S); \
  304. _MENU_INNER_F(TYPE, ##V); \
  305. } \
  306. NEXT_ITEM(); \
  307. }while(0)
  308. // Items with a unique F-string
  309. #define _MENU_ITEM_f_F(TYPE, f, V...) do{ \
  310. if (_menuLineNr == _thisItemNr) { \
  311. _skipStatic = false; \
  312. MenuItemBase::init(0, f); \
  313. _MENU_INNER_F(TYPE, ##V); \
  314. } \
  315. NEXT_ITEM(); \
  316. }while(0)
  317. // STATIC_ITEM draws a styled string with no highlight.
  318. // Parameters: label [, style [, char *value] ]
  319. #define STATIC_ITEM_INNER_F(FLABEL, V...) do{ \
  320. if (_skipStatic && encoderLine <= _thisItemNr) { \
  321. ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  322. ++encoderLine; \
  323. } \
  324. if (ui.should_draw()) \
  325. MenuItem_static::draw(_lcdLineNr, FLABEL, ##V); \
  326. } while(0)
  327. #define STATIC_ITEM_F(FLABEL, V...) do{ \
  328. if (_menuLineNr == _thisItemNr) \
  329. STATIC_ITEM_INNER_F(FLABEL, ##V); \
  330. NEXT_ITEM(); \
  331. } while(0)
  332. #define STATIC_ITEM_N_F(N, FLABEL, V...) do{ \
  333. if (_menuLineNr == _thisItemNr) { \
  334. MenuItemBase::init(N); \
  335. STATIC_ITEM_INNER_F(FLABEL, ##V); \
  336. } \
  337. NEXT_ITEM(); \
  338. }while(0)
  339. // PSTRING_ITEM is like STATIC_ITEM but it takes
  340. // two PSTRs with the style as the last parameter.
  341. #define PSTRING_ITEM_F(FLABEL, PVAL, STYL) do{ \
  342. constexpr int m = 20; \
  343. char msg[m+1]; \
  344. msg[0] = ':'; msg[1] = ' '; \
  345. strncpy_P(msg+2, PSTR(PVAL), m-2); \
  346. if (msg[m-1] & 0x80) msg[m-1] = '\0'; \
  347. STATIC_ITEM_F(FLABEL, STYL, msg); \
  348. }while(0)
  349. #define PSTRING_ITEM(LABEL, V...) PSTRING_ITEM_F(GET_TEXT_F(LABEL), ##V)
  350. #define STATIC_ITEM(LABEL, V...) STATIC_ITEM_F(GET_TEXT_F(LABEL), ##V)
  351. #define STATIC_ITEM_N(N, LABEL, V...) STATIC_ITEM_N_F(N, GET_TEXT_F(LABEL), ##V)
  352. // Menu item with index and composed C-string substitution
  353. #define MENU_ITEM_N_S_F(TYPE, N, S, FLABEL, V...) _MENU_ITEM_N_S_F(TYPE, N, S, false, FLABEL, ##V)
  354. #define MENU_ITEM_N_S(TYPE, N, S, LABEL, V...) MENU_ITEM_N_S_F(TYPE, N, S, GET_TEXT_F(LABEL), ##V)
  355. // Menu item with composed C-string substitution
  356. #define MENU_ITEM_S_F(TYPE, S, FLABEL, V...) _MENU_ITEM_S_F(TYPE, S, false, FLABEL, ##V)
  357. #define MENU_ITEM_S(TYPE, S, LABEL, V...) MENU_ITEM_S_F(TYPE, S, GET_TEXT_F(LABEL), ##V)
  358. // Menu item substitution, indexed
  359. #define MENU_ITEM_N_F(TYPE, N, FLABEL, V...) _MENU_ITEM_N_F(TYPE, N, false, FLABEL, ##V)
  360. #define MENU_ITEM_N(TYPE, N, LABEL, V...) MENU_ITEM_N_F(TYPE, N, GET_TEXT_F(LABEL), ##V)
  361. // Basic menu items, no substitution
  362. #define MENU_ITEM_F(TYPE, FLABEL, V...) _MENU_ITEM_F(TYPE, false, FLABEL, ##V)
  363. #define MENU_ITEM(TYPE, LABEL, V...) MENU_ITEM_F(TYPE, GET_TEXT_F(LABEL), ##V)
  364. // Predefined menu item types //
  365. #if DISABLED(DISABLE_ENCODER)
  366. #define BACK_ITEM_F(FLABEL) MENU_ITEM_F(back, FLABEL)
  367. #define BACK_ITEM(LABEL) MENU_ITEM(back, LABEL)
  368. #else
  369. #define BACK_ITEM_F(FLABEL) NOOP
  370. #define BACK_ITEM(LABEL) NOOP
  371. #endif
  372. #define ACTION_ITEM_N_S_F(N, S, FLABEL, ACTION) MENU_ITEM_N_S_F(function, N, S, FLABEL, ACTION)
  373. #define ACTION_ITEM_N_S(N, S, LABEL, ACTION) ACTION_ITEM_N_S_F(N, S, GET_TEXT_F(LABEL), ACTION)
  374. #define ACTION_ITEM_S_F(S, FLABEL, ACTION) MENU_ITEM_S_F(function, S, FLABEL, ACTION)
  375. #define ACTION_ITEM_S(S, LABEL, ACTION) ACTION_ITEM_S_F(S, GET_TEXT_F(LABEL), ACTION)
  376. #define ACTION_ITEM_N_F(N, FLABEL, ACTION) MENU_ITEM_N_F(function, N, FLABEL, ACTION)
  377. #define ACTION_ITEM_N(N, LABEL, ACTION) ACTION_ITEM_N_F(N, GET_TEXT_F(LABEL), ACTION)
  378. #define ACTION_ITEM_F(FLABEL, ACTION) MENU_ITEM_F(function, FLABEL, ACTION)
  379. #define ACTION_ITEM(LABEL, ACTION) ACTION_ITEM_F(GET_TEXT_F(LABEL), ACTION)
  380. #define GCODES_ITEM_N_S_F(N, S, FLABEL, GCODES) MENU_ITEM_N_S_F(gcode, N, S, FLABEL, GCODES)
  381. #define GCODES_ITEM_N_S(N, S, LABEL, GCODES) GCODES_ITEM_N_S_F(N, S, GET_TEXT_F(LABEL), GCODES)
  382. #define GCODES_ITEM_S_F(S, FLABEL, GCODES) MENU_ITEM_S_F(gcode, S, FLABEL, GCODES)
  383. #define GCODES_ITEM_S(S, LABEL, GCODES) GCODES_ITEM_S_F(S, GET_TEXT_F(LABEL), GCODES)
  384. #define GCODES_ITEM_N_F(N, FLABEL, GCODES) MENU_ITEM_N_F(gcode, N, FLABEL, GCODES)
  385. #define GCODES_ITEM_N(N, LABEL, GCODES) GCODES_ITEM_N_F(N, GET_TEXT_F(LABEL), GCODES)
  386. #define GCODES_ITEM_F(FLABEL, GCODES) MENU_ITEM_F(gcode, FLABEL, GCODES)
  387. #define GCODES_ITEM(LABEL, GCODES) GCODES_ITEM_F(GET_TEXT_F(LABEL), GCODES)
  388. #define SUBMENU_N_S_F(N, S, FLABEL, DEST) MENU_ITEM_N_S_F(submenu, N, S, FLABEL, DEST)
  389. #define SUBMENU_N_S(N, S, LABEL, DEST) SUBMENU_N_S_F(N, S, GET_TEXT_F(LABEL), DEST)
  390. #define SUBMENU_S_F(S, FLABEL, DEST) MENU_ITEM_S_F(submenu, S, FLABEL, DEST)
  391. #define SUBMENU_S(S, LABEL, DEST) SUBMENU_S_F(S, GET_TEXT_F(LABEL), DEST)
  392. #define SUBMENU_N_F(N, FLABEL, DEST) MENU_ITEM_N_F(submenu, N, FLABEL, DEST)
  393. #define SUBMENU_N(N, LABEL, DEST) SUBMENU_N_F(N, GET_TEXT_F(LABEL), DEST)
  394. #define SUBMENU_F(FLABEL, DEST) MENU_ITEM_F(submenu, FLABEL, DEST)
  395. #define SUBMENU(LABEL, DEST) SUBMENU_F(GET_TEXT_F(LABEL), DEST)
  396. #define EDIT_ITEM_N_S_F(TYPE, N, S, FLABEL, V...) MENU_ITEM_N_S_F(TYPE, N, S, FLABEL, ##V)
  397. #define EDIT_ITEM_N_S(TYPE, N, S, LABEL, V...) EDIT_ITEM_N_S_F(TYPE, N, S, GET_TEXT_F(LABEL), ##V)
  398. #define EDIT_ITEM_S_F(TYPE, S, FLABEL, V...) MENU_ITEM_S_F(TYPE, S, FLABEL, ##V)
  399. #define EDIT_ITEM_S(TYPE, S, LABEL, V...) EDIT_ITEM_S_F(TYPE, S, GET_TEXT_F(LABEL), ##V)
  400. #define EDIT_ITEM_N_F(TYPE, N, FLABEL, V...) MENU_ITEM_N_F(TYPE, N, FLABEL, ##V)
  401. #define EDIT_ITEM_N(TYPE, N, LABEL, V...) EDIT_ITEM_N_F(TYPE, N, GET_TEXT_F(LABEL), ##V)
  402. #define EDIT_ITEM_F(TYPE, FLABEL, V...) MENU_ITEM_F(TYPE, FLABEL, ##V)
  403. #define EDIT_ITEM(TYPE, LABEL, V...) EDIT_ITEM_F(TYPE, GET_TEXT_F(LABEL), ##V)
  404. #define EDIT_ITEM_FAST_N_S_F(TYPE, N, S, FLABEL, V...) _MENU_ITEM_N_S_F(TYPE, N, S, true, FLABEL, ##V)
  405. #define EDIT_ITEM_FAST_N_S(TYPE, N, S, LABEL, V...) EDIT_ITEM_FAST_N_S_F(TYPE, N, S, true, GET_TEXT_F(LABEL), ##V)
  406. #define EDIT_ITEM_FAST_S_F(TYPE, S, FLABEL, V...) _MENU_ITEM_S_F(TYPE, S, true, FLABEL, ##V)
  407. #define EDIT_ITEM_FAST_S(TYPE, S, LABEL, V...) EDIT_ITEM_FAST_S_F(TYPE, S, GET_TEXT_F(LABEL), ##V)
  408. #define EDIT_ITEM_FAST_N_F(TYPE, N, FLABEL, V...) _MENU_ITEM_N_F(TYPE, N, true, FLABEL, ##V)
  409. #define EDIT_ITEM_FAST_N(TYPE, N, LABEL, V...) EDIT_ITEM_FAST_N_F(TYPE, N, GET_TEXT_F(LABEL), ##V)
  410. #define EDIT_ITEM_FAST_F(TYPE, FLABEL, V...) _MENU_ITEM_F(TYPE, true, FLABEL, ##V)
  411. #define EDIT_ITEM_FAST(TYPE, LABEL, V...) EDIT_ITEM_FAST_F(TYPE, GET_TEXT_F(LABEL), ##V)
  412. // F-string substitution instead of C-string //
  413. #define MENU_ITEM_N_f_F(TYPE, N, f, FLABEL, V...) _MENU_ITEM_N_f_F(TYPE, N, f, false, FLABEL, ##V)
  414. #define MENU_ITEM_N_f(TYPE, N, f, LABEL, V...) MENU_ITEM_N_f_F(TYPE, N, f, GET_TEXT_F(LABEL), ##V)
  415. #define MENU_ITEM_f_F(TYPE, f, FLABEL, V...) _MENU_ITEM_f_F(TYPE, f, false, FLABEL, ##V)
  416. #define MENU_ITEM_f(TYPE, f, LABEL, V...) MENU_ITEM_f_F(TYPE, f, GET_TEXT_F(LABEL), ##V)
  417. #define ACTION_ITEM_N_f_F(N, f, FLABEL, ACTION) MENU_ITEM_N_f_F(function, N, f, FLABEL, ACTION)
  418. #define ACTION_ITEM_N_f(N, f, LABEL, ACTION) ACTION_ITEM_N_f_F(N, f, GET_TEXT_F(LABEL), ACTION)
  419. #define ACTION_ITEM_f_F(f, FLABEL, ACTION) MENU_ITEM_f_F(function, f, FLABEL, ACTION)
  420. #define ACTION_ITEM_f(f, LABEL, ACTION) ACTION_ITEM_f_F(f, GET_TEXT_F(LABEL), ACTION)
  421. #define GCODES_ITEM_N_f_F(N, f, FLABEL, GCODES) MENU_ITEM_N_f_F(gcode, N, f, FLABEL, GCODES)
  422. #define GCODES_ITEM_N_f(N, f, LABEL, GCODES) GCODES_ITEM_N_f_F(N, f, GET_TEXT_F(LABEL), GCODES)
  423. #define GCODES_ITEM_f_F(f, FLABEL, GCODES) MENU_ITEM_f_F(gcode, f, FLABEL, GCODES)
  424. #define GCODES_ITEM_f(f, LABEL, GCODES) GCODES_ITEM_f_F(f, GET_TEXT_F(LABEL), GCODES)
  425. #define SUBMENU_N_f_F(N, f, FLABEL, DEST) MENU_ITEM_N_f_F(submenu, N, f, FLABEL, DEST)
  426. #define SUBMENU_N_f(N, f, LABEL, DEST) SUBMENU_N_f_F(N, f, GET_TEXT_F(LABEL), DEST)
  427. #define SUBMENU_f_F(f, FLABEL, DEST) MENU_ITEM_f_F(submenu, f, FLABEL, DEST)
  428. #define SUBMENU_f(f, LABEL, DEST) SUBMENU_f_F(f, GET_TEXT_F(LABEL), DEST)
  429. #define EDIT_ITEM_N_f_F(TYPE, N, f, FLABEL, V...) MENU_ITEM_N_f_F(TYPE, N, f, FLABEL, ##V)
  430. #define EDIT_ITEM_N_f(TYPE, N, f, LABEL, V...) EDIT_ITEM_N_f_F(TYPE, N, f, GET_TEXT_F(LABEL), ##V)
  431. #define EDIT_ITEM_f_F(TYPE, f, FLABEL, V...) MENU_ITEM_f_F(TYPE, f, FLABEL, ##V)
  432. #define EDIT_ITEM_f(TYPE, f, LABEL, V...) EDIT_ITEM_f_F(TYPE, f, GET_TEXT_F(LABEL), ##V)
  433. #define EDIT_ITEM_FAST_N_f_F(TYPE, N, f, FLABEL, V...) _MENU_ITEM_N_f_F(TYPE, N, f, true, FLABEL, ##V)
  434. #define EDIT_ITEM_FAST_N_f(TYPE, N, f, LABEL, V...) EDIT_ITEM_FAST_N_f_F(TYPE, N, f, true, GET_TEXT_F(LABEL), ##V)
  435. #define EDIT_ITEM_FAST_f_F(TYPE, f, FLABEL, V...) _MENU_ITEM_f_F(TYPE, f, true, FLABEL, ##V)
  436. #define EDIT_ITEM_FAST_f(TYPE, f, LABEL, V...) EDIT_ITEM_FAST_f_F(TYPE, f, GET_TEXT_F(LABEL), ##V)
  437. #define _CONFIRM_ITEM_INNER_F(FLABEL, V...) do { \
  438. if (encoderLine == _thisItemNr && ui.use_click()) { \
  439. ui.push_current_screen(); \
  440. ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
  441. return; \
  442. } \
  443. if (ui.should_draw()) MenuItem_confirm::draw \
  444. (encoderLine == _thisItemNr, _lcdLineNr, FLABEL, ##V); \
  445. }while(0)
  446. // Indexed items set a global index value and optional data
  447. #define _CONFIRM_ITEM_F(FLABEL, V...) do { \
  448. if (_menuLineNr == _thisItemNr) { \
  449. _skipStatic = false; \
  450. _CONFIRM_ITEM_INNER_F(FLABEL, ##V); \
  451. } \
  452. NEXT_ITEM(); \
  453. }while(0)
  454. // Indexed items set a global index value
  455. #define _CONFIRM_ITEM_N_S_F(N, S, V...) do{ \
  456. if (_menuLineNr == _thisItemNr) { \
  457. _skipStatic = false; \
  458. MenuItemBase::init(N, S); \
  459. _CONFIRM_ITEM_INNER_F(TYPE, ##V); \
  460. } \
  461. NEXT_ITEM(); \
  462. }while(0)
  463. // Indexed items set a global index value
  464. #define _CONFIRM_ITEM_N_F(N, V...) _CONFIRM_ITEM_N_S_F(N, nullptr, V)
  465. #define CONFIRM_ITEM_F(FLABEL,A,B,V...) _CONFIRM_ITEM_F(FLABEL, GET_TEXT_F(A), GET_TEXT_F(B), ##V)
  466. #define CONFIRM_ITEM(LABEL, V...) CONFIRM_ITEM_F(GET_TEXT_F(LABEL), ##V)
  467. #define YESNO_ITEM_F(FLABEL, V...) CONFIRM_ITEM_F(FLABEL, MSG_YES, MSG_NO, ##V)
  468. #define YESNO_ITEM(LABEL, V...) YESNO_ITEM_F(GET_TEXT_F(LABEL), ##V)
  469. #define CONFIRM_ITEM_N_S_F(N,S,FLABEL,A,B,V...) _CONFIRM_ITEM_N_S_F(N, S, FLABEL, GET_TEXT_F(A), GET_TEXT_F(B), ##V)
  470. #define CONFIRM_ITEM_N_S(N,S,LABEL,V...) CONFIRM_ITEM_N_S_F(N, S, GET_TEXT_F(LABEL), ##V)
  471. #define CONFIRM_ITEM_N_F(N,FLABEL,A,B,V...) _CONFIRM_ITEM_N_F(N, FLABEL, GET_TEXT_F(A), GET_TEXT_F(B), ##V)
  472. #define CONFIRM_ITEM_N(N,LABEL, V...) CONFIRM_ITEM_N_F(N, GET_TEXT_F(LABEL), ##V)
  473. #define YESNO_ITEM_N_S_F(N,S,FLABEL, V...) _CONFIRM_ITEM_N_S_F(N, S, FLABEL, MSG_YES, MSG_NO, ##V)
  474. #define YESNO_ITEM_N_S(N,S,LABEL, V...) YESNO_ITEM_N_S_F(N, S, GET_TEXT_F(LABEL), ##V)
  475. #define YESNO_ITEM_N_F(N,FLABEL, V...) CONFIRM_ITEM_N_F(N, FLABEL, MSG_YES, MSG_NO, ##V)
  476. #define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_F(N, GET_TEXT_F(LABEL), ##V)
  477. #if ENABLED(LCD_BED_TRAMMING)
  478. void _lcd_level_bed_corners();
  479. #endif
  480. #if HAS_FAN
  481. #include "../../module/temperature.h"
  482. inline void on_fan_update() {
  483. thermalManager.set_fan_speed(MenuItemBase::itemIndex, editable.uint8);
  484. TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_BIT_SYNC_FANS));
  485. }
  486. #if ENABLED(EXTRA_FAN_SPEED)
  487. #define EDIT_EXTRA_FAN_SPEED(V...) EDIT_ITEM_FAST_N(V)
  488. #else
  489. #define EDIT_EXTRA_FAN_SPEED(...)
  490. #endif
  491. #define _FAN_EDIT_ITEMS(F,L) do{ \
  492. editable.uint8 = thermalManager.fan_speed[F]; \
  493. EDIT_ITEM_FAST_N(percent, F, MSG_##L, &editable.uint8, 0, 255, on_fan_update); \
  494. EDIT_EXTRA_FAN_SPEED(percent, F, MSG_EXTRA_##L, &thermalManager.extra_fan_speed[F].speed, 3, 255); \
  495. }while(0)
  496. #if FAN_COUNT > 1
  497. #define FAN_EDIT_ITEMS(F) _FAN_EDIT_ITEMS(F,FAN_SPEED_N)
  498. #endif
  499. #define SNFAN(N) (ENABLED(SINGLENOZZLE_STANDBY_FAN) && !HAS_FAN##N && EXTRUDERS > N)
  500. #if SNFAN(1) || SNFAN(2) || SNFAN(3) || SNFAN(4) || SNFAN(5) || SNFAN(6) || SNFAN(7)
  501. #define DEFINE_SINGLENOZZLE_ITEM() \
  502. auto singlenozzle_item = [&](const uint8_t f) { \
  503. editable.uint8 = thermalManager.singlenozzle_fan_speed[f]; \
  504. EDIT_ITEM_FAST_N(percent, f, MSG_STORED_FAN_N, &editable.uint8, 0, 255, on_fan_update); \
  505. }
  506. #else
  507. #define DEFINE_SINGLENOZZLE_ITEM() NOOP
  508. #endif
  509. #endif // HAS_FAN