Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filltered voltage warnings #116

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add filltered voltage warnings
boris.zalman committed May 24, 2024
commit 813113d6424abb4e0db3e08d4ca0df9212e910d9
3 changes: 3 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
@@ -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********************************************************

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