My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

menu.h 9.3KB

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