mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 04:15:44 +03:00
Merge pull request #6974 from etracer65/osd_remaining_time_div0
Fix OSD time remaining division by zero
This commit is contained in:
commit
05f935d38e
1 changed files with 2 additions and 2 deletions
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue