6 #include "fc/settings.h"
9 #include "sensors/battery.h"
11 #include "drivers/time.h"
12 #include "navigation/navigation.h"
14 #include "fc/config.h"
15 #include "config/parameter_group.h"
16 #include "config/parameter_group_ids.h"
18 #define MIN_FLIGHT_TIME_TO_RECORD_STATS_S 10 //prevent recording stats for that short "flights" [s]
21 PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t
, statsConfig
, PG_STATS_CONFIG
, 1);
23 PG_RESET_TEMPLATE(statsConfig_t
, statsConfig
,
24 .stats_enabled
= SETTING_STATS_DEFAULT
,
25 .stats_total_time
= SETTING_STATS_TOTAL_TIME_DEFAULT
,
26 .stats_total_dist
= SETTING_STATS_TOTAL_DIST_DEFAULT
,
28 .stats_total_energy
= SETTING_STATS_TOTAL_ENERGY_DEFAULT
32 static uint32_t arm_millis
;
33 static uint32_t arm_distance_cm
;
36 static uint32_t arm_mWhDrawn
;
37 static uint32_t flyingEnergy
; // energy drawn during flying up to last disarm (ARMED) mWh
39 uint32_t getFlyingEnergy() {
46 arm_millis
= millis();
47 arm_distance_cm
= getTotalTravelDistance();
49 arm_mWhDrawn
= getMWhDrawn();
53 void statsOnDisarm(void)
55 if (statsConfig()->stats_enabled
) {
56 uint32_t dt
= (millis() - arm_millis
) / 1000;
57 if (dt
>= MIN_FLIGHT_TIME_TO_RECORD_STATS_S
) {
58 statsConfigMutable()->stats_total_time
+= dt
; //[s]
59 statsConfigMutable()->stats_total_dist
+= (getTotalTravelDistance() - arm_distance_cm
) / 100; //[m]
61 if (feature(FEATURE_VBAT
) && isAmperageConfigured()) {
62 const uint32_t energy
= getMWhDrawn() - arm_mWhDrawn
;
63 statsConfigMutable()->stats_total_energy
+= energy
;
64 flyingEnergy
+= energy
;
67 saveConfigAndNotify();