working_modes.c 3.6 KB

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