diff --git a/src/main/fc/core.c b/src/main/fc/core.c index 6da06df8e9..e7ad31794e 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -129,7 +129,7 @@ enum { int16_t magHold; #endif -static bool flipOverAfterCrashMode = false; +static bool flipOverAfterCrashActive = false; static timeUs_t disarmAt; // Time of automatic disarm when "Don't spin the motors when armed" is enabled and auto_disarm_delay is nonzero @@ -216,7 +216,7 @@ void updateArmingStatus(void) } // Clear the crash flip active status - flipOverAfterCrashMode = false; + flipOverAfterCrashActive = false; // If switch is used for arming then check it is not defaulting to on when the RX link recovers from a fault if (!isUsingSticksForArming()) { @@ -339,11 +339,11 @@ void disarm(void) #endif BEEP_OFF; #ifdef USE_DSHOT - if (isMotorProtocolDshot() && flipOverAfterCrashMode && !featureIsEnabled(FEATURE_3D)) { + if (isMotorProtocolDshot() && flipOverAfterCrashActive && !featureIsEnabled(FEATURE_3D)) { pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, false); } #endif - flipOverAfterCrashMode = false; + flipOverAfterCrashActive = false; // if ARMING_DISABLED_RUNAWAY_TAKEOFF is set then we want to play it's beep pattern instead if (!(getArmingDisableFlags() & ARMING_DISABLED_RUNAWAY_TAKEOFF)) { @@ -370,7 +370,7 @@ void tryArm(void) #ifdef USE_DSHOT if (currentTimeUs - getLastDshotBeaconCommandTimeUs() < DSHOT_BEACON_GUARD_DELAY_US) { if (tryingToArm == ARMING_DELAYED_DISARMED) { - if (isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH) && IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) { + if (IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) { tryingToArm = ARMING_DELAYED_CRASHFLIP; #ifdef USE_LAUNCH_CONTROL } else if (canUseLaunchControl()) { @@ -384,12 +384,12 @@ void tryArm(void) } if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) { if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) { - flipOverAfterCrashMode = false; + flipOverAfterCrashActive = false; if (!featureIsEnabled(FEATURE_3D)) { pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, false); } } else { - flipOverAfterCrashMode = true; + flipOverAfterCrashActive = true; #ifdef USE_RUNAWAY_TAKEOFF runawayTakeoffCheckDisabled = false; #endif @@ -401,7 +401,7 @@ void tryArm(void) #endif #ifdef USE_LAUNCH_CONTROL - if (!flipOverAfterCrashMode && (canUseLaunchControl() || (tryingToArm == ARMING_DELAYED_LAUNCH_CONTROL))) { + if (!flipOverAfterCrashActive && (canUseLaunchControl() || (tryingToArm == ARMING_DELAYED_LAUNCH_CONTROL))) { if (launchControlState == LAUNCH_CONTROL_DISABLED) { // only activate if it hasn't already been triggered launchControlState = LAUNCH_CONTROL_ACTIVE; } @@ -648,7 +648,7 @@ bool processRx(timeUs_t currentTimeUs) if (ARMING_FLAG(ARMED) && pidConfig()->runaway_takeoff_prevention && !runawayTakeoffCheckDisabled - && !flipOverAfterCrashMode + && !flipOverAfterCrashActive && !runawayTakeoffTemporarilyDisabled && !STATE(FIXED_WING)) { @@ -784,7 +784,7 @@ bool processRx(timeUs_t currentTimeUs) #ifdef USE_DSHOT /* Enable beep warning when the crash flip mode is active */ - if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH) && IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) { + if (flipOverAfterCrashActive) { beeper(BEEPER_CRASH_FLIP_MODE); } #endif @@ -934,7 +934,7 @@ static FAST_CODE void subTaskPidController(timeUs_t currentTimeUs) && !STATE(FIXED_WING) && pidConfig()->runaway_takeoff_prevention && !runawayTakeoffCheckDisabled - && !flipOverAfterCrashMode + && !flipOverAfterCrashActive && !runawayTakeoffTemporarilyDisabled && (!featureIsEnabled(FEATURE_MOTOR_STOP) || airmodeIsEnabled() || (calculateThrottleStatus() != THROTTLE_LOW))) { @@ -1088,9 +1088,9 @@ FAST_CODE void taskMainPidLoop(timeUs_t currentTimeUs) } -bool isFlipOverAfterCrashMode(void) +bool isFlipOverAfterCrashActive(void) { - return flipOverAfterCrashMode; + return flipOverAfterCrashActive; } timeUs_t getLastDisarmTimeUs(void) diff --git a/src/main/fc/core.h b/src/main/fc/core.h index 28a7e9a347..6d3aa646f7 100644 --- a/src/main/fc/core.h +++ b/src/main/fc/core.h @@ -66,7 +66,8 @@ bool processRx(timeUs_t currentTimeUs); void updateArmingStatus(void); void taskMainPidLoop(timeUs_t currentTimeUs); -bool isFlipOverAfterCrashMode(void); + +bool isFlipOverAfterCrashActive(void); void runawayTakeoffTemporaryDisable(uint8_t disableFlag); bool isAirmodeActivated(); diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index b84d142239..df2fae9b71 100644 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -798,7 +798,7 @@ void updateDynLpfCutoffs(timeUs_t currentTimeUs, float throttle) FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensation) { - if (isFlipOverAfterCrashMode()) { + if (isFlipOverAfterCrashActive()) { applyFlipOverAfterCrashModeToMotors(); return; } diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index a7b28b36c7..0dd4d2ec9d 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -47,6 +47,7 @@ #include "drivers/vtx_common.h" #include "fc/config.h" +#include "fc/core.h" #include "fc/rc_controls.h" #include "fc/rc_modes.h" #include "fc/runtime_config.h" @@ -522,6 +523,7 @@ typedef enum { WARNING_ARMING_DISABLED, WARNING_LOW_BATTERY, WARNING_FAILSAFE, + WARNING_CRASH_FLIP_ACTIVE, } warningFlags_e; static void applyLedWarningLayer(bool updateNow, timeUs_t *timer) @@ -536,12 +538,18 @@ static void applyLedWarningLayer(bool updateNow, timeUs_t *timer) if (warningFlashCounter == 0) { // update when old flags was processed warningFlags = 0; - if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE && getBatteryState() != BATTERY_OK) + if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE && getBatteryState() != BATTERY_OK) { warningFlags |= 1 << WARNING_LOW_BATTERY; - if (failsafeIsActive()) + } + if (failsafeIsActive()) { warningFlags |= 1 << WARNING_FAILSAFE; - if (!ARMING_FLAG(ARMED) && isArmingDisabled()) + } + if (!ARMING_FLAG(ARMED) && isArmingDisabled()) { warningFlags |= 1 << WARNING_ARMING_DISABLED; + } + if (isFlipOverAfterCrashActive()) { + warningFlags |= 1 << WARNING_CRASH_FLIP_ACTIVE; + } } *timer += HZ_TO_US(10); } @@ -554,10 +562,13 @@ static void applyLedWarningLayer(bool updateNow, timeUs_t *timer) if (warningFlags & (1 << warningId)) { switch (warningId) { case WARNING_ARMING_DISABLED: - warningColor = colorOn ? &HSV(GREEN) : &HSV(BLACK); + warningColor = colorOn ? &HSV(GREEN) : &HSV(BLACK); + break; + case WARNING_CRASH_FLIP_ACTIVE: + warningColor = colorOn ? &HSV(MAGENTA) : &HSV(BLACK); break; case WARNING_LOW_BATTERY: - warningColor = colorOn ? &HSV(RED) : &HSV(BLACK); + warningColor = colorOn ? &HSV(RED) : &HSV(BLACK); break; case WARNING_FAILSAFE: warningColor = colorOn ? &HSV(YELLOW) : &HSV(BLUE); diff --git a/src/main/io/osd.c b/src/main/io/osd.c index b8d420f311..7e57f72680 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -483,7 +483,7 @@ static bool osdDrawSingleElement(uint8_t item) { const int angleR = attitude.values.roll / 10; const int angleP = attitude.values.pitch / 10; // still gotta update all angleR and angleP pointers. - if (IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH)) { + if (isFlipOverAfterCrashActive()) { if (angleP > 0 && ((angleR > 175 && angleR < 180) || (angleR > -180 && angleR < -175))) { buff[0] = SYM_ARROW_SOUTH; } else if (angleP > 0 && angleR > 0 && angleR < 175) { @@ -946,7 +946,7 @@ static bool osdDrawSingleElement(uint8_t item) #endif // Warn when in flip over after crash mode - if (osdWarnGetState(OSD_WARNING_CRASH_FLIP) && isFlipOverAfterCrashMode()) { + if (osdWarnGetState(OSD_WARNING_CRASH_FLIP) && isFlipOverAfterCrashActive()) { osdFormatMessage(buff, OSD_FORMAT_MESSAGE_BUFFER_SIZE, "CRASH FLIP"); break; } diff --git a/src/test/unit/ledstrip_unittest.cc b/src/test/unit/ledstrip_unittest.cc index eb7594d441..3a0cd8d9c8 100644 --- a/src/test/unit/ledstrip_unittest.cc +++ b/src/test/unit/ledstrip_unittest.cc @@ -388,4 +388,6 @@ bool isArmingDisabled(void) { return false; } uint8_t getRssiPercent(void) { return 0; } +bool isFlipOverAfterCrashActive(void) { return false; } + } diff --git a/src/test/unit/osd_unittest.cc b/src/test/unit/osd_unittest.cc index 4b9e22d1df..f7e56280b4 100644 --- a/src/test/unit/osd_unittest.cc +++ b/src/test/unit/osd_unittest.cc @@ -1055,9 +1055,7 @@ extern "C" { uint16_t getCoreTemperatureCelsius(void) { return simulationCoreTemperature; } - bool isFlipOverAfterCrashMode(void) { - return false; - } + bool isFlipOverAfterCrashActive(void) { return false; } float pidItermAccelerator(void) { return 1.0; } uint8_t getMotorCount(void){ return 4; }