1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +03:00

Reschedule stats saving on disarm, if quad still moving (#13637)

* Rescedule stats saving on disarm, if quad still moving

* Review suggestions by KarateBrot and Ledvinap

* Moved statsSaveMoveLimit under statsConfig_t
This commit is contained in:
Ivan Efimov 2024-08-19 23:44:40 -05:00 committed by GitHub
parent 6dcc268918
commit 295d5425ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 14 deletions

View file

@ -1786,7 +1786,7 @@ const clivalue_t valueTable[] = {
{ "stats_total_time_s", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_time_s) },
{ "stats_total_dist_m", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_total_dist_m) },
{ "stats_save_move_limit", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, UINT8_MAX }, PG_STATS_CONFIG, offsetof(statsConfig_t, statsSaveMoveLimit) },
#ifdef USE_BATTERY_CONTINUE
{ "stats_mah_used", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_mah_used) },
#endif

View file

@ -18,16 +18,18 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>
#include "platform.h"
#ifdef USE_PERSISTENT_STATS
#include "config/config.h"
#include "drivers/time.h"
#include "config/config.h"
#include "fc/dispatch.h"
#include "fc/runtime_config.h"
#include "fc/stats.h"
#include "io/beeper.h"
#include "io/gps.h"
@ -38,6 +40,10 @@
#include "sensors/battery.h"
#endif
#include "sensors/gyro.h"
#include "stats.h"
#define STATS_SAVE_DELAY_US 500000 // Let disarming complete and save stats after this time
static timeMs_t arm_millis;
@ -45,6 +51,9 @@ static uint32_t arm_distance_cm;
static bool saveRequired = false;
static void writeStats(dispatchEntry_t *self);
dispatchEntry_t writeStatsEntry = { writeStats, 0, NULL, false };
#ifdef USE_GPS
#define DISTANCE_FLOWN_CM (GPS_distanceFlownInCm)
#else
@ -56,29 +65,31 @@ void statsInit(void)
dispatchEnable();
}
void writeStats(struct dispatchEntry_s* self)
static void writeStats(dispatchEntry_t *self)
{
UNUSED(self);
if (!ARMING_FLAG(ARMED)) {
// Don't save if the user made config changes that have not yet been saved.
if (!isConfigDirty()) {
writeEEPROM();
const bool gyroIsStill = fabsf(gyro.gyroADCf[FD_ROLL]) < statsConfig()->statsSaveMoveLimit &&
fabsf(gyro.gyroADCf[FD_PITCH]) < statsConfig()->statsSaveMoveLimit &&
fabsf(gyro.gyroADCf[FD_YAW]) < statsConfig()->statsSaveMoveLimit;
if (gyroIsStill || statsConfig()->statsSaveMoveLimit == 0) {
writeEEPROM();
// Repeat disarming beep indicating the stats save is complete
beeper(BEEPER_DISARMING);
} else {
dispatchAdd(&writeStatsEntry, STATS_SAVE_DELAY_US);
}
}
saveRequired = false;
}
}
dispatchEntry_t writeStatsEntry =
{
writeStats, 0, NULL, false
};
void statsOnArm(void)
{
arm_millis = millis();

View file

@ -27,7 +27,7 @@
#include "stats.h"
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 3);
PG_REGISTER_WITH_RESET_TEMPLATE(statsConfig_t, statsConfig, PG_STATS_CONFIG, 4);
PG_RESET_TEMPLATE(statsConfig_t, statsConfig,
.stats_min_armed_time_s = STATS_OFF,
@ -35,5 +35,6 @@ PG_RESET_TEMPLATE(statsConfig_t, statsConfig,
.stats_total_time_s = 0,
.stats_total_dist_m = 0,
.stats_mah_used = 0,
.statsSaveMoveLimit = 20,
);
#endif

View file

@ -31,6 +31,7 @@ typedef struct statsConfig_s {
uint32_t stats_total_dist_m;
int8_t stats_min_armed_time_s;
uint32_t stats_mah_used;
uint8_t statsSaveMoveLimit; // gyro rate limit for saving stats upon disarm
} statsConfig_t;
PG_DECLARE(statsConfig_t, statsConfig);