menu.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #define MENU_TYPE_SETTING_BOOL 0
  3. #define MENU_TYPE_SETTING_U8 1
  4. #define MENU_TYPE_DISPLAY 2
  5. #define MENU_TYPE_FUNCTION 3
  6. #define IS_SETTING(x) (x<3)
  7. #define MENU_DISPLAY_TYPE_DEFAULT 0 // specific for setting type if IS_SETTING(), MENU_DISPLAY_STRING otherwise
  8. #define MENU_DISPLAY_TYPE_STRING 1
  9. #define MENU_DISPLAY_TYPE_FUNCTION 2
  10. #define MENU_DISPLAY_TYPE_NAME_FUNCTION 3
  11. #define MENU_DISPLAY_TYPE_NAME_CSFUNCTION 4
  12. #define MENU_DISPLAY_TYPE_U8_METERS 5
  13. #define MENU_DISPLAY_TYPE_U8_SECONDS 6
  14. #define menu_push(x) { if(__menu_num<DATA_NUM) __menu_data[__menu_num++] = x; } // stack commands
  15. #define menu_pop() --__menu_num
  16. #define menu_get() &__menu_data[__menu_num-1]
  17. #define no_menu() (__menu_num == 0)
  18. #define DATA_NUM 3 // maximum menu depth
  19. #define HAVE_NEXT_SETTING_POSITION 0
  20. #define HAVE_PREV_SETTING_POSITION 0
  21. struct menu_pos {
  22. unsigned char type;
  23. unsigned char display_type;
  24. __flash const char *name; // used for line 1 when MENU_DISPLAY_TYPE_STRING or MENU_DISPLAY_TYPE_NAME_(CS)FUNCTION
  25. union {
  26. __flash const char *value; // used for line 2 when MENU_DISPLAY_TYPE_STRING
  27. void (* display)(void); // used for line 2 when MENU_DISPLAY_TYPE_NAME_FUNCTION; used for both lines when MENU_DISPLAY_TYPE_FUNCTION
  28. __flash const char * (* csdisplay)(void); // used for line 2 when MENU_DISPLAY_TYPE_NAME_CSFUNCTION
  29. };
  30. unsigned char index; // index when IS_SETTING()
  31. void (* changed)(void); // what to call on changed value when IS_SETTING()
  32. unsigned char (* func)(void); // what to call on MENU_DISPLAY_TYPE_NAME_FUNCTION; returns true if display refresh is needed
  33. unsigned char allow_back; // left arrow will return to level up
  34. };
  35. struct menu_struct {
  36. __flash const struct menu_pos *list; // list of elements
  37. unsigned char num; // count of elements
  38. signed int ind:6; // current index/position
  39. };
  40. extern unsigned char __menu_num;
  41. extern struct menu_struct __menu_data[DATA_NUM];
  42. extern void (*func_enter_table[])(struct menu_pos *); // to be defined in the application
  43. unsigned char menu(void);