From 8205bb74e33999fb14315dfc4a513018a105238a Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Sat, 6 Oct 2018 11:04:28 -0400 Subject: [PATCH] Increase priority of arming disabled OSD warnings and cycle through all Previously the OSD arming disabled warnings were given a low priority so other warnings like "LOW BATTERY" would obscure the arming arming disabled reason(s). Increased the piority so that arming disabled reasons will always be displayed. Also change the logic to cycle through all arming disable reasons rather than only show the first active flag. --- src/main/io/osd.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index a20e60c77..9ac454ad8 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -770,10 +770,47 @@ static bool osdDrawSingleElement(uint8_t item) STATIC_ASSERT(OSD_FORMAT_MESSAGE_BUFFER_SIZE <= sizeof(buff), osd_warnings_size_exceeds_buffer_size); const batteryState_e batteryState = getBatteryState(); + const timeUs_t currentTimeUs = micros(); + + static timeUs_t armingDisabledUpdateTimeUs; + static unsigned armingDisabledDisplayIndex; + + // Cycle through the arming disabled reasons + if (osdWarnGetState(OSD_WARNING_ARMING_DISABLE)) { + if (IS_RC_MODE_ACTIVE(BOXARM) && isArmingDisabled()) { + const armingDisableFlags_e armSwitchOnlyFlag = 1 << (ARMING_DISABLE_FLAGS_COUNT - 1); + armingDisableFlags_e flags = getArmingDisableFlags(); + + // Remove the ARMSWITCH flag unless it's the only one + if ((flags & armSwitchOnlyFlag) && (flags != armSwitchOnlyFlag)) { + flags -= armSwitchOnlyFlag; + } + + // Rotate to the next arming disabled reason after a 0.5 second time delay + // or if the current flag is no longer set + if ((currentTimeUs - armingDisabledUpdateTimeUs > 5e5) || !(flags & (1 << armingDisabledDisplayIndex))) { + if (armingDisabledUpdateTimeUs == 0) { + armingDisabledDisplayIndex = ARMING_DISABLE_FLAGS_COUNT - 1; + } + armingDisabledUpdateTimeUs = currentTimeUs; + + do { + if (++armingDisabledDisplayIndex >= ARMING_DISABLE_FLAGS_COUNT) { + armingDisabledDisplayIndex = 0; + } + } while (!(flags & (1 << armingDisabledDisplayIndex))); + } + + osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, armingDisableFlagNames[armingDisabledDisplayIndex]); + break; + } else { + armingDisabledUpdateTimeUs = 0; + } + } #ifdef USE_DSHOT if (isTryingToArm() && !ARMING_FLAG(ARMED)) { - int armingDelayTime = (getLastDshotBeaconCommandTimeUs() + DSHOT_BEACON_GUARD_DELAY_US - micros()) / 1e5; + int armingDelayTime = (getLastDshotBeaconCommandTimeUs() + DSHOT_BEACON_GUARD_DELAY_US - currentTimeUs) / 1e5; if (armingDelayTime < 0) { armingDelayTime = 0; } @@ -866,18 +903,6 @@ static bool osdDrawSingleElement(uint8_t item) break; } - // Show most severe reason for arming being disabled - if (osdWarnGetState(OSD_WARNING_ARMING_DISABLE) && IS_RC_MODE_ACTIVE(BOXARM) && isArmingDisabled()) { - const armingDisableFlags_e flags = getArmingDisableFlags(); - for (int i = 0; i < ARMING_DISABLE_FLAGS_COUNT; i++) { - if (flags & (1 << i)) { - osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, armingDisableFlagNames[i]); - break; - } - } - break; - } - if (osdWarnGetState(OSD_WARNING_BATTERY_WARNING) && batteryState == BATTERY_WARNING) { osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, "LOW BATTERY"); break; -- 2.11.4.GIT