working_modes.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. };
  14. void change_display_mode(signed char dir) {
  15. display_mode_index += dir;
  16. if (display_mode_index < 0)
  17. display_mode_index = sizeof(main_display_modes) - 1;
  18. if (display_mode_index >= (signed char)sizeof(main_display_modes))
  19. display_mode_index = 0;
  20. }
  21. unsigned char working_mode_default(unsigned char k) {
  22. switch (k) {
  23. case K_UP:
  24. change_display_mode(-1);
  25. break;
  26. case K_DOWN:
  27. change_display_mode(1);
  28. break;
  29. case K_RIGHT:
  30. return MODE_MAIN_MENU;
  31. }
  32. display_state(main_display_modes[display_mode_index]);
  33. return MODE_NO_CHANGE;
  34. }
  35. unsigned char working_mode_main_menu(unsigned char k) {
  36. switch (k) {
  37. case K_LEFT:
  38. return MODE_DEFAULT;
  39. }
  40. display_state(DISPLAY_STATE_MAIN_MENU);
  41. return MODE_NO_CHANGE;
  42. }
  43. unsigned char (*__flash const working_modes[])(unsigned char) = {
  44. working_mode_default,
  45. working_mode_main_menu,
  46. };
  47. void key_process(void) {
  48. // static unsigned char mode_changed;
  49. unsigned char k = getkey();
  50. unsigned char newmode = working_modes[System.working_mode](k);
  51. if (newmode != MODE_NO_CHANGE && newmode != System.working_mode) {
  52. LCD_Clear();
  53. System.working_mode = newmode;
  54. }
  55. }