My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

menu_item.h 28KB

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