1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 05:45:31 +03:00

Reduce flash usage in OSD stats screen

This commit is contained in:
Dan Nixon 2017-05-23 11:38:23 +01:00
parent 5f4a72ad5b
commit 562ffbdbc4

View file

@ -824,6 +824,13 @@ static void osdGetBlackboxStatusString(char * buff, uint8_t len)
} }
#endif #endif
static void osdDisplayStatisticLabel(uint8_t y, const char * text, const char * value)
{
displayWrite(osdDisplayPort, 2, y, text);
displayWrite(osdDisplayPort, 20, y, ":");
displayWrite(osdDisplayPort, 22, y, value);
}
static void osdShowStats(void) static void osdShowStats(void)
{ {
uint8_t top = 2; uint8_t top = 2;
@ -833,70 +840,59 @@ static void osdShowStats(void)
displayWrite(osdDisplayPort, 2, top++, " --- STATS ---"); displayWrite(osdDisplayPort, 2, top++, " --- STATS ---");
if (osdConfig()->enabled_stats[OSD_STAT_ARMEDTIME]) { if (osdConfig()->enabled_stats[OSD_STAT_ARMEDTIME]) {
displayWrite(osdDisplayPort, 2, top, "ARMED TIME :");
tfp_sprintf(buff, "%02d:%02d", stats.armed_time / 60, stats.armed_time % 60); tfp_sprintf(buff, "%02d:%02d", stats.armed_time / 60, stats.armed_time % 60);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "ARMED TIME", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_FLYTIME]) { if (osdConfig()->enabled_stats[OSD_STAT_FLYTIME]) {
displayWrite(osdDisplayPort, 2, top, "FLY TIME :");
tfp_sprintf(buff, "%02d:%02d", flyTime / 60, flyTime % 60); tfp_sprintf(buff, "%02d:%02d", flyTime / 60, flyTime % 60);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "FLY TIME", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_MAX_SPEED] && STATE(GPS_FIX)) { if (osdConfig()->enabled_stats[OSD_STAT_MAX_SPEED] && STATE(GPS_FIX)) {
displayWrite(osdDisplayPort, 2, top, "MAX SPEED :");
itoa(stats.max_speed, buff, 10); itoa(stats.max_speed, buff, 10);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "MAX SPEED", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_MIN_BATTERY]) { if (osdConfig()->enabled_stats[OSD_STAT_MIN_BATTERY]) {
displayWrite(osdDisplayPort, 2, top, "MIN BATTERY :");
tfp_sprintf(buff, "%d.%1dV", stats.min_voltage / 10, stats.min_voltage % 10); tfp_sprintf(buff, "%d.%1dV", stats.min_voltage / 10, stats.min_voltage % 10);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "MIN BATTERY", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_END_BATTERY]) { if (osdConfig()->enabled_stats[OSD_STAT_END_BATTERY]) {
displayWrite(osdDisplayPort, 2, top, "END BATTERY :");
tfp_sprintf(buff, "%d.%1dV", getBatteryVoltage() / 10, getBatteryVoltage() % 10); tfp_sprintf(buff, "%d.%1dV", getBatteryVoltage() / 10, getBatteryVoltage() % 10);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "END BATTERY", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_MIN_RSSI]) { if (osdConfig()->enabled_stats[OSD_STAT_MIN_RSSI]) {
displayWrite(osdDisplayPort, 2, top, "MIN RSSI :");
itoa(stats.min_rssi, buff, 10); itoa(stats.min_rssi, buff, 10);
strcat(buff, "%"); strcat(buff, "%");
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "MIN RSSI", buff);
} }
if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) { if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) {
if (osdConfig()->enabled_stats[OSD_STAT_MAX_CURRENT]) { if (osdConfig()->enabled_stats[OSD_STAT_MAX_CURRENT]) {
displayWrite(osdDisplayPort, 2, top, "MAX CURRENT :");
itoa(stats.max_current, buff, 10); itoa(stats.max_current, buff, 10);
strcat(buff, "A"); strcat(buff, "A");
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "MAX CURRENT", buff);
} }
if (osdConfig()->enabled_stats[OSD_STAT_USED_MAH]) { if (osdConfig()->enabled_stats[OSD_STAT_USED_MAH]) {
displayWrite(osdDisplayPort, 2, top, "USED MAH :"); tfp_sprintf(buff, "%d%c", getMAhDrawn(), SYM_MAH);
itoa(getMAhDrawn(), buff, 10); osdDisplayStatisticLabel(top++, "USED MAH", buff);
strcat(buff, "\x07");
displayWrite(osdDisplayPort, 22, top++, buff);
} }
} }
if (osdConfig()->enabled_stats[OSD_STAT_MAX_ALTITUDE]) { if (osdConfig()->enabled_stats[OSD_STAT_MAX_ALTITUDE]) {
displayWrite(osdDisplayPort, 2, top, "MAX ALTITUDE :");
int32_t alt = osdGetAltitude(stats.max_altitude); int32_t alt = osdGetAltitude(stats.max_altitude);
tfp_sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol()); tfp_sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol());
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "MAX ALTITUDE", buff);
} }
#ifdef BLACKBOX #ifdef BLACKBOX
if (osdConfig()->enabled_stats[OSD_STAT_BLACKBOX] && blackboxConfig()->device && blackboxConfig()->device != BLACKBOX_DEVICE_SERIAL) { if (osdConfig()->enabled_stats[OSD_STAT_BLACKBOX] && blackboxConfig()->device && blackboxConfig()->device != BLACKBOX_DEVICE_SERIAL) {
displayWrite(osdDisplayPort, 2, top, "BLACKBOX :");
osdGetBlackboxStatusString(buff, 10); osdGetBlackboxStatusString(buff, 10);
displayWrite(osdDisplayPort, 22, top++, buff); osdDisplayStatisticLabel(top++, "BLACKBOX", buff);
} }
#endif #endif
} }