|
5 | 5 |
|
6 | 6 | #include "fc/settings.h" |
7 | 7 | #include "fc/stats.h" |
| 8 | +#include "fc/runtime_config.h" |
8 | 9 |
|
9 | 10 | #include "sensors/battery.h" |
| 11 | +#include "sensors/sensors.h" |
10 | 12 |
|
11 | 13 | #include "drivers/time.h" |
12 | 14 | #include "navigation/navigation.h" |
|
16 | 18 | #include "config/parameter_group_ids.h" |
17 | 19 |
|
18 | 20 | #define MIN_FLIGHT_TIME_TO_RECORD_STATS_S 10 //prevent recording stats for that short "flights" [s] |
| 21 | +#define MIN_FLIGHT_DISTANCE_M 10 // minimum distance flown for a flight to be registered [m] |
19 | 22 |
|
20 | 23 |
|
21 | 24 | PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 2); |
@@ -62,9 +65,17 @@ void statsOnDisarm(void) |
62 | 65 | if (statsConfig()->stats_enabled) { |
63 | 66 | uint32_t dt = (millis() - arm_millis) / 1000; |
64 | 67 | if (dt >= MIN_FLIGHT_TIME_TO_RECORD_STATS_S) { |
65 | | - statsConfigMutable()->stats_flight_count = prev_flight_count + 1; // only increment once per power on |
66 | 68 | statsConfigMutable()->stats_total_time += dt; //[s] |
67 | 69 | statsConfigMutable()->stats_total_dist += (getTotalTravelDistance() - arm_distance_cm) / 100; //[m] |
| 70 | +#ifdef USE_GPS |
| 71 | + // flight counter is incremented at most once per power on |
| 72 | + if (sensors(SENSOR_GPS)) { |
| 73 | + if ((getTotalTravelDistance() - arm_distance_cm) / 100 >= MIN_FLIGHT_DISTANCE_M) |
| 74 | + statsConfigMutable()->stats_flight_count = prev_flight_count + 1; |
| 75 | + } else statsConfigMutable()->stats_flight_count = prev_flight_count + 1; |
| 76 | +#else |
| 77 | + statsConfigMutable()->stats_flight_count = prev_flight_count + 1; |
| 78 | +#endif // USE_GPS |
68 | 79 | #ifdef USE_ADC |
69 | 80 | if (feature(FEATURE_VBAT) && isAmperageConfigured()) { |
70 | 81 | const uint32_t energy = getMWhDrawn() - arm_mWhDrawn; |
|
0 commit comments