1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 06:45:16 +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:
Bruce Luckcuck 2018-10-23 14:09:44 -04:00
parent 6adfd345db
commit c1f40b8ebb

View file

@ -604,13 +604,13 @@ static bool osdDrawSingleElement(uint8_t item)
case OSD_REMAINING_TIME_ESTIMATE: case OSD_REMAINING_TIME_ESTIMATE:
{ {
const int mAhDrawn = getMAhDrawn(); 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, "--:--"); tfp_sprintf(buff, "--:--");
} else if (mAhDrawn > osdConfig()->cap_alarm) { } else if (mAhDrawn > osdConfig()->cap_alarm) {
tfp_sprintf(buff, "00:00"); tfp_sprintf(buff, "00:00");
} else { } else {
const int remaining_time = (int)((osdConfig()->cap_alarm - mAhDrawn) * ((float)flyTime) / mAhDrawn);
osdFormatTime(buff, OSD_TIMER_PREC_SECOND, remaining_time); osdFormatTime(buff, OSD_TIMER_PREC_SECOND, remaining_time);
} }
break; break;