mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 09:45:37 +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:
parent
3f116fd103
commit
01fb3940e7
4 changed files with 7 additions and 19 deletions
|
@ -511,13 +511,13 @@ uint8_t getBatteryCellCount(void)
|
|||
|
||||
uint16_t getBatteryAverageCellVoltage(void)
|
||||
{
|
||||
return voltageMeter.displayFiltered / batteryCellCount;
|
||||
return (batteryCellCount ? voltageMeter.displayFiltered / batteryCellCount : 0);
|
||||
}
|
||||
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
uint16_t getBatterySagCellVoltage(void)
|
||||
{
|
||||
return voltageMeter.sagFiltered / batteryCellCount;
|
||||
return (batteryCellCount ? voltageMeter.sagFiltered / batteryCellCount : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue