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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 "../marlinui.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. typedef void (*selectFunc_t)();
  30. #define SS_LEFT 0x00
  31. #define SS_CENTER 0x01
  32. #define SS_INVERT 0x02
  33. #define SS_DEFAULT SS_CENTER
  34. #if ENABLED(BABYSTEP_ZPROBE_OFFSET) && Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
  35. #define BABYSTEP_TO_STR(N) ftostr43sign(N)
  36. #elif ENABLED(BABYSTEPPING)
  37. #define BABYSTEP_TO_STR(N) ftostr53sign(N)
  38. #endif
  39. ////////////////////////////////////////////
  40. ///////////// Base Menu Items //////////////
  41. ////////////////////////////////////////////
  42. class MenuItemBase {
  43. public:
  44. // Index to interject in the item label and/or for use by its action.
  45. static int8_t itemIndex;
  46. // Optional pointers for use in display or by the action
  47. static FSTR_P itemStringF;
  48. static const char* itemStringC;
  49. // Store an index and string for later substitution
  50. FORCE_INLINE static void init(const int8_t ind=0, FSTR_P const fstr=nullptr) { itemIndex = ind; itemStringF = fstr; itemStringC = nullptr; }
  51. FORCE_INLINE static void init(const int8_t ind, const char * const cstr) { itemIndex = ind; itemStringC = cstr; itemStringF = nullptr; }
  52. // Implementation-specific:
  53. // Draw an item either selected (pre_char) or not (space) with post_char
  54. // Menus may set up itemIndex, itemStringC/F and pass them to string-building or string-emitting functions
  55. static void _draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char pre_char, const char post_char);
  56. // Draw an item either selected ('>') or not (space) with post_char
  57. FORCE_INLINE static void _draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char post_char) {
  58. _draw(sel, row, fstr, '>', post_char);
  59. }
  60. };
  61. // STATIC_ITEM(LABEL,...)
  62. class MenuItem_static : public MenuItemBase {
  63. public:
  64. static void draw(const uint8_t row, FSTR_P const fstr, const uint8_t style=SS_DEFAULT, const char * const vstr=nullptr);
  65. };
  66. // BACK_ITEM(LABEL)
  67. class MenuItem_back : public MenuItemBase {
  68. public:
  69. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const fstr) {
  70. _draw(sel, row, fstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]);
  71. }
  72. // Back Item action goes back one step in history
  73. FORCE_INLINE static void action(FSTR_P const=nullptr) { ui.go_back(); }
  74. };
  75. // CONFIRM_ITEM(LABEL,Y,N,FY,FN,...),
  76. // YESNO_ITEM(LABEL,FY,FN,...)
  77. class MenuItem_confirm : public MenuItemBase {
  78. public:
  79. FORCE_INLINE static void draw(const bool sel, const uint8_t row, FSTR_P const ftpl, ...) {
  80. _draw(sel, row, ftpl, '>', LCD_STR_ARROW_RIGHT[0]);
  81. }
  82. // Implemented for HD44780 and DOGM
  83. // Draw the prompt, buttons, and state
  84. static void draw_select_screen(
  85. FSTR_P const yes, // Right option label
  86. FSTR_P const no, // Left option label
  87. const bool yesno, // Is "yes" selected?
  88. FSTR_P const pref, // Prompt prefix
  89. const char * const string, // Prompt runtime string
  90. FSTR_P const suff // Prompt suffix
  91. );
  92. static void select_screen(
  93. FSTR_P const yes, FSTR_P const no,
  94. selectFunc_t yesFunc, selectFunc_t noFunc,
  95. FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr
  96. );
  97. static void select_screen(
  98. FSTR_P const yes, FSTR_P const no,
  99. selectFunc_t yesFunc, selectFunc_t noFunc,
  100. FSTR_P const pref, FSTR_P const string, FSTR_P const suff=nullptr
  101. ) {
  102. char str[strlen_P(FTOP(string)) + 1];
  103. strcpy_P(str, FTOP(string));
  104. select_screen(yes, no, yesFunc, noFunc, pref, str, suff);
  105. }
  106. // Shortcut for prompt with "NO"/ "YES" labels
  107. FORCE_INLINE static void confirm_screen(selectFunc_t yesFunc, selectFunc_t noFunc, FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr) {
  108. select_screen(GET_TEXT_F(MSG_YES), GET_TEXT_F(MSG_NO), yesFunc, noFunc, pref, string, suff);
  109. }
  110. };
  111. ////////////////////////////////////////////
  112. ///////////// Edit Menu Items //////////////
  113. ////////////////////////////////////////////
  114. // The Menu Edit shadow value
  115. typedef union {
  116. bool state;
  117. float decimal;
  118. int8_t int8;
  119. int16_t int16;
  120. int32_t int32;
  121. uint8_t uint8;
  122. uint16_t uint16;
  123. uint32_t uint32;
  124. celsius_t celsius;
  125. } chimera_t;
  126. extern chimera_t editable;
  127. // Base class for Menu Edit Items
  128. class MenuEditItemBase : public MenuItemBase {
  129. private:
  130. // These values are statically constructed by init() via action()
  131. // The action() method acts like the instantiator. The entire lifespan
  132. // of a menu item is within its declaration, so all these values decompose
  133. // into behavior and unused items get optimized out.
  134. static FSTR_P editLabel;
  135. static void *editValue;
  136. static int32_t minEditValue, maxEditValue; // Encoder value range
  137. static screenFunc_t callbackFunc;
  138. static bool liveEdit;
  139. protected:
  140. typedef const char* (*strfunc_t)(const int32_t);
  141. typedef void (*loadfunc_t)(void *, const int32_t);
  142. static void goto_edit_screen(
  143. FSTR_P const el, // Edit label
  144. void * const ev, // Edit value pointer
  145. const int32_t minv, // Encoder minimum
  146. const int32_t maxv, // Encoder maximum
  147. const uint16_t ep, // Initial encoder value
  148. const screenFunc_t cs, // MenuItem_type::draw_edit_screen => MenuEditItemBase::edit()
  149. const screenFunc_t cb, // Callback after edit
  150. const bool le // Flag to call cb() during editing
  151. );
  152. static void edit_screen(strfunc_t, loadfunc_t); // Edit value handler
  153. public:
  154. // Implementation-specific:
  155. // Draw the current item at specified row with edit data
  156. static void draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm=false);
  157. static void draw(const bool sel, const uint8_t row, FSTR_P const ftpl, FSTR_P const fstr) {
  158. draw(sel, row, ftpl, FTOP(fstr), true);
  159. }
  160. // Implementation-specific:
  161. // This low-level method is good to draw from anywhere
  162. static void draw_edit_screen(FSTR_P const fstr, const char * const value);
  163. // This method is for the current menu item
  164. static void draw_edit_screen(const char * const value) { draw_edit_screen(editLabel, value); }
  165. };
  166. #if ENABLED(SDSUPPORT)
  167. class CardReader;
  168. class MenuItem_sdbase {
  169. public:
  170. // Implemented for HD44780 and DOGM
  171. static void draw(const bool sel, const uint8_t row, FSTR_P const fstr, CardReader &theCard, const bool isDir);
  172. };
  173. #endif
  174. ////////////////////////////////////////////
  175. /////////////// Menu Screens ///////////////
  176. ////////////////////////////////////////////
  177. void menu_main();
  178. void menu_move();
  179. #if ENABLED(SDSUPPORT)
  180. void menu_media();
  181. #endif
  182. ////////////////////////////////////////////
  183. //////// Menu Item Helper Functions ////////
  184. ////////////////////////////////////////////
  185. void lcd_move_z();
  186. void _lcd_draw_homing();
  187. #define HAS_LINE_TO_Z ANY(DELTA, PROBE_MANUALLY, MESH_BED_LEVELING, LCD_BED_TRAMMING)
  188. #if HAS_LINE_TO_Z
  189. void line_to_z(const_float_t z);
  190. #endif
  191. #if ENABLED(PROBE_OFFSET_WIZARD)
  192. void goto_probe_offset_wizard();
  193. #endif
  194. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  195. void xatc_wizard_continue();
  196. void menu_advanced_settings();
  197. #endif
  198. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  199. void _lcd_toggle_bed_leveling();
  200. #endif
  201. #if ENABLED(BABYSTEPPING)
  202. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  203. void lcd_babystep_zoffset();
  204. #else
  205. void lcd_babystep_z();
  206. #endif
  207. #if ENABLED(BABYSTEP_MILLIMETER_UNITS)
  208. #define BABYSTEP_SIZE_X int32_t((BABYSTEP_MULTIPLICATOR_XY) * planner.settings.axis_steps_per_mm[X_AXIS])
  209. #define BABYSTEP_SIZE_Y int32_t((BABYSTEP_MULTIPLICATOR_XY) * planner.settings.axis_steps_per_mm[Y_AXIS])
  210. #define BABYSTEP_SIZE_Z int32_t((BABYSTEP_MULTIPLICATOR_Z) * planner.settings.axis_steps_per_mm[Z_AXIS])
  211. #else
  212. #define BABYSTEP_SIZE_X BABYSTEP_MULTIPLICATOR_XY
  213. #define BABYSTEP_SIZE_Y BABYSTEP_MULTIPLICATOR_XY
  214. #define BABYSTEP_SIZE_Z BABYSTEP_MULTIPLICATOR_Z
  215. #endif
  216. #endif
  217. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  218. void touch_screen_calibration();
  219. #endif
  220. extern uint8_t screen_history_depth;
  221. inline void clear_menu_history() { screen_history_depth = 0; }
  222. #define STICKY_SCREEN(S) []{ ui.defer_status_screen(); ui.goto_screen(S); }
  223. #if HAS_LEVELING && ANY(LCD_BED_TRAMMING, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
  224. extern bool leveling_was_active;
  225. #endif
  226. #if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
  227. extern uint8_t manual_probe_index;
  228. #endif