working_modes.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "main.h"
  2. #include "working_modes.h"
  3. #include "display.h"
  4. #include "HD44780-I2C.h"
  5. #include "xprintf.h"
  6. #include "settings.h"
  7. #include "nmea.h"
  8. static signed char display_mode_index;
  9. __flash const unsigned char main_display_modes[] = {
  10. DISPLAY_STATE_MAIN_DEFAULT,
  11. DISPLAY_STATE_COORD,
  12. DISPLAY_STATE_ELE_SAT,
  13. };
  14. const char *enter_settings_get_name(void) {
  15. return PSTR("> Ustawienia");
  16. }
  17. unsigned char tracking_pause(void) {
  18. System.tracking_paused = !System.tracking_paused;
  19. if (System.tracking_paused)
  20. LEDB_ON();
  21. else
  22. LEDB_OFF();
  23. return MODE_NO_CHANGE;
  24. }
  25. #define STATE_PAUSE_TRACKING_NOTPAUSED 0
  26. #define STATE_PAUSE_TRACKING_JUSTPAUSED 1
  27. #define STATE_PAUSE_TRACKING_PAUSED 2
  28. #define STATE_PAUSE_TRACKING_JUSTUNPAUSED 3
  29. const char *pause_tracking_get_name(void) {
  30. static unsigned char state = STATE_PAUSE_TRACKING_NOTPAUSED;
  31. switch (state) {
  32. default:
  33. case STATE_PAUSE_TRACKING_NOTPAUSED:
  34. if (System.tracking_paused) {
  35. set_timer(info_display, 2000);
  36. state = STATE_PAUSE_TRACKING_JUSTPAUSED;
  37. }
  38. return PSTR("> Wstrzymaj rej.");
  39. case STATE_PAUSE_TRACKING_JUSTPAUSED:
  40. if (timer_expired(info_display))
  41. state = STATE_PAUSE_TRACKING_PAUSED;
  42. if (!System.tracking_paused) {
  43. set_timer(info_display, 2000);
  44. state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
  45. }
  46. return PSTR("Wstrzymano!");
  47. case STATE_PAUSE_TRACKING_PAUSED:
  48. if (!System.tracking_paused) {
  49. set_timer(info_display, 2000);
  50. state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
  51. }
  52. return PSTR("> Wznow rejestr.");
  53. case STATE_PAUSE_TRACKING_JUSTUNPAUSED:
  54. if (System.tracking_paused) {
  55. set_timer(info_display, 2000);
  56. state = STATE_PAUSE_TRACKING_JUSTPAUSED;
  57. }
  58. if (timer_expired(info_display))
  59. state = STATE_PAUSE_TRACKING_NOTPAUSED;
  60. return PSTR("Wznowiono!");
  61. }
  62. }
  63. __flash const struct main_menu_pos_s main_menu[MAIN_MENU_MAXPOS+1] = {
  64. {
  65. .func = enter_settings,
  66. .get_name = enter_settings_get_name,
  67. },
  68. {
  69. .func = tracking_pause,
  70. .get_name = pause_tracking_get_name,
  71. },
  72. };
  73. struct menu_params_s mp;
  74. void change_display_mode(signed char dir) {
  75. display_mode_index += dir;
  76. if (display_mode_index < 0)
  77. display_mode_index = sizeof(main_display_modes) - 1;
  78. if (display_mode_index >= (signed char)sizeof(main_display_modes))
  79. display_mode_index = 0;
  80. }
  81. unsigned char working_mode_default(unsigned char k) {
  82. switch (k) {
  83. case K_UP:
  84. change_display_mode(-1);
  85. break;
  86. case K_DOWN:
  87. change_display_mode(1);
  88. break;
  89. case K_RIGHT:
  90. return MODE_MAIN_MENU;
  91. }
  92. display_state(main_display_modes[display_mode_index]);
  93. return MODE_NO_CHANGE;
  94. }
  95. unsigned char working_mode_main_menu(unsigned char k) {
  96. switch (k) {
  97. case K_LEFT:
  98. return MODE_DEFAULT;
  99. case K_RIGHT:
  100. if (main_menu[mp.main_menu_pos].func)
  101. return main_menu[mp.main_menu_pos].func();
  102. break;
  103. case K_DOWN:
  104. if (mp.main_menu_pos < MAIN_MENU_MAXPOS)
  105. mp.main_menu_pos++;
  106. break;
  107. case K_UP:
  108. if (mp.main_menu_pos > 0)
  109. mp.main_menu_pos--;
  110. break;
  111. }
  112. display_state(DISPLAY_STATE_MAIN_MENU);
  113. return MODE_NO_CHANGE;
  114. }
  115. unsigned char working_mode_settings_menu(unsigned char k) {
  116. switch (k) {
  117. case K_LEFT:
  118. if (settings_menu[mp.settings_menu_pos].type == SETTINGS_TYPE_BACK)
  119. return MODE_MAIN_MENU;
  120. /* fall through */
  121. case K_RIGHT:
  122. switch (settings_menu[mp.settings_menu_pos].type) {
  123. case SETTINGS_TYPE_BOOL: settings_display_and_modify_bool(mp.settings_menu_pos, k); break;
  124. case SETTINGS_TYPE_U8: settings_display_and_modify_u8(mp.settings_menu_pos, k); break;
  125. }
  126. break;
  127. case K_DOWN:
  128. if (mp.settings_menu_pos < SETTINGS_MENU_MAXPOS)
  129. mp.settings_menu_pos++;
  130. break;
  131. case K_UP:
  132. if (mp.settings_menu_pos > 0)
  133. mp.settings_menu_pos--;
  134. break;
  135. }
  136. return MODE_NO_CHANGE;
  137. }
  138. void display_main_menu_item(void) {
  139. strcpy_P(disp.line1, PSTR(" *** MENU *** "));
  140. strcpy_P(disp.line2, main_menu[mp.main_menu_pos].get_name());
  141. }
  142. void display_settings_menu_item(void) {
  143. switch (settings_menu[mp.settings_menu_pos].type) {
  144. case SETTINGS_TYPE_BOOL:
  145. settings_display_and_modify_bool(mp.settings_menu_pos, 0);
  146. break;
  147. case SETTINGS_TYPE_U8:
  148. settings_display_and_modify_u8(mp.settings_menu_pos, 0);
  149. break;
  150. case SETTINGS_TYPE_BACK:
  151. strcpy_P(disp.line1, PSTR("* Ustawienia *"));
  152. strcpy_P(disp.line2, settings_menu[mp.settings_menu_pos].name);
  153. if (HAVE_NEXT_SETTING_POSITION)
  154. strcat_P(disp.line2, PSTR(" \x01")); /* down arrow */
  155. if (HAVE_PREV_SETTING_POSITION)
  156. strcat_P(disp.line2, PSTR(" \x02")); /* up arrow */
  157. break;
  158. };
  159. }
  160. unsigned char (*__flash const working_modes[])(unsigned char) = {
  161. working_mode_default,
  162. working_mode_main_menu,
  163. working_mode_settings_menu,
  164. };
  165. void key_process(void) {
  166. unsigned char k = getkey();
  167. unsigned char newmode = working_modes[System.working_mode](k);
  168. if (newmode != MODE_NO_CHANGE && newmode != System.working_mode) {
  169. LCD_Clear();
  170. System.working_mode = newmode;
  171. }
  172. }
  173. unsigned char enter_settings(void) {
  174. display_state(DISPLAY_STATE_SETTINGS_MENU);
  175. return MODE_SETTINGS_MENU;
  176. }