working_modes.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "main.h"
  2. #include "working_modes.h"
  3. #include "display.h"
  4. #include "HD44780-I2C.h"
  5. #include "xprintf.h"
  6. __flash const unsigned char main_display_modes[] = {
  7. DISPLAY_STATE_MAIN_DEFAULT,
  8. DISPLAY_STATE_COORD,
  9. DISPLAY_STATE_ELE_SAT,
  10. };
  11. void change_display_mode(signed char dir) {
  12. static signed char display_mode_index;
  13. display_mode_index += dir;
  14. if (display_mode_index < 0)
  15. display_mode_index = sizeof(main_display_modes) - 1;
  16. if (display_mode_index >= (signed char)sizeof(main_display_modes))
  17. display_mode_index = 0;
  18. display_state(main_display_modes[display_mode_index]);
  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. }
  29. return MODE_NO_CHANGE;
  30. }
  31. unsigned char (*__flash const working_modes[])(unsigned char) = {
  32. working_mode_default,
  33. };
  34. void key_process(void) {
  35. // static unsigned char mode_changed;
  36. unsigned char k = getkey();
  37. unsigned char newmode = working_modes[System.working_mode](k);
  38. if (newmode != MODE_NO_CHANGE && newmode != System.working_mode) {
  39. LCD_Clear();
  40. System.working_mode = newmode;
  41. }
  42. }