1
0

working_modes.c 1.4 KB

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