diff --git a/src/main/cms/cms.c b/src/main/cms/cms.c index de8395e9e..0669c1512 100644 --- a/src/main/cms/cms.c +++ b/src/main/cms/cms.c @@ -61,22 +61,16 @@ #include "flight/mixer.h" #include "io/rcdevice_cam.h" +#include "io/usb_cdc_hid.h" #include "pg/pg.h" #include "pg/pg_ids.h" #include "pg/rx.h" -#ifdef USE_USB_CDC_HID -#include "pg/usb.h" -#endif #include "osd/osd.h" #include "rx/rx.h" -#ifdef USE_USB_CDC_HID -#include "sensors/battery.h" -#endif - // DisplayPort management #ifndef CMS_MAX_DEVICE @@ -1202,7 +1196,7 @@ static void cmsUpdate(uint32_t currentTimeUs) || rcdeviceInMenu #endif #ifdef USE_USB_CDC_HID - || (getBatteryCellCount() == 0 && usbDevConfig()->type == COMPOSITE) + || cdcDeviceIsMayBeActive() // If this target is used as a joystick, we should leave here. #endif ) { return; diff --git a/src/main/fc/rc_controls.c b/src/main/fc/rc_controls.c index 867881288..beeab54cb 100644 --- a/src/main/fc/rc_controls.c +++ b/src/main/fc/rc_controls.c @@ -46,6 +46,7 @@ #include "flight/failsafe.h" #include "io/beeper.h" +#include "io/usb_cdc_hid.h" #include "io/dashboard.h" #include "io/gps.h" #include "io/vtx_control.h" @@ -228,6 +229,13 @@ void processRcStickPositions() } doNotRepeat = true; + #ifdef USE_USB_CDC_HID + // If this target is used as a joystick, we should leave here. + if (cdcDeviceIsMayBeActive()) { + return; + } + #endif + // actions during not armed if (rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) { diff --git a/src/main/io/usb_cdc_hid.c b/src/main/io/usb_cdc_hid.c index 96b86fb7b..99a5233be 100644 --- a/src/main/io/usb_cdc_hid.c +++ b/src/main/io/usb_cdc_hid.c @@ -18,6 +18,9 @@ * If not, see . */ + +#include + #include "platform.h" #ifdef USE_USB_CDC_HID @@ -28,6 +31,10 @@ #include "rx/rx.h" +#include "pg/usb.h" + +#include "sensors/battery.h" + //TODO: Make it platform independent in the future #if defined(STM32F4) #include "vcpf4/usbd_cdc_vcp.h" @@ -75,4 +82,9 @@ void sendRcDataToHid(void) # error "MCU does not support USB HID." #endif } + +bool cdcDeviceIsMayBeActive() +{ + return usbDevConfig()->type == COMPOSITE && usbIsConnected() && (getBatteryState() == BATTERY_NOT_PRESENT || batteryConfig()->voltageMeterSource == VOLTAGE_METER_NONE); +} #endif diff --git a/src/main/io/usb_cdc_hid.h b/src/main/io/usb_cdc_hid.h index ff0b53886..38261701a 100644 --- a/src/main/io/usb_cdc_hid.h +++ b/src/main/io/usb_cdc_hid.h @@ -21,3 +21,4 @@ #pragma once void sendRcDataToHid(void); +bool cdcDeviceIsMayBeActive();