Skip to content

Commit e0bd68d

Browse files
Add min distance check to flight counter in stats; update settings.md
1 parent d93a128 commit e0bd68d

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

docs/Settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5792,6 +5792,16 @@ General switch of the statistics recording feature (a.k.a. odometer)
57925792

57935793
---
57945794

5795+
### stats_flight_count
5796+
5797+
Total number of flights. The value is updated on every disarm when "stats" are enabled.
5798+
5799+
| Default | Min | Max |
5800+
| --- | --- | --- |
5801+
| 0 | | 65535 |
5802+
5803+
---
5804+
57955805
### stats_total_dist
57965806

57975807
Total flight distance [in meters]. The value is updated on every disarm when "stats" are enabled.

src/main/fc/stats.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#include "fc/settings.h"
77
#include "fc/stats.h"
8+
#include "fc/runtime_config.h"
89

910
#include "sensors/battery.h"
11+
#include "sensors/sensors.h"
1012

1113
#include "drivers/time.h"
1214
#include "navigation/navigation.h"
@@ -16,6 +18,7 @@
1618
#include "config/parameter_group_ids.h"
1719

1820
#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]
1922

2023

2124
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 2);
@@ -62,9 +65,17 @@ void statsOnDisarm(void)
6265
if (statsConfig()->stats_enabled) {
6366
uint32_t dt = (millis() - arm_millis) / 1000;
6467
if (dt >= MIN_FLIGHT_TIME_TO_RECORD_STATS_S) {
65-
statsConfigMutable()->stats_flight_count = prev_flight_count + 1; // only increment once per power on
6668
statsConfigMutable()->stats_total_time += dt; //[s]
6769
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
6879
#ifdef USE_ADC
6980
if (feature(FEATURE_VBAT) && isAmperageConfigured()) {
7081
const uint32_t energy = getMWhDrawn() - arm_mWhDrawn;

0 commit comments

Comments
 (0)