menu.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //menu.h
  2. #ifndef _MENU_H
  3. #define _MENU_H
  4. #include <inttypes.h>
  5. #include "eeprom.h"
  6. #define MENU_DATA_SIZE 32
  7. //Function pointer to menu functions.
  8. typedef void (*menu_func_t)(void);
  9. typedef struct
  10. {
  11. menu_func_t menu;
  12. int8_t position;
  13. } menu_record_t;
  14. typedef struct
  15. {
  16. //Variables used when editing values.
  17. const char* editLabel;
  18. void* editValue;
  19. int32_t minEditValue;
  20. int32_t maxEditValue;
  21. } menu_data_edit_t;
  22. extern uint8_t menu_data[MENU_DATA_SIZE];
  23. extern uint8_t menu_depth;
  24. //! definition of reasons blocking the main menu
  25. //! Use them as bit mask, so that the code may set various errors at the same time
  26. enum ESeriousErrors {
  27. MENU_BLOCK_NONE = 0,
  28. MENU_BLOCK_THERMAL_ERROR = 0x01,
  29. #ifdef TEMP_MODEL
  30. MENU_BLOCK_TEMP_MODEL_AUTOTUNE = 0x02,
  31. #endif
  32. }; // and possibly others in the future.
  33. //! this is a flag for disabling entering the main menu and longpress. If this is set to anything !=
  34. //! 0, the only the main status screen will be shown on the LCD and the user will be prevented from
  35. //! entering the menu.
  36. extern uint8_t menu_block_mask;
  37. //! a pair of macros for manipulating menu entry
  38. //! a c++ class would have been better
  39. #define menu_set_block(x) menu_block_mask |= x;
  40. #define menu_unset_block(x) menu_block_mask &= ~x;
  41. #define menu_is_blocked(x) (menu_block_mask & x) != 0
  42. extern uint8_t menu_line;
  43. extern uint8_t menu_item;
  44. extern uint8_t menu_row;
  45. //scroll offset in the current menu
  46. extern uint8_t menu_top;
  47. extern uint8_t menu_clicked;
  48. extern uint8_t menu_leaving;
  49. //function pointer to the currently active menu
  50. extern menu_func_t menu_menu;
  51. extern void menu_data_reset(void);
  52. extern void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state);
  53. #define MENU_BEGIN() menu_start(); for(menu_row = 0; menu_row < LCD_HEIGHT; menu_row++, menu_line++) { menu_item = 0;
  54. void menu_start(void);
  55. #define MENU_END() menu_end(); }
  56. extern void menu_end(void);
  57. extern void menu_back(void);
  58. extern void menu_back_no_reset(void);
  59. extern void menu_back(uint8_t nLevel);
  60. extern void menu_back_if_clicked(void);
  61. extern void menu_back_if_clicked_fb(void);
  62. extern void menu_submenu(menu_func_t submenu);
  63. extern void menu_submenu_no_reset(menu_func_t submenu);
  64. extern uint8_t menu_item_ret(void);
  65. //extern int menu_draw_item_printf_P(char type_char, const char* format, ...);
  66. //int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, );
  67. #define MENU_ITEM_DUMMY() menu_item_dummy()
  68. extern void menu_item_dummy(void);
  69. #define MENU_ITEM_TEXT_P(str) do { if (menu_item_text_P(str)) return; } while (0)
  70. extern uint8_t menu_item_text_P(const char* str);
  71. #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0)
  72. extern uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu);
  73. #define MENU_ITEM_SUBMENU_E(sheet, submenu) do { if (menu_item_submenu_E(sheet, submenu)) return; } while (0)
  74. extern uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu);
  75. #define MENU_ITEM_FUNCTION_E(sheet, submenu) do { if (menu_item_function_E(sheet, submenu)) return; } while (0)
  76. extern uint8_t menu_item_function_E(const Sheet &sheet, menu_func_t func);
  77. #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0)
  78. extern uint8_t menu_item_back_P(const char* str);
  79. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  80. #define ON_MENU_LEAVE(func) do { if (menu_item_leave()){ func } } while (0)
  81. extern bool menu_item_leave();
  82. /// Entering a new menu
  83. /// @param func lines of code to run once upon enter a menu or submenu
  84. #define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
  85. extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
  86. #define MENU_ITEM_FUNCTION_NR_P(str, number, func, fn_par) do { if (menu_item_function_P(str, number, func, fn_par)) return; } while (0)
  87. extern uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t), uint8_t fn_par);
  88. #define MENU_ITEM_TOGGLE_P(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, 0x02)) return; } while (0)
  89. #define MENU_ITEM_TOGGLE(str, toggle, func) do { if (menu_item_toggle_P(str, toggle, func, 0x00)) return; } while (0)
  90. extern uint8_t menu_item_toggle_P(const char* str, const char* toggle, menu_func_t func, const uint8_t settings);
  91. #define MENU_ITEM_GCODE_P(str, str_gcode) do { if (menu_item_gcode_P(str, str_gcode)) return; } while (0)
  92. extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode);
  93. extern const char menu_fmt_int3[];
  94. extern const char menu_fmt_float31[];
  95. extern const char menu_fmt_float13[];
  96. extern void menu_draw_float31(const char* str, float val);
  97. extern void menu_draw_float13(const char* str, float val);
  98. struct SheetFormatBuffer
  99. {
  100. char c[19];
  101. };
  102. extern void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer);
  103. #define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_P(str, pval, minval, maxval)) return; } while (0)
  104. //#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval)
  105. template <typename T>
  106. extern uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val);
  107. extern void menu_progressbar_init(uint16_t total, const char* title);
  108. extern void menu_progressbar_update(uint16_t newVal);
  109. extern void menu_progressbar_finish(void);
  110. #endif //_MENU_H