working_modes.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "main.h"
  2. #include "working_modes.h"
  3. #include "display.h"
  4. #include "xprintf.h"
  5. #include "settings.h"
  6. #include "nmea.h"
  7. #include "gpx.h"
  8. #include "menu.h"
  9. void tracking_pause(unsigned char cmd, unsigned char display) {
  10. switch (cmd) {
  11. case TRACKING_PAUSE_CMD_TOGGLE:
  12. System.tracking_paused = !System.tracking_paused;
  13. break;
  14. case TRACKING_PAUSE_CMD_RESUME:
  15. System.tracking_paused = 0;
  16. break;
  17. case TRACKING_PAUSE_CMD_PAUSE:
  18. System.tracking_paused = 1;
  19. break;
  20. }
  21. if (System.tracking_paused) {
  22. LEDB_ON();
  23. if (display)
  24. display_event(DISPLAY_EVENT_TRACKING_PAUSED);
  25. } else {
  26. LEDB_OFF();
  27. if (display)
  28. display_event(DISPLAY_EVENT_TRACKING_RESUMED);
  29. }
  30. }
  31. unsigned char tracking_pause_cmd(void) {
  32. tracking_pause(TRACKING_PAUSE_CMD_TOGGLE, 1);
  33. return 0;
  34. }
  35. __flash const char *pause_tracking_get_name(void) {
  36. if (System.tracking_paused)
  37. return PSTR("> Wznow rejestr.");
  38. else
  39. return PSTR("> Wstrzymaj rej.");
  40. }
  41. unsigned char save_point(void) {
  42. if (System.location_valid) {
  43. gpx_save_single_point(&location);
  44. display_event(DISPLAY_EVENT_POINT_SAVED);
  45. } else {
  46. display_event(DISPLAY_EVENT_POINT_NOT_SAVED);
  47. }
  48. return 0;
  49. }
  50. unsigned char new_file(void) {
  51. System.open_new_file = 1;
  52. return 0;
  53. }
  54. __flash const char _menu_header[] = " *** MENU *** ";
  55. __flash const char _settings[] = "> Ustawienia";
  56. __flash const char _new_file[] = "> Nowy plik";
  57. __flash const char _save_point[] = "> Zapisz punkt";
  58. __flash const struct menu_pos main_menu_list[] = {
  59. {
  60. .type = MENU_TYPE_FUNCTION,
  61. .display_type = MENU_DISPLAY_TYPE_STRING,
  62. .name = _menu_header,
  63. .value = _save_point,
  64. .func = save_point,
  65. .allow_back = 1,
  66. },
  67. {
  68. .type = MENU_TYPE_FUNCTION,
  69. .display_type = MENU_DISPLAY_TYPE_STRING,
  70. .name = _menu_header,
  71. .value = _settings,
  72. .func = enter_settings,
  73. .allow_back = 1,
  74. },
  75. {
  76. .type = MENU_TYPE_FUNCTION,
  77. .display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
  78. .name = _menu_header,
  79. .csdisplay = pause_tracking_get_name,
  80. .func = tracking_pause_cmd,
  81. .allow_back = 1,
  82. },
  83. {
  84. .type = MENU_TYPE_FUNCTION,
  85. .display_type = MENU_DISPLAY_TYPE_STRING,
  86. .name = _menu_header,
  87. .value = _new_file,
  88. .func = new_file,
  89. .allow_back = 1,
  90. },
  91. };
  92. __flash const struct menu_struct main_menu = {
  93. .list = main_menu_list,
  94. .num = sizeof(main_menu_list) / sizeof(main_menu_list[0]),
  95. };
  96. __flash const struct menu_pos default_menu_list[] = {
  97. {
  98. .type = MENU_TYPE_FUNCTION,
  99. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  100. .display = disp_func_main_default,
  101. .func = enter_main_menu,
  102. },
  103. {
  104. .type = MENU_TYPE_FUNCTION,
  105. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  106. .display = disp_func_coord,
  107. .func = enter_main_menu,
  108. },
  109. {
  110. .type = MENU_TYPE_FUNCTION,
  111. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  112. .display = disp_func_ele_sat,
  113. .func = enter_main_menu,
  114. },
  115. {
  116. .type = MENU_TYPE_FUNCTION,
  117. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  118. .display = disp_distance_and_time,
  119. .func = enter_main_menu,
  120. },
  121. {
  122. .type = MENU_TYPE_FUNCTION,
  123. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  124. .display = disp_speed,
  125. .func = enter_main_menu,
  126. },
  127. {
  128. .type = MENU_TYPE_FUNCTION,
  129. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  130. .display = disp_pause_time,
  131. .func = enter_main_menu,
  132. },
  133. {
  134. .type = MENU_TYPE_FUNCTION,
  135. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  136. .display = disp_time,
  137. .func = enter_main_menu,
  138. },
  139. {
  140. .type = MENU_TYPE_FUNCTION,
  141. .display_type = MENU_DISPLAY_TYPE_FUNCTION,
  142. .display = disp_func_temperature,
  143. .func = enter_main_menu,
  144. },
  145. };
  146. __flash const struct menu_struct default_menu = {
  147. .list = default_menu_list,
  148. .num = sizeof(default_menu_list) / sizeof(default_menu_list[0]),
  149. };
  150. unsigned char enter_settings(void) {
  151. menu_push(settings_menu);
  152. return 1;
  153. }
  154. unsigned char enter_main_menu(void) {
  155. menu_push(main_menu);
  156. return 1;
  157. }