Merge pull request #6648 from timman2er/set_number_of_cells_bat
add way to manually override battery cell count
This commit is contained in:
commit
8c47db882f
|
@ -682,6 +682,7 @@ const clivalue_t valueTable[] = {
|
||||||
{ "use_cbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useConsumptionAlerts) },
|
{ "use_cbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useConsumptionAlerts) },
|
||||||
{ "cbat_alert_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, consumptionWarningPercentage) },
|
{ "cbat_alert_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, consumptionWarningPercentage) },
|
||||||
{ "vbat_cutoff_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, lvcPercentage) },
|
{ "vbat_cutoff_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, lvcPercentage) },
|
||||||
|
{ "force_battery_cell_count", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 24 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, forceBatteryCellCount) },
|
||||||
|
|
||||||
// PG_VOLTAGE_SENSOR_ADC_CONFIG
|
// PG_VOLTAGE_SENSOR_ADC_CONFIG
|
||||||
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VBAT_SCALE_MIN, VBAT_SCALE_MAX }, PG_VOLTAGE_SENSOR_ADC_CONFIG, offsetof(voltageSensorADCConfig_t, vbatscale) },
|
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, .config.minmax = { VBAT_SCALE_MIN, VBAT_SCALE_MAX }, PG_VOLTAGE_SENSOR_ADC_CONFIG, offsetof(voltageSensorADCConfig_t, vbatscale) },
|
||||||
|
|
|
@ -105,6 +105,9 @@ PG_RESET_TEMPLATE(batteryConfig_t, batteryConfig,
|
||||||
.batteryCapacity = 0,
|
.batteryCapacity = 0,
|
||||||
.currentMeterSource = DEFAULT_CURRENT_METER_SOURCE,
|
.currentMeterSource = DEFAULT_CURRENT_METER_SOURCE,
|
||||||
|
|
||||||
|
// cells
|
||||||
|
.forceBatteryCellCount = 0, //0 will be ignored
|
||||||
|
|
||||||
// warnings / alerts
|
// warnings / alerts
|
||||||
.useVBatAlerts = true,
|
.useVBatAlerts = true,
|
||||||
.useConsumptionAlerts = false,
|
.useConsumptionAlerts = false,
|
||||||
|
@ -180,14 +183,18 @@ void batteryUpdatePresence(void)
|
||||||
/* battery has just been connected - calculate cells, warning voltages and reset state */
|
/* battery has just been connected - calculate cells, warning voltages and reset state */
|
||||||
|
|
||||||
|
|
||||||
unsigned cells = (voltageMeter.filtered / batteryConfig()->vbatmaxcellvoltage) + 1;
|
|
||||||
if (cells > 8) {
|
|
||||||
// something is wrong, we expect 8 cells maximum (and autodetection will be problematic at 6+ cells)
|
|
||||||
cells = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
consumptionState = voltageState = BATTERY_OK;
|
consumptionState = voltageState = BATTERY_OK;
|
||||||
batteryCellCount = cells;
|
if (batteryConfig()->forceBatteryCellCount != 0) {
|
||||||
|
batteryCellCount = batteryConfig()->forceBatteryCellCount;
|
||||||
|
} else {
|
||||||
|
unsigned cells = (voltageMeter.filtered / batteryConfig()->vbatmaxcellvoltage) + 1;
|
||||||
|
if (cells > 8) {
|
||||||
|
// something is wrong, we expect 8 cells maximum (and autodetection will be problematic at 6+ cells)
|
||||||
|
cells = 8;
|
||||||
|
}
|
||||||
|
batteryCellCount = cells;
|
||||||
|
}
|
||||||
batteryWarningVoltage = batteryCellCount * batteryConfig()->vbatwarningcellvoltage;
|
batteryWarningVoltage = batteryCellCount * batteryConfig()->vbatwarningcellvoltage;
|
||||||
batteryCriticalVoltage = batteryCellCount * batteryConfig()->vbatmincellvoltage;
|
batteryCriticalVoltage = batteryCellCount * batteryConfig()->vbatmincellvoltage;
|
||||||
lowVoltageCutoff.percentage = 100;
|
lowVoltageCutoff.percentage = 100;
|
||||||
|
|
|
@ -48,6 +48,8 @@ typedef struct batteryConfig_s {
|
||||||
|
|
||||||
uint8_t vbatfullcellvoltage; // Cell voltage at which the battery is deemed to be "full" 0.1V units, default is 41 (4.1V)
|
uint8_t vbatfullcellvoltage; // Cell voltage at which the battery is deemed to be "full" 0.1V units, default is 41 (4.1V)
|
||||||
|
|
||||||
|
uint8_t forceBatteryCellCount; // number of cells in battery, used for overwriting auto-detected cell count if someone has issues with it.
|
||||||
|
|
||||||
} batteryConfig_t;
|
} batteryConfig_t;
|
||||||
|
|
||||||
typedef struct lowVoltageCutoff_s {
|
typedef struct lowVoltageCutoff_s {
|
||||||
|
|
Loading…
Reference in New Issue