From 00c3a5d1b41248032d79ca652c09524113f11903 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Mon, 15 Apr 2019 19:27:31 -0400 Subject: [PATCH] Maximize OSD stats display lines based on video mode Will dynamically determine the number of active OSD stats lines that are being displayed (accounting for user selections and #define logic) and maximize the number of stats that can be displayed based on the current video format (13 for NTSC, 16 for PAL). If the number of stats is equal to or greater than the available display lines, the heading will be suppressed and used instead for an extra stats line. The entire stats page will be centered vertically based on the screen size determined by the video format. --- src/main/osd/osd.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index cac20672d..eef60ae54 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -120,6 +120,7 @@ static uint8_t osdProfile = 1; static displayPort_t *osdDisplayPort; static bool suppressStatsDisplay = false; +static uint8_t osdStatsRowCount = 0; #ifdef USE_ESC_SENSOR escSensorData_t *osdEscDataCombined; @@ -462,13 +463,26 @@ static bool isSomeStatEnabled(void) // on the stats screen will have to be more beneficial than the hassle of not matching exactly to the // configurator list. -static void osdShowStats(uint16_t endBatteryVoltage) +static uint8_t osdShowStats(uint16_t endBatteryVoltage, int statsRowCount) { - uint8_t top = 2; + uint8_t top = 0; char buff[OSD_ELEMENT_BUFFER_LENGTH]; + bool displayLabel = false; + + // if statsRowCount is 0 then we're running an initial analysis of the active stats items + if (statsRowCount > 0) { + const int availableRows = osdDisplayPort->rows; + int displayRows = MIN(statsRowCount, availableRows); + if (statsRowCount < availableRows) { + displayLabel = true; + displayRows++; + } + top = (availableRows - displayRows) / 2; // center the stats vertically + } - displayClearScreen(osdDisplayPort); - displayWrite(osdDisplayPort, 2, top++, " --- STATS ---"); + if (displayLabel) { + displayWrite(osdDisplayPort, 2, top++, " --- STATS ---"); + } if (osdStatGetState(OSD_STAT_RTC_DATE_TIME)) { bool success = false; @@ -603,6 +617,22 @@ static void osdShowStats(uint16_t endBatteryVoltage) } } #endif + + return top; +} + +static void osdRefreshStats(uint16_t endBatteryVoltage) +{ + displayClearScreen(osdDisplayPort); + if (osdStatsRowCount == 0) { + // No stats row count has been set yet. + // Go through the logic one time to determine how many stats are actually displayed. + osdStatsRowCount = osdShowStats(endBatteryVoltage, 0); + // Then clear the screen and commence with normal stats display which will + // determine if the heading should be displayed and also center the content vertically. + displayClearScreen(osdDisplayPort); + } + osdShowStats(endBatteryVoltage, osdStatsRowCount); } static void osdShowArmed(void) @@ -634,6 +664,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) osdStatsEnabled = true; resumeRefreshAt = currentTimeUs + (60 * REFRESH_1S); endBatteryVoltage = getBatteryVoltage(); + osdStatsRowCount = 0; // reset to 0 so it will be recalculated on the next stats refresh } armState = ARMING_FLAG(ARMED); @@ -661,7 +692,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) } if (currentTimeUs >= osdStatsRefreshTimeUs) { osdStatsRefreshTimeUs = currentTimeUs + REFRESH_1S; - osdShowStats(endBatteryVoltage); + osdRefreshStats(endBatteryVoltage); } } } -- 2.11.4.GIT