Skip to content

Commit

Permalink
Center ARMED message and stats (betaflight#12086)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCEvans authored and davidbitton committed Feb 5, 2024
1 parent c34addd commit 73845e5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
83 changes: 44 additions & 39 deletions src/main/osd/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,15 @@ static void osdCompleteInitialization(void)
displayBeginTransaction(osdDisplayPort, DISPLAY_TRANSACTION_OPT_RESET_DRAWING);
displayClearScreen(osdDisplayPort, DISPLAY_CLEAR_WAIT);

osdDrawLogo(midCol - (OSD_LOGO_COLS) / 2, midRow - 7);
osdDrawLogo(midCol - (OSD_LOGO_COLS) / 2, midRow - 5);

char string_buffer[30];
tfp_sprintf(string_buffer, "V%s", FC_VERSION_STRING);
displayWrite(osdDisplayPort, midCol + 5, midRow - 2, DISPLAYPORT_ATTR_NORMAL, string_buffer);
displayWrite(osdDisplayPort, midCol + 5, midRow, DISPLAYPORT_ATTR_NORMAL, string_buffer);
#ifdef USE_CMS
displayWrite(osdDisplayPort, midCol - 8, midRow, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT1);
displayWrite(osdDisplayPort, midCol - 4, midRow + 1, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT2);
displayWrite(osdDisplayPort, midCol - 4, midRow + 2, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT3);
displayWrite(osdDisplayPort, midCol - 8, midRow + 2, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT1);
displayWrite(osdDisplayPort, midCol - 4, midRow + 3, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT2);
displayWrite(osdDisplayPort, midCol - 4, midRow + 4, DISPLAYPORT_ATTR_NORMAL, CMS_STARTUP_HELP_TEXT3);
#endif

#ifdef USE_RTC_TIME
Expand Down Expand Up @@ -680,11 +680,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 @@ -704,6 +704,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 @@ -716,39 +717,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 @@ -757,57 +758,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 @@ -816,7 +817,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 @@ -826,7 +827,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 @@ -837,7 +838,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 @@ -851,23 +852,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 @@ -877,9 +878,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 @@ -889,27 +890,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 @@ -921,7 +922,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 @@ -952,6 +953,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 @@ -968,7 +971,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 @@ -1061,6 +1064,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 @@ -1073,10 +1078,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
8 changes: 4 additions & 4 deletions src/test/unit/link_quality_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void doTestArm(bool testEmpty = true)

// then
// arming alert displayed
displayPortTestBufferSubstring(12, 7, "ARMED");
displayPortTestBufferSubstring(13, 8, "ARMED");

// given
// armed alert times out (0.5 seconds)
Expand Down Expand Up @@ -221,9 +221,9 @@ TEST(LQTest, TestInit)

// then
// display buffer should contain splash screen
displayPortTestBufferSubstring(7, 8, "MENU:THR MID");
displayPortTestBufferSubstring(11, 9, "+ YAW LEFT");
displayPortTestBufferSubstring(11, 10, "+ PITCH UP");
displayPortTestBufferSubstring(7, 10, "MENU:THR MID");
displayPortTestBufferSubstring(11, 11, "+ YAW LEFT");
displayPortTestBufferSubstring(11, 12, "+ PITCH UP");

// when
// splash screen timeout has elapsed
Expand Down
10 changes: 5 additions & 5 deletions src/test/unit/osd_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void doTestArm(bool testEmpty = true)

// then
// arming alert displayed
displayPortTestBufferSubstring(12, 7, "ARMED");
displayPortTestBufferSubstring(13, 8, "ARMED");

// given
// armed alert times out (0.5 seconds)
Expand Down Expand Up @@ -220,7 +220,7 @@ void doTestDisarm()
enabledStats >>= 1;
}

displayPortTestBufferSubstring(2, 7 - count / 2, " --- STATS ---");
displayPortTestBufferSubstring(9, 7 - count / 2, "--- STATS ---");
}
}

Expand Down Expand Up @@ -363,9 +363,9 @@ TEST_F(OsdTest, TestInit)

// then
// display buffer should contain splash screen
displayPortTestBufferSubstring(7, 8, "MENU:THR MID");
displayPortTestBufferSubstring(11, 9, "+ YAW LEFT");
displayPortTestBufferSubstring(11, 10, "+ PITCH UP");
displayPortTestBufferSubstring(7, 10, "MENU:THR MID");
displayPortTestBufferSubstring(11, 11, "+ YAW LEFT");
displayPortTestBufferSubstring(11, 12, "+ PITCH UP");

// when
// splash screen timeout has elapsed
Expand Down

0 comments on commit 73845e5

Please sign in to comment.