working_modes.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include "gpx.h"
  9. #include "menu.h"
  10. struct menu_params_s mp;
  11. void tracking_pause(void) {
  12. System.tracking_paused = !System.tracking_paused;
  13. if (System.tracking_paused)
  14. LEDB_ON();
  15. else
  16. LEDB_OFF();
  17. }
  18. __flash const char *pause_tracking_get_name(void) {
  19. static unsigned char state = STATE_PAUSE_TRACKING_NOTPAUSED;
  20. switch (state) {
  21. default:
  22. case STATE_PAUSE_TRACKING_NOTPAUSED:
  23. if (System.tracking_paused) {
  24. set_timer(info_display, 2000);
  25. state = STATE_PAUSE_TRACKING_JUSTPAUSED;
  26. }
  27. return PSTR("> Wstrzymaj rej.");
  28. case STATE_PAUSE_TRACKING_JUSTPAUSED:
  29. if (timer_expired(info_display))
  30. state = STATE_PAUSE_TRACKING_PAUSED;
  31. if (!System.tracking_paused) {
  32. set_timer(info_display, 2000);
  33. state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
  34. }
  35. return PSTR("Wstrzymano!");
  36. case STATE_PAUSE_TRACKING_PAUSED:
  37. if (!System.tracking_paused) {
  38. set_timer(info_display, 2000);
  39. state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
  40. }
  41. return PSTR("> Wznow rejestr.");
  42. case STATE_PAUSE_TRACKING_JUSTUNPAUSED:
  43. if (System.tracking_paused) {
  44. set_timer(info_display, 2000);
  45. state = STATE_PAUSE_TRACKING_JUSTPAUSED;
  46. }
  47. if (timer_expired(info_display))
  48. state = STATE_PAUSE_TRACKING_NOTPAUSED;
  49. return PSTR("Wznowiono!");
  50. }
  51. }
  52. __flash const char *save_point_get_name(void) {
  53. switch (mp.point_save_state) {
  54. default:
  55. return PSTR("> Zapisz punkt");
  56. case STATE_POINT_SAVE_NOT_DONE:
  57. if (timer_expired(info_display))
  58. mp.point_save_state = STATE_POINT_SAVE_READY;
  59. return PSTR("Nie zapisano!");
  60. case STATE_POINT_SAVE_DONE:
  61. if (timer_expired(info_display))
  62. mp.point_save_state = STATE_POINT_SAVE_READY;
  63. return PSTR("Zapisano!");
  64. }
  65. }
  66. void save_point(void) {
  67. if (timer_expired(info_display)) { /* don't save too often */
  68. if (System.location_valid) {
  69. gpx_save_single_point(&location);
  70. mp.point_save_state = STATE_POINT_SAVE_DONE;
  71. } else {
  72. mp.point_save_state = STATE_POINT_SAVE_NOT_DONE;
  73. }
  74. }
  75. set_timer(info_display, 2000);
  76. }
  77. void new_file(void) {
  78. System.open_new_file = 1;
  79. }
  80. __flash const char _menu_header[] = " *** MENU *** ";
  81. __flash const char _settings[] = "> Ustawienia";
  82. __flash const char _new_file[] = "> Nowy plik";
  83. __flash const struct menu_pos main_menu_list[] = {
  84. {
  85. .type = MENU_TYPE_FUNCTION,
  86. .display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
  87. .name = _menu_header,
  88. .csdisplay = save_point_get_name,
  89. .func = save_point,
  90. .allow_back = 1,
  91. },
  92. {
  93. .type = MENU_TYPE_FUNCTION,
  94. .display_type = MENU_DISPLAY_TYPE_STRING,
  95. .name = _menu_header,
  96. .value = _settings,
  97. .func = enter_settings,
  98. .allow_back = 1,
  99. },
  100. {
  101. .type = MENU_TYPE_FUNCTION,
  102. .display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
  103. .name = _menu_header,
  104. .csdisplay = pause_tracking_get_name,
  105. .func = tracking_pause,
  106. .allow_back = 1,
  107. },
  108. {
  109. .type = MENU_TYPE_FUNCTION,
  110. .display_type = MENU_DISPLAY_TYPE_STRING,
  111. .name = _menu_header,
  112. .value = _new_file,
  113. .func = new_file,
  114. .allow_back = 1,
  115. },
  116. };
  117. __flash const struct menu_struct main_menu = {
  118. .list = main_menu_list,
  119. .num = sizeof(main_menu_list) / sizeof(main_menu_list[0]),
  120. };
  121. __flash const struct menu_pos default_menu_list[] = {
  122. {
  123. .type = MENU_TYPE_FUNCTION,
  124. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  125. .display = disp_func_main_default,
  126. .func = enter_main_menu,
  127. },
  128. {
  129. .type = MENU_TYPE_FUNCTION,
  130. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  131. .display = disp_func_coord,
  132. .func = enter_main_menu,
  133. },
  134. {
  135. .type = MENU_TYPE_FUNCTION,
  136. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  137. .display = disp_func_ele_sat,
  138. .func = enter_main_menu,
  139. },
  140. {
  141. .type = MENU_TYPE_FUNCTION,
  142. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  143. .display = disp_distance_and_time,
  144. .func = enter_main_menu,
  145. },
  146. {
  147. .type = MENU_TYPE_FUNCTION,
  148. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  149. .display = disp_speed,
  150. .func = enter_main_menu,
  151. },
  152. {
  153. .type = MENU_TYPE_FUNCTION,
  154. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  155. .display = disp_time,
  156. .func = enter_main_menu,
  157. },
  158. {
  159. .type = MENU_TYPE_FUNCTION,
  160. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  161. .display = disp_func_temperature,
  162. .func = enter_main_menu,
  163. },
  164. };
  165. __flash const struct menu_struct default_menu = {
  166. .list = default_menu_list,
  167. .num = sizeof(default_menu_list) / sizeof(default_menu_list[0]),
  168. };
  169. void enter_settings(void) {
  170. xprintf(PSTR("ENTER SETTINGS MENU, %d\r\n"), (int)__menu_num);
  171. menu_push(settings_menu);
  172. }
  173. void enter_main_menu(void) {
  174. xprintf(PSTR("ENTER MAIN MENU, %d\r\n"), (int)__menu_num);
  175. menu_push(main_menu);
  176. }