From 813113d6424abb4e0db3e08d4ca0df9212e910d9 Mon Sep 17 00:00:00 2001 From: "boris.zalman" Date: Fri, 24 May 2024 11:25:26 +0200 Subject: [PATCH 1/2] Add filltered voltage warnings --- src/config/config.h | 3 +++ src/core/profile.c | 1 + src/core/profile.h | 2 ++ src/io/vbat.c | 13 +++++++++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index b06c20f9d..023a94cf5 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -148,6 +148,9 @@ #define ACTUAL_BATTERY_VOLTAGE 4.20 #define REPORTED_TELEMETRY_VOLTAGE 4.20 +// *************Use filtered voltage instead of fuel gauge voltage for low battery warnings +#define USE_FILTERED_VOLTAGE_FOR_WARNINGS 0 + //********************************************************************************************************************** //***********************************************FILTER SETTINGS******************************************************** diff --git a/src/core/profile.c b/src/core/profile.c index 77d865f5e..5c59961c8 100644 --- a/src/core/profile.c +++ b/src/core/profile.c @@ -383,6 +383,7 @@ const profile_t default_profile = { .vbattlow = VBATTLOW, .actual_battery_voltage = ACTUAL_BATTERY_VOLTAGE, .reported_telemetry_voltage = REPORTED_TELEMETRY_VOLTAGE, + .use_filtered_voltage_for_warnings = USE_FILTERED_VOLTAGE_FOR_WARNINGS, .vbat_scale = 110, #ifdef IBAT_SCALE .ibat_scale = IBAT_SCALE, diff --git a/src/core/profile.h b/src/core/profile.h index 75d943894..ee07610e2 100644 --- a/src/core/profile.h +++ b/src/core/profile.h @@ -224,6 +224,7 @@ typedef struct { float vbattlow; float actual_battery_voltage; float reported_telemetry_voltage; + uint8_t use_filtered_voltage_for_warnings; float vbat_scale; float ibat_scale; } profile_voltage_t; @@ -235,6 +236,7 @@ typedef struct { MEMBER(vbattlow, float) \ MEMBER(actual_battery_voltage, float) \ MEMBER(reported_telemetry_voltage, float) \ + MEMBER(use_filtered_voltage_for_warnings, uint8_t) \ MEMBER(vbat_scale, float) \ MEMBER(ibat_scale, float) \ END_STRUCT() diff --git a/src/io/vbat.c b/src/io/vbat.c index ff77737d0..249dcbbcd 100644 --- a/src/io/vbat.c +++ b/src/io/vbat.c @@ -115,8 +115,13 @@ void vbat_calc() { state.vbat_compensated = tempvolt + vdrop_factor * thrfilt; state.vbat_compensated_cell_avg = state.vbat_compensated / (float)state.lipo_cell_count; - if ((state.vbat_compensated_cell_avg < profile.voltage.vbattlow + hyst) || (state.vbat_cell_avg < VBATTLOW_ABS)) - flags.lowbatt = 1; - else - flags.lowbatt = 0; + + if (profile.voltage.use_filtered_voltage_for_warnings) { + flags.lowbatt = state.vbat_cell_avg < profile.voltage.vbattlow ? 1 : 0; + } else { + if ((state.vbat_compensated_cell_avg < profile.voltage.vbattlow + hyst) || (state.vbat_cell_avg < VBATTLOW_ABS)) + flags.lowbatt = 1; + else + flags.lowbatt = 0; + } } From 5b45362eebf74c0c38611a83784a4fa7fd283afb Mon Sep 17 00:00:00 2001 From: "boris.zalman" Date: Fri, 24 May 2024 15:31:02 +0200 Subject: [PATCH 2/2] Bump profile version --- src/core/profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/profile.h b/src/core/profile.h index ee07610e2..71ff5a86f 100644 --- a/src/core/profile.h +++ b/src/core/profile.h @@ -9,7 +9,7 @@ #define OSD_NUMBER_ELEMENTS 32 -#define PROFILE_VERSION MAKE_SEMVER(0, 2, 2) +#define PROFILE_VERSION MAKE_SEMVER(0, 2, 3) // Rates typedef enum {