menu.h 2.0 KB

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