1
0

working_modes.c 1.4 KB

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