Skip to content

Commit

Permalink
Merge pull request #6470 from avsaase/avs-fix-osd-efficiency-bug
Browse files Browse the repository at this point in the history
Do not show efficiency on osd when ground speed is below 1 m/s
  • Loading branch information
digitalentity authored Jan 5, 2021
2 parents b40eaf4 + 791ed4e commit 9914216
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2108,8 +2108,7 @@ static bool osdDrawSingleElement(uint8_t item)
case OSD_EFFICIENCY_MAH_PER_KM:
{
// amperage is in centi amps, speed is in cms/s. We want
// mah/km. Values over 999 are considered useless and
// displayed as "---""
// mah/km. Only show when ground speed > 1m/s.
static pt1Filter_t eFilterState;
static timeUs_t efficiencyUpdated = 0;
int32_t value = 0;
Expand All @@ -2125,7 +2124,7 @@ static bool osdDrawSingleElement(uint8_t item)
value = eFilterState.state;
}
}
if (value > 0 && value <= 999) {
if (value > 0 && gpsSol.groundSpeed > 100) {
tfp_sprintf(buff, "%3d", (int)value);
} else {
buff[0] = buff[1] = buff[2] = '-';
Expand All @@ -2139,8 +2138,7 @@ static bool osdDrawSingleElement(uint8_t item)
case OSD_EFFICIENCY_WH_PER_KM:
{
// amperage is in centi amps, speed is in cms/s. We want
// mWh/km. Values over 999Wh/km are considered useless and
// displayed as "---""
// mWh/km. Only show when ground speed > 1m/s.
static pt1Filter_t eFilterState;
static timeUs_t efficiencyUpdated = 0;
int32_t value = 0;
Expand All @@ -2156,7 +2154,7 @@ static bool osdDrawSingleElement(uint8_t item)
value = eFilterState.state;
}
}
if (value > 0 && value <= 999999) {
if (value > 0 && gpsSol.groundSpeed > 100) {
osdFormatCentiNumber(buff, value / 10, 0, 2, 0, 3);
} else {
buff[0] = buff[1] = buff[2] = '-';
Expand Down Expand Up @@ -2937,7 +2935,7 @@ static void osdShowStats(void)
if (osdDisplayIsPAL())
displayWrite(osdDisplayPort, statNameX, top++, " --- STATS ---");

if (STATE(GPS_FIX)) {
if (feature(FEATURE_GPS)) {
displayWrite(osdDisplayPort, statNameX, top, "MAX SPEED :");
osdFormatVelocityStr(buff, stats.max_speed, true);
osdLeftAlignString(buff);
Expand Down Expand Up @@ -2989,7 +2987,7 @@ static void osdShowStats(void)
displayWrite(osdDisplayPort, statValuesX, top++, buff);

int32_t totalDistance = getTotalTravelDistance();
if (totalDistance > 0) {
if (feature(FEATURE_GPS)) {
displayWrite(osdDisplayPort, statNameX, top, "AVG EFFICIENCY :");
if (osdConfig()->stats_energy_unit == OSD_STATS_ENERGY_UNIT_MAH)
tfp_sprintf(buff, "%d%c%c", (int)(getMAhDrawn() * 100000 / totalDistance),
Expand All @@ -3000,6 +2998,19 @@ static void osdShowStats(void)
buff[4] = SYM_WH_KM_1;
buff[5] = '\0';
}
// If traveled distance is less than 100 meters efficiency numbers are useless and unreliable so display --- instead
if (totalDistance < 10000) {
buff[0] = buff[1] = buff[2] = '-';
if (osdConfig()->stats_energy_unit == OSD_STATS_ENERGY_UNIT_MAH){
buff[3] = SYM_MAH_KM_0;
buff[4] = SYM_MAH_KM_1;
buff[5] = '\0';
} else {
buff[3] = SYM_WH_KM_0;
buff[4] = SYM_WH_KM_1;
buff[5] = '\0';
}
}
displayWrite(osdDisplayPort, statValuesX, top++, buff);
}
}
Expand Down

0 comments on commit 9914216

Please sign in to comment.