1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 08:45:36 +03:00

Fix multiple div-by-zero related to battery cell count

Battery cell count will be 0 if the battery is not detected or the voltage meter is not configured. This exposed multiple div-by-zero risks.
This commit is contained in:
Bruce Luckcuck 2020-12-25 14:17:00 -05:00
parent 3f116fd103
commit 01fb3940e7
4 changed files with 7 additions and 19 deletions

View file

@ -72,11 +72,10 @@ extern "C" {
static int32_t amperage = 100;
static int32_t estimatedVario = 0;
static uint8_t batteryRemaining = 0;
static uint16_t avgCellVoltage = vbat/testBatteryCellCount;
static throttleStatus_e throttleStatus = THROTTLE_HIGH;
static uint32_t definedFeatures = 0;
static uint32_t definedSensors = SENSOR_GYRO | SENSOR_ACC | SENSOR_MAG | SENSOR_SONAR | SENSOR_GPS | SENSOR_GPSMAG;
static uint16_t testBatteryVoltage = 1000;
int32_t getAmperage(void)
{
@ -95,7 +94,7 @@ uint8_t calculateBatteryPercentageRemaining(void)
uint16_t getBatteryAverageCellVoltage(void)
{
return avgCellVoltage;
return testBatteryVoltage / testBatteryCellCount;
}
int32_t getMAhDrawn(void)
@ -128,7 +127,6 @@ typedef struct serialPortStub_s {
} serialPortStub_t;
static uint16_t testBatteryVoltage = 1000;
uint16_t getBatteryVoltage(void)
{
return testBatteryVoltage;