working_modes.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #include "main.h"
  2. void tracking_pause(unsigned char cmd, unsigned char display) {
  3. unsigned char was_paused = System.tracking_paused;
  4. unsigned char was_auto_paused = System.tracking_auto_paused;
  5. switch (cmd) {
  6. case TRACKING_PAUSE_CMD_TOGGLE:
  7. System.tracking_paused = !System.tracking_paused;
  8. break;
  9. case TRACKING_PAUSE_CMD_RESUME:
  10. System.tracking_paused = 0;
  11. break;
  12. case TRACKING_PAUSE_CMD_PAUSE:
  13. System.tracking_paused = 1;
  14. break;
  15. }
  16. if (System.tracking_paused) {
  17. if (!was_paused && !was_auto_paused)
  18. pause_time_start();
  19. LEDB_ON();
  20. if (display)
  21. display_event(DISPLAY_EVENT_TRACKING_PAUSED);
  22. } else {
  23. /* A manual resume must actually resume, even if auto-pause is also
  24. * active: auto_pause_process() only clears tracking_auto_paused
  25. * while tracking_paused is *true*, so left alone here it would
  26. * survive this transition and tracking_is_paused() would still
  27. * report paused. */
  28. if (was_auto_paused)
  29. auto_pause_clear_manual_resume();
  30. if (was_paused && (was_auto_paused || !System.tracking_auto_paused))
  31. pause_time_end();
  32. LEDB_OFF();
  33. if (display)
  34. display_event(DISPLAY_EVENT_TRACKING_RESUMED);
  35. }
  36. }
  37. unsigned char tracking_pause_cmd(void) {
  38. tracking_pause(TRACKING_PAUSE_CMD_TOGGLE, 1);
  39. return 0;
  40. }
  41. __flash const char *pause_tracking_get_name(void) {
  42. if (System.tracking_paused)
  43. return PSTR("> Wznow rejestr.");
  44. else
  45. return PSTR("> Wstrzymaj rej.");
  46. }
  47. unsigned char save_point(void) {
  48. if (System.location_valid) {
  49. gpx_save_single_point(&location);
  50. display_event(DISPLAY_EVENT_POINT_SAVED);
  51. } else {
  52. display_event(DISPLAY_EVENT_POINT_NOT_SAVED);
  53. }
  54. return 0;
  55. }
  56. unsigned char new_file(void) {
  57. System.open_new_file = 1;
  58. return 0;
  59. }
  60. __flash const char _menu_header[] = " *** MENU *** ";
  61. __flash const char _settings[] = "> Ustawienia";
  62. __flash const char _new_file[] = "> Nowy plik";
  63. __flash const char _save_point[] = "> Zapisz punkt";
  64. __flash const struct menu_pos main_menu_list[] = {
  65. {
  66. .type = MENU_TYPE_FUNCTION,
  67. .display_type = MENU_DISPLAY_TYPE_STRING,
  68. .name = _menu_header,
  69. .value = _save_point,
  70. .func = save_point,
  71. .allow_back = 1,
  72. },
  73. {
  74. .type = MENU_TYPE_FUNCTION,
  75. .display_type = MENU_DISPLAY_TYPE_STRING,
  76. .name = _menu_header,
  77. .value = _settings,
  78. .func = enter_settings,
  79. .allow_back = 1,
  80. },
  81. {
  82. .type = MENU_TYPE_FUNCTION,
  83. .display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
  84. .name = _menu_header,
  85. .csdisplay = pause_tracking_get_name,
  86. .func = tracking_pause_cmd,
  87. .allow_back = 1,
  88. },
  89. {
  90. .type = MENU_TYPE_FUNCTION,
  91. .display_type = MENU_DISPLAY_TYPE_STRING,
  92. .name = _menu_header,
  93. .value = _new_file,
  94. .func = new_file,
  95. .allow_back = 1,
  96. },
  97. };
  98. __flash const struct menu_struct main_menu = {
  99. .list = main_menu_list,
  100. .num = sizeof(main_menu_list) / sizeof(main_menu_list[0]),
  101. };
  102. __flash const struct menu_pos default_menu_list[] = {
  103. {
  104. .type = MENU_TYPE_FUNCTION,
  105. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  106. .display = disp_func_main_default,
  107. .func = enter_main_menu,
  108. },
  109. {
  110. .type = MENU_TYPE_FUNCTION,
  111. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  112. .display = disp_func_coord,
  113. .func = enter_main_menu,
  114. },
  115. {
  116. .type = MENU_TYPE_FUNCTION,
  117. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  118. .display = disp_func_ele_sat,
  119. .func = enter_main_menu,
  120. },
  121. {
  122. .type = MENU_TYPE_FUNCTION,
  123. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  124. .display = disp_func_elevation_gain,
  125. .func = enter_main_menu,
  126. },
  127. {
  128. .type = MENU_TYPE_FUNCTION,
  129. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  130. .display = disp_distance_and_time,
  131. .func = enter_main_menu,
  132. },
  133. {
  134. .type = MENU_TYPE_FUNCTION,
  135. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  136. .display = disp_speed,
  137. .func = enter_main_menu,
  138. },
  139. {
  140. .type = MENU_TYPE_FUNCTION,
  141. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  142. .display = disp_pause_time,
  143. .func = enter_main_menu,
  144. },
  145. {
  146. .type = MENU_TYPE_FUNCTION,
  147. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  148. .display = disp_time,
  149. .func = enter_main_menu,
  150. },
  151. {
  152. .type = MENU_TYPE_FUNCTION,
  153. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  154. .display = disp_func_temperature,
  155. .func = enter_main_menu,
  156. },
  157. {
  158. .type = MENU_TYPE_FUNCTION_WITH_KEY,
  159. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  160. .display = disp_func_global_error,
  161. .func_key = error_browser_func,
  162. },
  163. };
  164. __flash const struct menu_struct default_menu = {
  165. .list = default_menu_list,
  166. .num = sizeof(default_menu_list) / sizeof(default_menu_list[0]),
  167. };
  168. unsigned char enter_settings(void) {
  169. menu_push(settings_menu);
  170. return 1;
  171. }
  172. unsigned char enter_main_menu(void) {
  173. menu_push(main_menu);
  174. return 1;
  175. }
  176. void check_error_and_jump(void) {
  177. static unsigned int prev_error = ERROR_NO;
  178. struct menu_struct *curr;
  179. /* Only act if we're in the default menu and error changed */
  180. if (__menu_num != 1)
  181. return;
  182. curr = menu_get();
  183. if (curr->list != default_menu_list)
  184. return;
  185. /* Check if a new error occurred */
  186. if (System.global_error != ERROR_NO && prev_error == ERROR_NO) {
  187. /* Jump to last menu item (error display) */
  188. curr->ind = curr->num - 1;
  189. display_refresh(1);
  190. }
  191. prev_error = System.global_error;
  192. }