1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Merge pull request #6974 from etracer65/osd_remaining_time_div0

Fix OSD time remaining division by zero
This commit is contained in:
Michael Keller 2018-10-24 23:47:57 +13:00 committed by GitHub
commit 05f935d38e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;