mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Fix OSD time remaining division by zero
If the current sensor wasn't configured (or the mahDrawn was still zero) then there would be a division by zero error in the remaining time OSD element calculation. Rearranged the logic to prevent.
This commit is contained in:
parent
6adfd345db
commit
c1f40b8ebb
1 changed files with 2 additions and 2 deletions
|
@ -604,13 +604,13 @@ static bool osdDrawSingleElement(uint8_t item)
|
|||
case OSD_REMAINING_TIME_ESTIMATE:
|
||||
{
|
||||
const int mAhDrawn = getMAhDrawn();
|
||||
const int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn);
|
||||
|
||||
if (mAhDrawn < 0.1 * osdConfig()->cap_alarm) {
|
||||
if (mAhDrawn <= 0.1 * osdConfig()->cap_alarm) { // also handles the mAhDrawn == 0 condition
|
||||
tfp_sprintf(buff, "--:--");
|
||||
} else if (mAhDrawn > osdConfig()->cap_alarm) {
|
||||
tfp_sprintf(buff, "00:00");
|
||||
} else {
|
||||
const int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn);
|
||||
osdFormatTime(buff, OSD_TIMER_PREC_SECOND, remaining_time);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue