Skip to content

Commit

Permalink
Center ARMED message and stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCEvans committed Dec 24, 2022
1 parent 7b70abd commit 1d6e3be
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions src/main/osd/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,11 @@ static void osdGetBlackboxStatusString(char * buff)
}
#endif

static void osdDisplayStatisticLabel(uint8_t y, const char * text, const char * value)
static void osdDisplayStatisticLabel(uint8_t x, uint8_t y, const char * text, const char * value)
{
displayWrite(osdDisplayPort, 2, y, DISPLAYPORT_ATTR_NORMAL, text);
displayWrite(osdDisplayPort, 20, y, DISPLAYPORT_ATTR_NORMAL, ":");
displayWrite(osdDisplayPort, 22, y, DISPLAYPORT_ATTR_NORMAL, value);
displayWrite(osdDisplayPort, x - 13, y, DISPLAYPORT_ATTR_NORMAL, text);
displayWrite(osdDisplayPort, x + 5, y, DISPLAYPORT_ATTR_NORMAL, ":");
displayWrite(osdDisplayPort, x + 7, y, DISPLAYPORT_ATTR_NORMAL, value);
}

/*
Expand All @@ -707,6 +707,7 @@ static bool isSomeStatEnabled(void)

static bool osdDisplayStat(int statistic, uint8_t displayRow)
{
uint8_t midCol = osdDisplayPort->cols / 2;
char buff[OSD_ELEMENT_BUFFER_LENGTH];

switch (statistic) {
Expand All @@ -719,39 +720,39 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
tfp_sprintf(buff, "NO RTC");
}

displayWrite(osdDisplayPort, 2, displayRow, DISPLAYPORT_ATTR_NORMAL, buff);
displayWrite(osdDisplayPort, midCol - 13, displayRow, DISPLAYPORT_ATTR_NORMAL, buff);
return true;
}

case OSD_STAT_TIMER_1:
osdFormatTimer(buff, false, (OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_1]) == OSD_TIMER_SRC_ON ? false : true), OSD_TIMER_1);
osdDisplayStatisticLabel(displayRow, osdTimerSourceNames[OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_1])], buff);
osdDisplayStatisticLabel(midCol, displayRow, osdTimerSourceNames[OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_1])], buff);
return true;

case OSD_STAT_TIMER_2:
osdFormatTimer(buff, false, (OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_2]) == OSD_TIMER_SRC_ON ? false : true), OSD_TIMER_2);
osdDisplayStatisticLabel(displayRow, osdTimerSourceNames[OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_2])], buff);
osdDisplayStatisticLabel(midCol, displayRow, osdTimerSourceNames[OSD_TIMER_SRC(osdConfig()->timers[OSD_TIMER_2])], buff);
return true;

case OSD_STAT_MAX_ALTITUDE: {
osdPrintFloat(buff, SYM_NONE, osdGetMetersToSelectedUnit(stats.max_altitude) / 100.0f, "", 1, true, osdGetMetersToSelectedUnitSymbol());
osdDisplayStatisticLabel(displayRow, "MAX ALTITUDE", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX ALTITUDE", buff);
return true;
}

#ifdef USE_GPS
case OSD_STAT_MAX_SPEED:
if (featureIsEnabled(FEATURE_GPS)) {
tfp_sprintf(buff, "%d%c", osdGetSpeedToSelectedUnit(stats.max_speed), osdGetSpeedToSelectedUnitSymbol());
osdDisplayStatisticLabel(displayRow, "MAX SPEED", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX SPEED", buff);
return true;
}
break;

case OSD_STAT_MAX_DISTANCE:
if (featureIsEnabled(FEATURE_GPS)) {
osdFormatDistanceString(buff, stats.max_distance, SYM_NONE);
osdDisplayStatisticLabel(displayRow, "MAX DISTANCE", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX DISTANCE", buff);
return true;
}
break;
Expand All @@ -760,57 +761,57 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
if (featureIsEnabled(FEATURE_GPS)) {
const int distanceFlown = GPS_distanceFlownInCm / 100;
osdFormatDistanceString(buff, distanceFlown, SYM_NONE);
osdDisplayStatisticLabel(displayRow, "FLIGHT DISTANCE", buff);
osdDisplayStatisticLabel(midCol, displayRow, "FLIGHT DISTANCE", buff);
return true;
}
break;
#endif

case OSD_STAT_MIN_BATTERY:
osdPrintFloat(buff, SYM_NONE, stats.min_voltage / 100.0f, "", 2, true, SYM_VOLT);
osdDisplayStatisticLabel(displayRow, osdConfig()->stat_show_cell_value? "MIN AVG CELL" : "MIN BATTERY", buff);
osdDisplayStatisticLabel(midCol, displayRow, osdConfig()->stat_show_cell_value? "MIN AVG CELL" : "MIN BATTERY", buff);
return true;

case OSD_STAT_END_BATTERY:
osdPrintFloat(buff, SYM_NONE, stats.end_voltage / 100.0f, "", 2, true, SYM_VOLT);
osdDisplayStatisticLabel(displayRow, osdConfig()->stat_show_cell_value ? "END AVG CELL" : "END BATTERY", buff);
osdDisplayStatisticLabel(midCol, displayRow, osdConfig()->stat_show_cell_value ? "END AVG CELL" : "END BATTERY", buff);
return true;

case OSD_STAT_BATTERY:
{
const uint16_t statsVoltage = getStatsVoltage();
osdPrintFloat(buff, SYM_NONE, statsVoltage / 100.0f, "", 2, true, SYM_VOLT);
osdDisplayStatisticLabel(displayRow, osdConfig()->stat_show_cell_value ? "AVG BATT CELL" : "BATTERY", buff);
osdDisplayStatisticLabel(midCol, displayRow, osdConfig()->stat_show_cell_value ? "AVG BATT CELL" : "BATTERY", buff);
return true;
}
break;

case OSD_STAT_MIN_RSSI:
itoa(stats.min_rssi, buff, 10);
strcat(buff, "%");
osdDisplayStatisticLabel(displayRow, "MIN RSSI", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MIN RSSI", buff);
return true;

case OSD_STAT_MAX_CURRENT:
if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) {
tfp_sprintf(buff, "%d%c", stats.max_current, SYM_AMP);
osdDisplayStatisticLabel(displayRow, "MAX CURRENT", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX CURRENT", buff);
return true;
}
break;

case OSD_STAT_USED_MAH:
if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) {
tfp_sprintf(buff, "%d%c", getMAhDrawn(), SYM_MAH);
osdDisplayStatisticLabel(displayRow, "USED MAH", buff);
osdDisplayStatisticLabel(midCol, displayRow, "USED MAH", buff);
return true;
}
break;

case OSD_STAT_WATT_HOURS_DRAWN:
if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) {
osdPrintFloat(buff, SYM_NONE, getWhDrawn(), "", 2, true, SYM_NONE);
osdDisplayStatisticLabel(displayRow, "USED WATT HOURS", buff);
osdDisplayStatisticLabel(midCol, displayRow, "USED WATT HOURS", buff);
return true;
}
break;
Expand All @@ -819,7 +820,7 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
case OSD_STAT_BLACKBOX:
if (blackboxConfig()->device && blackboxConfig()->device != BLACKBOX_DEVICE_SERIAL) {
osdGetBlackboxStatusString(buff);
osdDisplayStatisticLabel(displayRow, "BLACKBOX", buff);
osdDisplayStatisticLabel(midCol, displayRow, "BLACKBOX", buff);
return true;
}
break;
Expand All @@ -829,7 +830,7 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
int32_t logNumber = blackboxGetLogNumber();
if (logNumber >= 0) {
itoa(logNumber, buff, 10);
osdDisplayStatisticLabel(displayRow, "BB LOG NUM", buff);
osdDisplayStatisticLabel(midCol, displayRow, "BB LOG NUM", buff);
return true;
}
}
Expand All @@ -840,7 +841,7 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
case OSD_STAT_MAX_G_FORCE:
if (sensors(SENSOR_ACC)) {
osdPrintFloat(buff, SYM_NONE, stats.max_g_force, "", 1, true, 'G');
osdDisplayStatisticLabel(displayRow, "MAX G-FORCE", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX G-FORCE", buff);
return true;
}
break;
Expand All @@ -854,23 +855,23 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
ix = tfp_sprintf(buff, "%d ", stats.max_esc_temp_ix);
}
tfp_sprintf(buff + ix, "%d%c", osdConvertTemperatureToSelectedUnit(stats.max_esc_temp), osdGetTemperatureSymbolForSelectedUnit());
osdDisplayStatisticLabel(displayRow, "MAX ESC TEMP", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX ESC TEMP", buff);
return true;
}
#endif

#if defined(USE_ESC_SENSOR) || defined(USE_DSHOT_TELEMETRY)
case OSD_STAT_MAX_ESC_RPM:
itoa(stats.max_esc_rpm, buff, 10);
osdDisplayStatisticLabel(displayRow, "MAX ESC RPM", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MAX ESC RPM", buff);
return true;
#endif

#ifdef USE_RX_LINK_QUALITY_INFO
case OSD_STAT_MIN_LINK_QUALITY:
tfp_sprintf(buff, "%d", stats.min_link_quality);
strcat(buff, "%");
osdDisplayStatisticLabel(displayRow, "MIN LINK", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MIN LINK", buff);
return true;
#endif

Expand All @@ -880,9 +881,9 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
int value = getMaxFFT();
if (value > 0) {
tfp_sprintf(buff, "%dHZ", value);
osdDisplayStatisticLabel(displayRow, "PEAK FFT", buff);
osdDisplayStatisticLabel(midCol, displayRow, "PEAK FFT", buff);
} else {
osdDisplayStatisticLabel(displayRow, "PEAK FFT", "THRT<20%");
osdDisplayStatisticLabel(midCol, displayRow, "PEAK FFT", "THRT<20%");
}
return true;
}
Expand All @@ -892,27 +893,27 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
#ifdef USE_RX_RSSI_DBM
case OSD_STAT_MIN_RSSI_DBM:
tfp_sprintf(buff, "%3d", stats.min_rssi_dbm);
osdDisplayStatisticLabel(displayRow, "MIN RSSI DBM", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MIN RSSI DBM", buff);
return true;
#endif

#ifdef USE_RX_RSNR
case OSD_STAT_MIN_RSNR:
tfp_sprintf(buff, "%3d", stats.min_rsnr);
osdDisplayStatisticLabel(displayRow, "MIN RSNR", buff);
osdDisplayStatisticLabel(midCol, displayRow, "MIN RSNR", buff);
return true;
#endif

#ifdef USE_PERSISTENT_STATS
case OSD_STAT_TOTAL_FLIGHTS:
itoa(statsConfig()->stats_total_flights, buff, 10);
osdDisplayStatisticLabel(displayRow, "TOTAL FLIGHTS", buff);
osdDisplayStatisticLabel(midCol, displayRow, "TOTAL FLIGHTS", buff);
return true;

case OSD_STAT_TOTAL_TIME: {
int minutes = statsConfig()->stats_total_time_s / 60;
tfp_sprintf(buff, "%d:%02dH", minutes / 60, minutes % 60);
osdDisplayStatisticLabel(displayRow, "TOTAL FLIGHT TIME", buff);
osdDisplayStatisticLabel(midCol, displayRow, "TOTAL FLIGHT TIME", buff);
return true;
}

Expand All @@ -924,7 +925,7 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
} else {
tfp_sprintf(buff, "%d%c", statsConfig()->stats_total_dist_m / METERS_PER_KILOMETER, SYM_KM);
}
osdDisplayStatisticLabel(displayRow, "TOTAL DISTANCE", buff);
osdDisplayStatisticLabel(midCol, displayRow, "TOTAL DISTANCE", buff);
return true;
#endif
}
Expand Down Expand Up @@ -955,6 +956,8 @@ static void osdRenderStatsBegin(void)
// call repeatedly until it returns true which indicates that all stats have been rendered.
static bool osdRenderStatsContinue(void)
{
uint8_t midCol = osdDisplayPort->cols / 2;

if (osdStatsRenderingState.row == 0) {

bool displayLabel = false;
Expand All @@ -971,7 +974,7 @@ static bool osdRenderStatsContinue(void)
}

if (displayLabel) {
displayWrite(osdDisplayPort, 2, osdStatsRenderingState.row++, DISPLAYPORT_ATTR_NORMAL, " --- STATS ---");
displayWrite(osdDisplayPort, midCol - (strlen("--- STATS ---") / 2), osdStatsRenderingState.row++, DISPLAYPORT_ATTR_NORMAL, "--- STATS ---");
return false;
}
}
Expand Down Expand Up @@ -1064,6 +1067,8 @@ static bool osdRefreshStats(void)

static timeDelta_t osdShowArmed(void)
{
uint8_t midRow = osdDisplayPort->rows / 2;
uint8_t midCol = osdDisplayPort->cols / 2;
timeDelta_t ret;

displayClearScreen(osdDisplayPort, DISPLAY_CLEAR_WAIT);
Expand All @@ -1076,10 +1081,10 @@ static timeDelta_t osdShowArmed(void)
} else {
ret = (REFRESH_1S / 2);
}
displayWrite(osdDisplayPort, 12, 7, DISPLAYPORT_ATTR_NORMAL, "ARMED");
displayWrite(osdDisplayPort, midCol - (strlen("ARMED") / 2), midRow, DISPLAYPORT_ATTR_NORMAL, "ARMED");

if (isFlipOverAfterCrashActive()) {
displayWrite(osdDisplayPort, 8, 8, DISPLAYPORT_ATTR_NORMAL, CRASH_FLIP_WARNING);
displayWrite(osdDisplayPort, midCol - (strlen(CRASH_FLIP_WARNING) / 2), midRow + 1, DISPLAYPORT_ATTR_NORMAL, CRASH_FLIP_WARNING);
}

return ret;
Expand Down

0 comments on commit 1d6e3be

Please sign in to comment.