working_modes.c 4.6 KB

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