1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Merge pull request #10011 from mikeller/add_configurable_stats_flight_time

Added configurable minimum arming time for a flight to be counted in flight statistics.
This commit is contained in:
Michael Keller 2020-07-22 02:11:59 +12:00 committed by GitHub
commit 4e922f9ea4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View file

@ -1626,7 +1626,7 @@ const clivalue_t valueTable[] = {
#endif
#ifdef USE_PERSISTENT_STATS
{ "stats", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_enabled) },
{ "stats_min_armed_time_s", VAR_INT8 | MASTER_VALUE, .config.minmax = { STATS_OFF, INT8_MAX }, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_min_armed_time_s) },
{ "stats_total_flights", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_flights) },
{ "stats_total_time_s", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_time_s) },

View file

@ -35,7 +35,6 @@
#include "pg/stats.h"
#define MIN_FLIGHT_TIME_TO_RECORD_STATS_S 10 // Prevent recording stats for that short "flights" [s]
#define STATS_SAVE_DELAY_US 500000 // Let disarming complete and save stats after this time
static timeMs_t arm_millis;
@ -85,12 +84,13 @@ void statsOnArm(void)
void statsOnDisarm(void)
{
if (statsConfig()->stats_enabled) {
uint32_t dt = (millis() - arm_millis) / 1000;
if (dt >= MIN_FLIGHT_TIME_TO_RECORD_STATS_S) {
statsConfigMutable()->stats_total_flights += 1; //arm/flight counter
statsConfigMutable()->stats_total_time_s += dt; //[s]
statsConfigMutable()->stats_total_dist_m += (DISTANCE_FLOWN_CM - arm_distance_cm) / 100; //[m]
int8_t minArmedTimeS = statsConfig()->stats_min_armed_time_s;
if (minArmedTimeS >= 0) {
uint32_t dtS = (millis() - arm_millis) / 1000;
if (dtS >= (uint8_t)minArmedTimeS) {
statsConfigMutable()->stats_total_flights += 1; // arm / flight counter
statsConfigMutable()->stats_total_time_s += dtS;
statsConfigMutable()->stats_total_dist_m += (DISTANCE_FLOWN_CM - arm_distance_cm) / 100;
saveRequired = true;
}

View file

@ -27,13 +27,12 @@
#include "stats.h"
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 1);
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 2);
PG_RESET_TEMPLATE(statsConfig_t, statsConfig,
.stats_enabled = 0,
.stats_min_armed_time_s = STATS_OFF,
.stats_total_flights = 0,
.stats_total_time_s = 0,
.stats_total_dist_m = 0,
);
#endif

View file

@ -23,11 +23,13 @@
#include "pg/pg.h"
#include "drivers/io_types.h"
#define STATS_OFF (-1)
typedef struct statsConfig_s {
uint32_t stats_total_flights;
uint32_t stats_total_time_s; // [s]
uint32_t stats_total_dist_m; // [m]
uint8_t stats_enabled;
uint32_t stats_total_time_s;
uint32_t stats_total_dist_m;
int8_t stats_min_armed_time_s;
} statsConfig_t;
PG_DECLARE(statsConfig_t, statsConfig);