From f4a9f9876fa2bb7803a838110580eae15ffb91ee Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 8 Jul 2015 11:19:07 +1000 Subject: [PATCH] HAL_PX4: make usb_connected() more robust thanks to a suggestion from Phillip Kocmoud, this should fix issues with the XUAV-X2 --- libraries/AP_HAL_PX4/GPIO.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_PX4/GPIO.cpp b/libraries/AP_HAL_PX4/GPIO.cpp index 3f8459c6fb..f956a97bee 100644 --- a/libraries/AP_HAL_PX4/GPIO.cpp +++ b/libraries/AP_HAL_PX4/GPIO.cpp @@ -242,7 +242,13 @@ bool PX4GPIO::attach_interrupt(uint8_t interrupt_num, AP_HAL::Proc p, uint8_t mo */ bool PX4GPIO::usb_connected(void) { - return stm32_gpioread(GPIO_OTGFS_VBUS); + struct stat st; + /* + we use a combination of voltage on the USB connector and the + existance of the /dev/ttyACM0 character device. This copes with + systems where the VBUS may go high even with no USB connected + */ + return stm32_gpioread(GPIO_OTGFS_VBUS) && stat("/dev/ttyACM0", &st) == 0; }