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
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down 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;
}
}