From 19ece685552ac49edd7bca0c87cf32ff9b4ebcd9 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 15 Sep 2020 12:51:19 -0400 Subject: [PATCH] Add box mode to disable stick commands Adds a `STICK COMMAND DISABLE SW` mode used to prevent inadvertant triggering of controls, calibrations, or settings changes. Useful for USB HID mode when using the flight controller as a joystick (and auto-detect doesn't work), in "team" or "relay" racing where multiple quads might be bound to the same transmitter, or just in general if the user wants prevent stick commands. Will also prevent stick arming when the mode is active (but not stick disarming). --- src/main/cms/cms.c | 2 +- src/main/fc/rc_controls.c | 4 ++-- src/main/fc/rc_modes.h | 1 + src/main/io/rcdevice_cam.c | 2 +- src/main/msp/msp_box.c | 3 +++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/cms/cms.c b/src/main/cms/cms.c index 0669c15127..f1c13ad0dd 100644 --- a/src/main/cms/cms.c +++ b/src/main/cms/cms.c @@ -1214,7 +1214,7 @@ static void cmsUpdate(uint32_t currentTimeUs) if (!cmsInMenu) { // Detect menu invocation - if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED)) { + if (IS_MID(THROTTLE) && IS_LO(YAW) && IS_HI(PITCH) && !ARMING_FLAG(ARMED) && !IS_RC_MODE_ACTIVE(BOXSTICKCOMMANDDISABLE)) { cmsMenuOpen(); rcDelayMs = BUTTON_PAUSE; // Tends to overshoot if BUTTON_TIME } diff --git a/src/main/fc/rc_controls.c b/src/main/fc/rc_controls.c index beeab54cb5..1001d4a456 100644 --- a/src/main/fc/rc_controls.c +++ b/src/main/fc/rc_controls.c @@ -205,7 +205,7 @@ void processRcStickPositions() } } return; - } else if (rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE) { + } else if (rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE && !IS_RC_MODE_ACTIVE(BOXSTICKCOMMANDDISABLE)) { // disable stick arming if STICK COMMAND DISABLE SW is active if (rcDelayMs >= ARM_DELAY_MS && !doNotRepeat) { doNotRepeat = true; if (!ARMING_FLAG(ARMED)) { @@ -231,7 +231,7 @@ void processRcStickPositions() #ifdef USE_USB_CDC_HID // If this target is used as a joystick, we should leave here. - if (cdcDeviceIsMayBeActive()) { + if (cdcDeviceIsMayBeActive() || IS_RC_MODE_ACTIVE(BOXSTICKCOMMANDDISABLE)) { return; } #endif diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index b8bb947ec9..5f2c972648 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -75,6 +75,7 @@ typedef enum { BOXVTXCONTROLDISABLE, BOXLAUNCHCONTROL, BOXMSPOVERRIDE, + BOXSTICKCOMMANDDISABLE, CHECKBOX_ITEM_COUNT } boxId_e; diff --git a/src/main/io/rcdevice_cam.c b/src/main/io/rcdevice_cam.c index 1bd2c6ea22..697fd223aa 100644 --- a/src/main/io/rcdevice_cam.c +++ b/src/main/io/rcdevice_cam.c @@ -236,7 +236,7 @@ static void rcdevice5KeySimulationProcess(timeUs_t currentTimeUs) } #endif - if (ARMING_FLAG(ARMED) || (getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) { + if (ARMING_FLAG(ARMED) || IS_RC_MODE_ACTIVE(BOXSTICKCOMMANDDISABLE) || (getArmingDisableFlags() & (ARMING_DISABLED_RUNAWAY_TAKEOFF | ARMING_DISABLED_CRASH_DETECTED))) { return; } diff --git a/src/main/msp/msp_box.c b/src/main/msp/msp_box.c index e5c98b8966..a4fb846a9b 100644 --- a/src/main/msp/msp_box.c +++ b/src/main/msp/msp_box.c @@ -98,6 +98,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT] = { { BOXVTXCONTROLDISABLE, "DISABLE VTX CONTROL", 48}, { BOXLAUNCHCONTROL, "LAUNCH CONTROL", 49 }, { BOXMSPOVERRIDE, "MSP OVERRIDE", 50}, + { BOXSTICKCOMMANDDISABLE, "STICK COMMAND DISABLE SW", 51} }; // mask of enabled IDs, calculated on startup based on enabled features. boxId_e is used as bit index @@ -330,6 +331,8 @@ void initActiveBoxIds(void) BME(BOXLAUNCHCONTROL); #endif + BME(BOXSTICKCOMMANDDISABLE); + #undef BME // check that all enabled IDs are in boxes array (check may be skipped when using findBoxById() functions) for (boxId_e boxId = 0; boxId < CHECKBOX_ITEM_COUNT; boxId++)