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

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