menu.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. extern uint8_t menu_line;
  24. extern uint8_t menu_item;
  25. extern uint8_t menu_row;
  26. //scroll offset in the current menu
  27. extern uint8_t menu_top;
  28. extern uint8_t menu_clicked;
  29. extern uint8_t menu_entering;
  30. extern uint8_t menu_leaving;
  31. //function pointer to the currently active menu
  32. extern menu_func_t menu_menu;
  33. extern void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bool reset_menu_state);
  34. #define MENU_BEGIN() menu_start(); for(menu_row = 0; menu_row < LCD_HEIGHT; menu_row++, menu_line++) { menu_item = 0;
  35. void menu_start(void);
  36. #define MENU_END() menu_end(); }
  37. extern void menu_end(void);
  38. extern void menu_back(void);
  39. extern void menu_back_no_reset(void);
  40. extern void menu_back_if_clicked(void);
  41. extern void menu_back_if_clicked_fb(void);
  42. extern void menu_submenu(menu_func_t submenu);
  43. extern void menu_submenu_no_reset(menu_func_t submenu);
  44. extern uint8_t menu_item_ret(void);
  45. //extern int menu_draw_item_printf_P(char type_char, const char* format, ...);
  46. extern int menu_draw_item_puts_P(char type_char, const char* str);
  47. //int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, );
  48. #define MENU_ITEM_DUMMY() menu_item_dummy()
  49. extern void menu_item_dummy(void);
  50. #define MENU_ITEM_TEXT_P(str) do { if (menu_item_text_P(str)) return; } while (0)
  51. extern uint8_t menu_item_text_P(const char* str);
  52. #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0)
  53. extern uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu);
  54. #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0)
  55. extern uint8_t menu_item_back_P(const char* str);
  56. #define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
  57. extern uint8_t menu_item_function_P(const char* str, menu_func_t func);
  58. #define MENU_ITEM_GCODE_P(str, str_gcode) do { if (menu_item_gcode_P(str, str_gcode)) return; } while (0)
  59. extern uint8_t menu_item_gcode_P(const char* str, const char* str_gcode);
  60. extern const char menu_fmt_int3[];
  61. extern const char menu_fmt_float31[];
  62. extern void menu_draw_int3(char chr, const char* str, int16_t val);
  63. extern void menu_draw_float31(char chr, const char* str, float val);
  64. extern void menu_draw_float13(char chr, const char* str, float val);
  65. extern void _menu_edit_int3(void);
  66. #define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_int3(str, pval, minval, maxval)) return; } while (0)
  67. //#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval)
  68. extern uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int16_t max_val);
  69. #endif //_MENU_H