From 843a25903a8625dc7e5d82eb65e8c09c9ddc574c Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 12 Jun 2018 20:04:06 -0400 Subject: [PATCH 1/2] Display OSD message and countdown if arming is delayed due to beacon Provides a clear indication that arming is delayed for cases where DSHOT beacon is active. Clears the OSD and displays "DISABLING BEACON" and "ARMING IN X.Y" with an active countdown in tenths of a second while arming is delayed due to DSHOT beacon. Once delay period is over the normal "ARMING" message appears. If the DSHOT beacon is not active then this delay screen is not displayed. --- src/main/io/osd.c | 31 ++++++++++++++++++++++++++++++- src/test/unit/osd_unittest.cc | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index c0829e2718..5339f031e2 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -202,6 +202,13 @@ static const uint8_t osdElementDisplayOrder[] = { PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 3); +static void osdDisplayCenteredMessage(int row, const char *message) +{ + const int messageLen = strlen(message); + const int col = (messageLen >= osdDisplayPort->cols) ? 0 : (osdDisplayPort->cols - strlen(message)) / 2; + displayWrite(osdDisplayPort, col, row, message); +} + /** * Gets the correct altitude symbol for the current unit system */ @@ -1390,9 +1397,24 @@ static void osdShowStats(uint16_t endBatteryVoltage) static void osdShowArmed(void) { displayClearScreen(osdDisplayPort); - displayWrite(osdDisplayPort, 12, 7, "ARMED"); + osdDisplayCenteredMessage(7, "ARMED"); } +#ifdef USE_DSHOT +static void osdShowTryingToArm(timeUs_t currentTimeUs) +{ + char buff[14]; + int delayTime = (getLastDshotBeaconCommandTimeUs() + DSHOT_BEACON_GUARD_DELAY_US - currentTimeUs) / 1e5; + if (delayTime < 0) { + delayTime = 0; + } + displayClearScreen(osdDisplayPort); + osdDisplayCenteredMessage(5, "DISABLING BEACON"); + tfp_sprintf(buff, "ARMING IN %d.%d", delayTime / 10, delayTime % 10); + osdDisplayCenteredMessage(7, buff); +} +#endif + STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) { static timeUs_t lastTimeUs = 0; @@ -1401,6 +1423,13 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) static timeUs_t osdStatsRefreshTimeUs; static uint16_t endBatteryVoltage; +#ifdef USE_DSHOT + if (isTryingToArm() && !ARMING_FLAG(ARMED)) { + osdShowTryingToArm(currentTimeUs); + return; + } +#endif + // detect arm/disarm if (armState != ARMING_FLAG(ARMED)) { if (ARMING_FLAG(ARMED)) { diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 353fddcc9d..28d076ac6e 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -45,6 +45,7 @@ extern "C" { #include "flight/pid.h" #include "flight/imu.h" + #include "io/beeper.h" #include "io/gps.h" #include "io/osd.h" From c15933fbd63c9bd05253f856dd89e83ac2b7f0b8 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Wed, 13 Jun 2018 12:05:10 -0400 Subject: [PATCH 2/2] Change beacon arming delayed message to use the warning message Uses the OSD_WARN element rather than a separate separate screen before arming. The "BEACON ON" message will appear for the first 0.5 seconds and then "AM IN x.y" will countdown for the remaining delay. Also fixed OSD_WARN element blinking related to battery warnings to only blink the warning element if the battery warnings are actually configured. --- src/main/io/osd.c | 62 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 5339f031e2..b178f44b03 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -202,13 +202,6 @@ static const uint8_t osdElementDisplayOrder[] = { PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 3); -static void osdDisplayCenteredMessage(int row, const char *message) -{ - const int messageLen = strlen(message); - const int col = (messageLen >= osdDisplayPort->cols) ? 0 : (osdDisplayPort->cols - strlen(message)) / 2; - displayWrite(osdDisplayPort, col, row, message); -} - /** * Gets the correct altitude symbol for the current unit system */ @@ -724,6 +717,23 @@ static bool osdDrawSingleElement(uint8_t item) const batteryState_e batteryState = getBatteryState(); +#ifdef USE_DSHOT + if (isTryingToArm() && !ARMING_FLAG(ARMED)) { + int armingDelayTime = (getLastDshotBeaconCommandTimeUs() + DSHOT_BEACON_GUARD_DELAY_US - micros()) / 1e5; + if (armingDelayTime < 0) { + armingDelayTime = 0; + } + if (armingDelayTime >= (DSHOT_BEACON_GUARD_DELAY_US / 1e5 - 5)) { + osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, " BEACON ON"); // Display this message for the first 0.5 seconds + } else { + char armingDelayMessage[OSD_FORMAT_MESSAGE_BUFFER_SIZE]; + tfp_sprintf(armingDelayMessage, "ARM IN %d.%d", armingDelayTime / 10, armingDelayTime % 10); + osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, armingDelayMessage); + } + break; + } +#endif + if (osdWarnGetState(OSD_WARNING_BATTERY_CRITICAL) && batteryState == BATTERY_CRITICAL) { osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, " LAND NOW"); break; @@ -1105,12 +1115,22 @@ void osdUpdateAlarms(void) CLR_BLINK(OSD_RSSI_VALUE); } - if (getBatteryState() == BATTERY_OK) { + // Determine if the OSD_WARNINGS should blink + if (getBatteryState() != BATTERY_OK + && (osdWarnGetState(OSD_WARNING_BATTERY_CRITICAL) || osdWarnGetState(OSD_WARNING_BATTERY_WARNING)) +#ifdef USE_DSHOT + && (!isTryingToArm()) +#endif + ) { + SET_BLINK(OSD_WARNINGS); + } else { CLR_BLINK(OSD_WARNINGS); + } + + if (getBatteryState() == BATTERY_OK) { CLR_BLINK(OSD_MAIN_BATT_VOLTAGE); CLR_BLINK(OSD_AVG_CELL_VOLTAGE); } else { - SET_BLINK(OSD_WARNINGS); SET_BLINK(OSD_MAIN_BATT_VOLTAGE); SET_BLINK(OSD_AVG_CELL_VOLTAGE); } @@ -1397,24 +1417,9 @@ static void osdShowStats(uint16_t endBatteryVoltage) static void osdShowArmed(void) { displayClearScreen(osdDisplayPort); - osdDisplayCenteredMessage(7, "ARMED"); + displayWrite(osdDisplayPort, 12, 7, "ARMED"); } -#ifdef USE_DSHOT -static void osdShowTryingToArm(timeUs_t currentTimeUs) -{ - char buff[14]; - int delayTime = (getLastDshotBeaconCommandTimeUs() + DSHOT_BEACON_GUARD_DELAY_US - currentTimeUs) / 1e5; - if (delayTime < 0) { - delayTime = 0; - } - displayClearScreen(osdDisplayPort); - osdDisplayCenteredMessage(5, "DISABLING BEACON"); - tfp_sprintf(buff, "ARMING IN %d.%d", delayTime / 10, delayTime % 10); - osdDisplayCenteredMessage(7, buff); -} -#endif - STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) { static timeUs_t lastTimeUs = 0; @@ -1423,13 +1428,6 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) static timeUs_t osdStatsRefreshTimeUs; static uint16_t endBatteryVoltage; -#ifdef USE_DSHOT - if (isTryingToArm() && !ARMING_FLAG(ARMED)) { - osdShowTryingToArm(currentTimeUs); - return; - } -#endif - // detect arm/disarm if (armState != ARMING_FLAG(ARMED)) { if (ARMING_FLAG(ARMED)) {