diff --git a/src/main/io/osd.c b/src/main/io/osd.c index cdda88521b2..835dcd529ae 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -1644,6 +1644,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 = 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]); + } + } + + return elementEnabled; +} + static bool osdDrawSingleElement(uint8_t item) { uint16_t pos = osdLayoutsConfig()->item_pos[currentLayout][item]; @@ -5203,65 +5217,90 @@ 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 = 2; // Start at row 2 + uint8_t armScreenRow = 1; + + bool showPilotOrCraftName = false; armScreenRow = drawLogos(false, armScreenRow); armScreenRow++; - if (strlen(systemConfig()->craftName) > 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); - strcpy(buf2, "ARMED!"); - tfp_sprintf(buf, "%s - %s", craftNameBuf, buf2); + if (strlen(buf2) > 0) { + strcat(buf2, " : "); + } + showPilotOrCraftName = true; + } + + if (showPilotOrCraftName) { + tfp_sprintf(buf, "%s%s: ! ARMED !", buf2, craftNameBuf); } else { - strcpy(buf, "ARMED!"); + 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 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) { + // 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 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) @@ -5275,19 +5314,23 @@ 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++; } - armScreenRow++; } #endif 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++; } @@ -5308,45 +5351,77 @@ 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; + bool showPilotOrCraftName = false; - 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 += 2; + } +#endif +#endif + + if (osdElementEnabled(OSD_PILOT_NAME, false) && strlen(systemConfig()->pilotName) > 0) { + osdFormatPilotName(buf2); + showPilotOrCraftName = true; + } - 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, " : "); + } + showPilotOrCraftName = true; + } + + 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++; } 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) @@ -5357,22 +5432,25 @@ 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)); } #endif } else { strcpy(buf, "!NO HOME POSITION!"); displayWrite(osdDisplayPort, (osdDisplayPort->cols - strlen(buf)) / 2, armScreenRow++, buf); + memset(buf, '\0', sizeof(buf)); + armScreenRow++; } - armScreenRow++; } #endif 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++; }