Skip to content

Commit

Permalink
Merge pull request #10300 from iNavFlight/MrD_update-arming-screen-fo…
Browse files Browse the repository at this point in the history
…r-better-space-utilisation

Update arming screen for better space utilisation
  • Loading branch information
MrD-RC authored Oct 24, 2024
2 parents 6e4e7b5 + 7ef094a commit a7854b3
Showing 1 changed file with 128 additions and 50 deletions.
178 changes: 128 additions & 50 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand All @@ -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++;
}

Expand All @@ -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)
Expand All @@ -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++;
}

Expand Down

0 comments on commit a7854b3

Please sign in to comment.