autopause.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Auto-pause detection: shared between the firmware and gps-test-tool (see
  3. * autopause_wrapper.c), since it directly gates what ends up in
  4. * System.distance/elevation_gain/elevation_loss (excluded while paused) and
  5. * is a major part of what those tools' output actually looks like.
  6. */
  7. #ifdef PC_BUILD
  8. #include "../gps-test-tool/main.h"
  9. #else
  10. #include "main.h"
  11. #endif
  12. struct auto_pause_s auto_pause;
  13. static void auto_unpause(void) {
  14. if (!System.tracking_auto_paused)
  15. return;
  16. System.tracking_auto_paused = 0;
  17. log_pause_event(0);
  18. beep(50, 4);
  19. }
  20. static void auto_pause_activate(void) {
  21. System.tracking_auto_paused = 1;
  22. log_pause_event(1);
  23. beep(50, 3);
  24. }
  25. void auto_pause_process(void) {
  26. if (System.tracking_paused || !get_flag(CONFFLAG_AUTO_PAUSE)) { /* remove auto-pause */
  27. System.tracking_auto_paused = 0;
  28. auto_pause.prev_distance = System.distance;
  29. auto_pause.point_counter = 0;
  30. auto_pause.speed_counter = 0;
  31. return;
  32. }
  33. if (System.speed >= System.conf.auto_pause_speed) { /* unpause when set speed is exceeded for 3 consecutive measurements */
  34. if (++auto_pause.speed_counter >= 3) {
  35. auto_pause.point_counter = 0;
  36. auto_pause.speed_counter = 0;
  37. auto_unpause();
  38. return;
  39. }
  40. } else {
  41. auto_pause.speed_counter = 0;
  42. }
  43. if (++auto_pause.point_counter < System.conf.auto_pause_time)
  44. return;
  45. auto_pause.point_counter = 0;
  46. if ((System.distance - auto_pause.prev_distance)/100 > System.conf.auto_pause_dist) {
  47. if (System.tracking_auto_paused)
  48. auto_unpause(); /* unpause when distance exceeded */
  49. } else {
  50. if (!System.tracking_auto_paused)
  51. auto_pause_activate(); /* pause otherwise */
  52. }
  53. auto_pause.prev_distance = System.distance;
  54. }