menu.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_push(x) { if(__menu_num<DATA_NUM) __menu_data[__menu_num++] = x; } // stack commands
  13. #define menu_pop() --__menu_num
  14. #define menu_get() &__menu_data[__menu_num-1]
  15. #define no_menu() (__menu_num == 0)
  16. #define DATA_NUM 3 // maximum menu depth
  17. #define HAVE_NEXT_SETTING_POSITION 0
  18. #define HAVE_PREV_SETTING_POSITION 0
  19. struct menu_pos {
  20. unsigned char type;
  21. unsigned char display_type;
  22. __flash const char *name; // used for line 1 when MENU_DISPLAY_TYPE_STRING or MENU_DISPLAY_TYPE_NAME_(CS)FUNCTION
  23. union {
  24. __flash const char *value; // used for line 2 when MENU_DISPLAY_TYPE_STRING
  25. void (* display)(void); // used for line 2 when MENU_DISPLAY_TYPE_NAME_FUNCTION; used for both lines when MENU_DISPLAY_TYPE_FUNCTION
  26. __flash const char * (* csdisplay)(void); // used for line 2 when MENU_DISPLAY_TYPE_NAME_CSFUNCTION
  27. };
  28. unsigned char index; // index when IS_SETTING()
  29. void (* changed)(void); // what to call on changed value when IS_SETTING()
  30. void (* func)(void); // what to call on MENU_DISPLAY_TYPE_NAME_FUNCTION
  31. unsigned char allow_back; // left arrow will return to level up
  32. };
  33. struct menu_struct {
  34. __flash const struct menu_pos *list; // list of elements
  35. unsigned char num; // count of elements
  36. signed int ind:6; // current index/position
  37. };
  38. extern unsigned char __menu_num;
  39. extern struct menu_struct __menu_data[DATA_NUM];
  40. extern void (*func_enter_table[])(struct menu_pos *); // to be defined in the application
  41. unsigned char menu(void);