Skip to content

Commit

Permalink
Add filltered voltage warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
boris.zalman authored and bkleiner committed May 24, 2024
1 parent 7dfec48 commit 106f12b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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********************************************************

Expand Down
1 change: 1 addition & 0 deletions src/core/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,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,
Expand Down
2 changes: 2 additions & 0 deletions src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions src/io/vbat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 106f12b

Please sign in to comment.