menu.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //menu.h
  2. #ifndef _MENU_H
  3. #define _MENU_H
  4. #include <inttypes.h>
  5. #define MENU_DATA_SIZE 32
  6. //Function pointer to menu functions.
  7. typedef void (*menu_func_t)(void);
  8. typedef struct
  9. {
  10. menu_func_t menu;
  11. int8_t position;
  12. } menu_record_t;
  13. typedef struct
  14. {
  15. //Variables used when editing values.
  16. const char* editLabel;
  17. void* editValue;
  18. int32_t minEditValue;
  19. int32_t maxEditValue;
  20. } menu_data_edit_t;
  21. extern uint8_t menu_data[MENU_DATA_SIZE];
  22. extern uint8_t menu_depth;
  23. //! definition of serious errors possibly blocking the main menu
  24. //! Use them as bit mask, so that the code may set various errors at the same time
  25. enum ESeriousErrors {
  26. SERIOUS_ERR_NONE = 0,
  27. SERIOUS_ERR_MINTEMP_HEATER = 0x01,
  28. SERIOUS_ERR_MINTEMP_BED = 0x02
  29. }; // and possibly others in the future.
  30. //! this is a flag for disabling entering the main menu. If this is set
  31. //! to anything != 0, the only the main status screen will be shown on the
  32. //! LCD and the user will be prevented from entering the menu.
  33. //! Now used only to block doing anything with the printer when there is
  34. //! the infamous MINTEMP error (SERIOUS_ERR_MINTEMP).
  35. extern uint8_t menu_block_entering_on_serious_errors;
  36. //! a pair of macros for manipulating the serious errors
  37. //! a c++ class would have been better
  38. #define menu_set_serious_error(x) menu_block_entering_on_serious_errors |= x;
  39. #define menu_unset_serious_error(x) menu_block_entering_on_serious_errors &= ~x;
  40. #define menu_is_serious_error(x) (menu_block_entering_on_serious_errors & x) != 0
  41. extern uint8_t menu_line;
  42. extern uint8_t menu_item;
  43. extern uint8_t menu_row;
  44. //scroll offset in the current menu
  45. extern uint8_t menu_top;
  46. extern uint8_t menu_clicked;
  47. extern uint8_t menu_entering;
  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_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state);
  52. #define MENU_BEGIN() menu_start(); for(menu_row = 0; menu_row < LCD_HEIGHT; menu_row++, menu_line++) { menu_item = 0;
  53. void menu_start(void);
  54. #define MENU_END() menu_end(); }
  55. extern void menu_end(void);
  56. extern void menu_back(void);
  57. extern void menu_back(uint8_t nLevel);
  58. extern void menu_back_if_clicked(void);
  59. extern void menu_back_if_clicked_fb(void);
  60. extern void menu_submenu(menu_func_t submenu);
  61. extern uint8_t menu_item_ret(void);
  62. //extern int menu_draw_item_printf_P(char type_char, const char* format, ...);
  63. //int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, );
  64. #define MENU_ITEM_DUMMY() menu_item_dummy()
  65. extern void menu_item_dummy(void);
  66. #define MENU_ITEM_TEXT_P(str) do { if (menu_item_text_P(str)) return; } while (0)
  67. extern uint8_t menu_item_text_P(const char* str);
  68. #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0)
  69. extern uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu);
  70. #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0)
  71. extern uint8_t menu_item_back_P(const char* str);
  72. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  73. #define ON_MENU_LEAVE(func) do { if (((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving){ func } } while (0)
  74. #define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
  75. extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
  76. #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)
  77. extern uint8_t menu_item_function_P(const char* str, char number, void (*func)(uint8_t), uint8_t fn_par);
  78. #define MENU_ITEM_GCODE_P(str, str_gcode) do { if (menu_item_gcode_P(str, str_gcode)) return; } while (0)
  79. extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode);
  80. extern const char menu_fmt_int3[];
  81. extern const char menu_fmt_float31[];
  82. extern const char menu_fmt_float13[];
  83. extern void menu_draw_float31(const char* str, float val);
  84. extern void menu_draw_float13(const char* str, float val);
  85. #define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_P(str, pval, minval, maxval)) return; } while (0)
  86. //#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval)
  87. template <typename T>
  88. extern uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_val);
  89. #endif //_MENU_H