From 64e65349b11db9c933daa51948ed70631bacce32 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Sun, 21 Apr 2024 15:16:21 +0100 Subject: [PATCH 1/4] Initial code --- src/main/io/osd.c | 143 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 42 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 56245ea04af..eb99ef917e9 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1712,6 +1712,20 @@ void osdDisplaySwitchIndicator(const char *swName, int rcValue, char *buff) { buff[ptr] = '\0'; } +static bool osdElementEnabled(uint8_t elementID, bool onlyCurrentLayout) { + bool elementEnabled = false; + + if (onlyCurrentLayout) + elementEnabled = (osdLayoutsConfig()->item_pos[currentLayout][elementID]) ? true : false; + else { + for (uint8_t layout = 0; layout < 4 || elementEnabled; layout++) { + elementEnabled = (osdLayoutsConfig()->item_pos[layout][elementID]) ? true : false; + } + } + + return elementEnabled; +} + static bool osdDrawSingleElement(uint8_t item) { uint16_t pos = osdLayoutsConfig()->item_pos[currentLayout][item]; @@ -5122,19 +5136,21 @@ static void osdShowHDArmScreen(void) char craftNameBuf[MAX_NAME_LENGTH]; char versionBuf[osdDisplayPort->cols]; uint8_t safehomeRow = 0; - uint8_t armScreenRow = 2; // Start at row 2 + uint8_t armScreenRow = 1; armScreenRow = drawLogos(false, armScreenRow); armScreenRow++; - if (strlen(systemConfig()->craftName) > 0) { + if (osdElementEnabled(OSD_CRAFT_NAME, false) && strlen(systemConfig()->craftName) > 0) { osdFormatCraftName(craftNameBuf); - strcpy(buf2, "ARMED!"); + strcat(buf2, ": ! ARMED !"); tfp_sprintf(buf, "%s - %s", craftNameBuf, buf2); } else { - strcpy(buf, "ARMED!"); + strcpy(buf, " ! ARMED !"); } displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); + #if defined(USE_GPS) #if defined (USE_SAFE_HOME) if (posControl.safehomeState.distance) { @@ -5149,35 +5165,43 @@ static void osdShowHDArmScreen(void) #ifdef USE_MULTI_MISSION tfp_sprintf(buf, "MISSION %u/%u (%u WP)", posControl.loadedMultiMissionIndex, posControl.multiMissionCount, posControl.waypointCount); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); #else strcpy(buf, "*MISSION LOADED*"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); #endif } - armScreenRow++; #if defined(USE_GPS) if (feature(FEATURE_GPS)) { if (STATE(GPS_FIX_HOME)) { - if (osdConfig()->osd_home_position_arm_screen){ - osdFormatCoordinate(buf, SYM_LAT, GPS_home.lat); - osdFormatCoordinate(buf2, SYM_LON, GPS_home.lon); - uint8_t gap = 1; - uint8_t col = strlen(buf) + strlen(buf2) + gap; - - if ((osdDisplayPort->cols %2) != (col %2)) { - gap++; - col++; - } - - col = (osdDisplayPort->cols - col) / 2; + if (osdConfig()->osd_home_position_arm_screen) { + if (osdElementEnabled(OSD_PLUS_CODE, false)) { + int digits = osdConfig()->plus_code_digits; + olc_encode(GPS_home.lat, GPS_home.lon, digits, buf, sizeof(buf)); + tfp_sprintf(buf2, "+CODE: %s%c", buf, '\0'); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf2)) / 2, armScreenRow++, buf2); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); + } else { + osdFormatCoordinate(buf, SYM_LAT, GPS_home.lat); + osdFormatCoordinate(buf2, SYM_LON, GPS_home.lon); + uint8_t gap = 1; + uint8_t col = strlen(buf) + strlen(buf2) + gap; + + if ((osdDisplayPort->cols %2) != (col %2)) { + gap++; + col++; + } - displayWrite(osdDisplayPort, col, armScreenRow, buf); - displayWrite(osdDisplayPort, col + strlen(buf) + gap, armScreenRow++, buf2); + col = (osdDisplayPort->cols - col) / 2; - int digits = osdConfig()->plus_code_digits; - olc_encode(GPS_home.lat, GPS_home.lon, digits, buf, sizeof(buf)); - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + displayWrite(osdDisplayPort, col, armScreenRow, buf); + displayWrite(osdDisplayPort, col + strlen(buf) + gap, armScreenRow++, buf2); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); + } } #if defined (USE_SAFE_HOME) @@ -5191,11 +5215,14 @@ static void osdShowHDArmScreen(void) textAttributes_t elemAttr = _TEXT_ATTRIBUTES_BLINK_BIT; // write this message below the ARMED message to make it obvious displayWriteWithAttr(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, safehomeRow, buf, elemAttr); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); } #endif } else { strcpy(buf, "!NO HOME POSITION!"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); } armScreenRow++; } @@ -5204,6 +5231,7 @@ static void osdShowHDArmScreen(void) if (rtcGetDateTimeLocal(&dt)) { tfp_sprintf(buf, "%04u-%02u-%02u %02u:%02u:%02u", dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); armScreenRow++; } @@ -5224,45 +5252,72 @@ static void osdShowSDArmScreen(void) char buf2[MAX(osdDisplayPort->cols, FORMATTED_DATE_TIME_BUFSIZE)]; char craftNameBuf[MAX_NAME_LENGTH]; char versionBuf[osdDisplayPort->cols]; - // We need 12 visible rows, start row never < first fully visible row 1 - uint8_t armScreenRow = osdDisplayPort->rows > 13 ? (osdDisplayPort->rows - 12) / 2 : 1; + uint8_t armScreenRow = 1; uint8_t safehomeRow = 0; - strcpy(buf, "ARMED!"); + strcpy(buf, "! ARMED !"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); - safehomeRow = armScreenRow; - armScreenRow++; + memset(buf, '\0', sizeof(buf)); +#if defined(USE_GPS) +#if defined (USE_SAFE_HOME) + if (posControl.safehomeState.distance) { + safehomeRow = armScreenRow; + armScreenRow++; + } +#endif +#endif + + if (osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) + osdFormatPilotName(buf2); - if (strlen(systemConfig()->craftName) > 0) { + if (osdElementEnabled(OSD_CRAFT_NAME, false) && strlen(systemConfig()->craftName) > 0) { osdFormatCraftName(craftNameBuf); - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(systemConfig()->craftName)) / 2, armScreenRow++, craftNameBuf ); + if (strlen(buf2) > 0) { + strcat(buf2, ": "); + strcat(buf2, craftNameBuf); + } else + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(craftNameBuf)) / 2, armScreenRow++, craftNameBuf ); + } + + if (strlen(buf2) > 0) { + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf2)) / 2, armScreenRow++, buf2 ); + memset(buf2, '\0', sizeof(buf2)); } if (posControl.waypointListValid && posControl.waypointCount > 0) { #ifdef USE_MULTI_MISSION tfp_sprintf(buf, "MISSION %u/%u (%u WP)", posControl.loadedMultiMissionIndex, posControl.multiMissionCount, posControl.waypointCount); - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow, buf); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); #else strcpy(buf, "*MISSION LOADED*"); - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow, buf); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); #endif } - armScreenRow++; #if defined(USE_GPS) if (feature(FEATURE_GPS)) { if (STATE(GPS_FIX_HOME)) { if (osdConfig()->osd_home_position_arm_screen) { - osdFormatCoordinate(buf, SYM_LAT, GPS_home.lat); - osdFormatCoordinate(buf2, SYM_LON, GPS_home.lon); - - uint8_t gpsStartCol = (osdDisplayPort->cols - (strlen(buf) + strlen(buf2) + 2)) / 2; - displayWrite(osdDisplayPort, gpsStartCol, armScreenRow, buf); - displayWrite(osdDisplayPort, gpsStartCol + strlen(buf) + 2, armScreenRow++, buf2); - - int digits = osdConfig()->plus_code_digits; - olc_encode(GPS_home.lat, GPS_home.lon, digits, buf, sizeof(buf)); - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + // Show pluscode if enabled on any OSD layout. Otherwise show GNSS cordinates. + if (osdElementEnabled(OSD_PLUS_CODE, false)) { + int digits = osdConfig()->plus_code_digits; + olc_encode(GPS_home.lat, GPS_home.lon, digits, buf, sizeof(buf)); + tfp_sprintf(buf2, "+CODE: %s%c", buf, '\0'); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf2)) / 2, armScreenRow++, buf2); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); + } else { + osdFormatCoordinate(buf, SYM_LAT, GPS_home.lat); + osdFormatCoordinate(buf2, SYM_LON, GPS_home.lon); + + uint8_t gpsStartCol = (osdDisplayPort->cols - (strlen(buf) + strlen(buf2) + 2)) / 2; + displayWrite(osdDisplayPort, gpsStartCol, armScreenRow, buf); + displayWrite(osdDisplayPort, gpsStartCol + strlen(buf) + 2, armScreenRow++, buf2); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); + } } #if defined (USE_SAFE_HOME) @@ -5276,11 +5331,14 @@ static void osdShowSDArmScreen(void) textAttributes_t elemAttr = _TEXT_ATTRIBUTES_BLINK_BIT; // write this message below the ARMED message to make it obvious displayWriteWithAttr(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, safehomeRow, buf, elemAttr); + memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); } #endif } else { strcpy(buf, "!NO HOME POSITION!"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); } armScreenRow++; } @@ -5289,6 +5347,7 @@ static void osdShowSDArmScreen(void) if (rtcGetDateTimeLocal(&dt)) { tfp_sprintf(buf, "%04u-%02u-%02u %02u:%02u:%02u", dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); armScreenRow++; } From 4d9e9d318ed069f5fe6bcbb6e98fa16593a1c0b9 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Tue, 23 Apr 2024 22:09:13 +0100 Subject: [PATCH 2/4] Fix element detection and tidy up --- src/main/io/osd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index eb99ef917e9..da8cde972c0 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1715,11 +1715,11 @@ void osdDisplaySwitchIndicator(const char *swName, int rcValue, char *buff) { static bool osdElementEnabled(uint8_t elementID, bool onlyCurrentLayout) { bool elementEnabled = false; - if (onlyCurrentLayout) - elementEnabled = (osdLayoutsConfig()->item_pos[currentLayout][elementID]) ? true : false; - else { - for (uint8_t layout = 0; layout < 4 || elementEnabled; layout++) { - elementEnabled = (osdLayoutsConfig()->item_pos[layout][elementID]) ? true : false; + if (onlyCurrentLayout) { + elementEnabled = OSD_VISIBLE(osdLayoutsConfig()->item_pos[currentLayout][elementID]); + } else { + for (uint8_t layout = 0; layout < 4 && !elementEnabled; layout++) { + elementEnabled = OSD_VISIBLE(osdLayoutsConfig()->item_pos[layout][elementID]); } } @@ -5141,25 +5141,30 @@ static void osdShowHDArmScreen(void) armScreenRow = drawLogos(false, armScreenRow); armScreenRow++; + if (!osdConfig()->use_pilot_logo && osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) + osdFormatPilotName(buf2); + if (osdElementEnabled(OSD_CRAFT_NAME, false) && strlen(systemConfig()->craftName) > 0) { osdFormatCraftName(craftNameBuf); - strcat(buf2, ": ! ARMED !"); - tfp_sprintf(buf, "%s - %s", craftNameBuf, buf2); + if (strlen(buf2) > 0) { + strcat(buf2, " : "); + } + tfp_sprintf(buf, "%s%s: ! ARMED !", buf2, craftNameBuf); } else { strcpy(buf, " ! ARMED !"); } displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf2)); #if defined(USE_GPS) #if defined (USE_SAFE_HOME) if (posControl.safehomeState.distance) { safehomeRow = armScreenRow; - armScreenRow++; + armScreenRow +=2; } #endif // USE_SAFE_HOME #endif // USE_GPS - armScreenRow++; if (posControl.waypointListValid && posControl.waypointCount > 0) { #ifdef USE_MULTI_MISSION @@ -5177,6 +5182,7 @@ static void osdShowHDArmScreen(void) if (feature(FEATURE_GPS)) { if (STATE(GPS_FIX_HOME)) { if (osdConfig()->osd_home_position_arm_screen) { + // Show pluscode if enabled on any OSD layout. Otherwise show GNSS cordinates. if (osdElementEnabled(OSD_PLUS_CODE, false)) { int digits = osdConfig()->plus_code_digits; olc_encode(GPS_home.lat, GPS_home.lon, digits, buf, sizeof(buf)); @@ -5224,7 +5230,6 @@ static void osdShowHDArmScreen(void) displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); } - armScreenRow++; } #endif @@ -5262,7 +5267,7 @@ static void osdShowSDArmScreen(void) #if defined (USE_SAFE_HOME) if (posControl.safehomeState.distance) { safehomeRow = armScreenRow; - armScreenRow++; + armScreenRow += 2; } #endif #endif @@ -5282,6 +5287,7 @@ static void osdShowSDArmScreen(void) if (strlen(buf2) > 0) { displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf2)) / 2, armScreenRow++, buf2 ); memset(buf2, '\0', sizeof(buf2)); + armScreenRow++; } if (posControl.waypointListValid && posControl.waypointCount > 0) { @@ -5340,7 +5346,6 @@ static void osdShowSDArmScreen(void) displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); } - armScreenRow++; } #endif From de09caecfd5d5b08ec27997480f75178ccfed45d Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Wed, 15 May 2024 08:07:47 +0100 Subject: [PATCH 3/4] Add blank line after "no home position" --- src/main/io/osd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index da8cde972c0..6e3948f61aa 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -5229,6 +5229,7 @@ static void osdShowHDArmScreen(void) strcpy(buf, "!NO HOME POSITION!"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); + armScreenRow++; } } #endif @@ -5345,6 +5346,7 @@ static void osdShowSDArmScreen(void) strcpy(buf, "!NO HOME POSITION!"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); + armScreenRow++; } } #endif From 746c168deec2790cc4f164d7e00d02b62d4ab815 Mon Sep 17 00:00:00 2001 From: Darren Lines Date: Tue, 13 Aug 2024 12:14:30 +0300 Subject: [PATCH 4/4] Updates - Updated draw for pilot/craft name - Removed blink from safehome, because it looked bad --- src/main/io/osd.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index e9ac5dd78da..bb44cbf581b 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -5193,26 +5193,35 @@ static void osdShowHDArmScreen(void) dateTime_t dt; char buf[MAX(osdDisplayPort->cols, FORMATTED_DATE_TIME_BUFSIZE)]; char buf2[MAX(osdDisplayPort->cols, FORMATTED_DATE_TIME_BUFSIZE)]; - char craftNameBuf[MAX_NAME_LENGTH]; + char craftNameBuf[MAX_NAME_LENGTH]; char versionBuf[osdDisplayPort->cols]; uint8_t safehomeRow = 0; uint8_t armScreenRow = 1; + bool showPilotOrCraftName = false; + armScreenRow = drawLogos(false, armScreenRow); armScreenRow++; - if (!osdConfig()->use_pilot_logo && osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) + if (!osdConfig()->use_pilot_logo && osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) { osdFormatPilotName(buf2); + showPilotOrCraftName = true; + } if (osdElementEnabled(OSD_CRAFT_NAME, false) && strlen(systemConfig()->craftName) > 0) { osdFormatCraftName(craftNameBuf); if (strlen(buf2) > 0) { strcat(buf2, " : "); } + showPilotOrCraftName = true; + } + + if (showPilotOrCraftName) { tfp_sprintf(buf, "%s%s: ! ARMED !", buf2, craftNameBuf); } else { strcpy(buf, " ! ARMED !"); } + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); memset(buf, '\0', sizeof(buf)); memset(buf2, '\0', sizeof(buf2)); @@ -5320,6 +5329,7 @@ static void osdShowSDArmScreen(void) char versionBuf[osdDisplayPort->cols]; uint8_t armScreenRow = 1; uint8_t safehomeRow = 0; + bool showPilotOrCraftName = false; strcpy(buf, "! ARMED !"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); @@ -5333,20 +5343,23 @@ static void osdShowSDArmScreen(void) #endif #endif - if (osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) + if (osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) { osdFormatPilotName(buf2); + showPilotOrCraftName = true; + } if (osdElementEnabled(OSD_CRAFT_NAME, false) && strlen(systemConfig()->craftName) > 0) { osdFormatCraftName(craftNameBuf); if (strlen(buf2) > 0) { - strcat(buf2, ": "); - strcat(buf2, craftNameBuf); - } else - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(craftNameBuf)) / 2, armScreenRow++, craftNameBuf ); + strcat(buf2, " : "); + } + showPilotOrCraftName = true; } - if (strlen(buf2) > 0) { - displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf2)) / 2, armScreenRow++, buf2 ); + if (showPilotOrCraftName) { + tfp_sprintf(buf, "%s%s", buf2, craftNameBuf); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf ); + memset(buf, '\0', sizeof(buf)); memset(buf2, '\0', sizeof(buf2)); armScreenRow++; } @@ -5395,9 +5408,8 @@ static void osdShowSDArmScreen(void) osdFormatDistanceStr(buf2, posControl.safehomeState.distance); tfp_sprintf(buf, "%c SAFEHOME %u @ %s", SYM_HOME, posControl.safehomeState.index, buf2); } - textAttributes_t elemAttr = _TEXT_ATTRIBUTES_BLINK_BIT; // write this message below the ARMED message to make it obvious - displayWriteWithAttr(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, safehomeRow, buf, elemAttr); + displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, safehomeRow, buf); memset(buf, '\0', sizeof(buf)); memset(buf2, '\0', sizeof(buf2)); }