1
0

working_modes.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "main.h"
  2. #include "working_modes.h"
  3. #include "display.h"
  4. #include "HD44780-I2C.h"
  5. #include "xprintf.h"
  6. static signed char display_mode_index;
  7. __flash const unsigned char main_display_modes[] = {
  8. DISPLAY_STATE_MAIN_DEFAULT,
  9. DISPLAY_STATE_COORD,
  10. DISPLAY_STATE_ELE_SAT,
  11. DISPLAY_STATE_VOLTAGE,
  12. DISPLAY_STATE_TEMPERATURE,
  13. DISPLAY_STATE_GPX_POINTS_WRITTEN,
  14. };
  15. void change_display_mode(signed char dir) {
  16. display_mode_index += dir;
  17. if (display_mode_index < 0)
  18. display_mode_index = sizeof(main_display_modes) - 1;
  19. if (display_mode_index >= (signed char)sizeof(main_display_modes))
  20. display_mode_index = 0;
  21. }
  22. unsigned char working_mode_default(unsigned char k) {
  23. switch (k) {
  24. case K_UP:
  25. change_display_mode(-1);
  26. break;
  27. case K_DOWN:
  28. change_display_mode(1);
  29. break;
  30. case K_RIGHT:
  31. return MODE_MAIN_MENU;
  32. }
  33. display_state(main_display_modes[display_mode_index]);
  34. return MODE_NO_CHANGE;
  35. }
  36. unsigned char working_mode_main_menu(unsigned char k) {
  37. switch (k) {
  38. case K_LEFT:
  39. return MODE_DEFAULT;
  40. }
  41. display_state(DISPLAY_STATE_MAIN_MENU);
  42. return MODE_NO_CHANGE;
  43. }
  44. unsigned char (*__flash const working_modes[])(unsigned char) = {
  45. working_mode_default,
  46. working_mode_main_menu,
  47. };
  48. void key_process(void) {
  49. // static unsigned char mode_changed;
  50. unsigned char k = getkey();
  51. unsigned char newmode = working_modes[System.working_mode](k);
  52. if (newmode != MODE_NO_CHANGE && newmode != System.working_mode) {
  53. LCD_Clear();
  54. System.working_mode = newmode;
  55. }
  56. }