From bc596e1f8b3686aafc75753adb70b1a6efedcfcb Mon Sep 17 00:00:00 2001 From: timman2er Date: Wed, 29 Aug 2018 02:38:41 +0200 Subject: [PATCH] fixup Mikeller and levinap --- src/main/interface/msp.c | 2 -- src/main/interface/settings.c | 2 +- src/main/sensors/battery.c | 15 +++++++++------ src/main/sensors/battery.h | 1 - src/main/target/COLIBRI_RACE/i2c_bst.c | 2 -- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/interface/msp.c b/src/main/interface/msp.c index 685193b430..65108aca1b 100644 --- a/src/main/interface/msp.c +++ b/src/main/interface/msp.c @@ -654,7 +654,6 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce sbufWriteU16(dst, batteryConfig()->batteryCapacity); sbufWriteU8(dst, batteryConfig()->voltageMeterSource); sbufWriteU8(dst, batteryConfig()->currentMeterSource); - sbufWriteU8(dst, batteryConfig()->forceBatteryCellCount); break; case MSP_TRANSPONDER_CONFIG: { @@ -2419,7 +2418,6 @@ static mspResult_e mspCommonProcessInCommand(uint8_t cmdMSP, sbuf_t *src, mspPos batteryConfigMutable()->batteryCapacity = sbufReadU16(src); batteryConfigMutable()->voltageMeterSource = sbufReadU8(src); batteryConfigMutable()->currentMeterSource = sbufReadU8(src); - batteryConfigMutable()->forceBatteryCellCount = sbufReadU8(src); break; #if defined(USE_OSD) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 4cd45dd48d..8dfc912945 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -682,7 +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) }, { "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) }, - { "force_battery_cell_count", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 80 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, forceBatteryCellCount) }, + { "force_battery_cell_count", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 24 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, forceBatteryCellCount) }, // 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) }, diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index a5eb19ea9e..6d8fadb206 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -183,17 +183,20 @@ void batteryUpdatePresence(void) /* 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; if (batteryConfig()->forceBatteryCellCount != 0) { batteryCellCount = batteryConfig()->forceBatteryCellCount; } else { - batteryCellCount = cells; + 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; + } + else + { + batteryCellCount = cells; + } } batteryWarningVoltage = batteryCellCount * batteryConfig()->vbatwarningcellvoltage; batteryCriticalVoltage = batteryCellCount * batteryConfig()->vbatmincellvoltage; diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index ee9f4df5d0..5f311ba42b 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -48,7 +48,6 @@ 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) - // cells uint8_t forceBatteryCellCount; // number of cells in battery, used for overwriting auto-detected cell count if someone has issues with it. } batteryConfig_t; diff --git a/src/main/target/COLIBRI_RACE/i2c_bst.c b/src/main/target/COLIBRI_RACE/i2c_bst.c index ea01734161..02685a8251 100644 --- a/src/main/target/COLIBRI_RACE/i2c_bst.c +++ b/src/main/target/COLIBRI_RACE/i2c_bst.c @@ -381,7 +381,6 @@ static bool bstSlaveProcessFeedbackCommand(uint8_t bstRequest) bstWrite8(batteryConfig()->vbatmincellvoltage); bstWrite8(batteryConfig()->vbatmaxcellvoltage); bstWrite8(batteryConfig()->vbatwarningcellvoltage); - bstWrite8(batteryConfig()->forceBatteryCellCount); break; case BST_FEATURE: @@ -539,7 +538,6 @@ static bool bstSlaveProcessWriteCommand(uint8_t bstWriteCommand) batteryConfigMutable()->vbatmincellvoltage = bstRead8(); // vbatlevel_warn1 in MWC2.3 GUI batteryConfigMutable()->vbatmaxcellvoltage = bstRead8(); // vbatlevel_warn2 in MWC2.3 GUI batteryConfigMutable()->vbatwarningcellvoltage = bstRead8(); // vbatlevel when buzzer starts to alert - batteryConfigMutable()->forceBatteryCellCount = bstRead8(); break; case BST_ACC_CALIBRATION: