1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Fix MacOS halt issues by using the USBMonitor to detect device re-insertion:wq:

This commit is contained in:
Edouard Lafargue 2011-09-25 15:26:12 +02:00
parent bcf200bc4f
commit 822cbfbc81
4 changed files with 23 additions and 24 deletions

View File

@ -117,7 +117,7 @@ void USBMonitor::removeDevice(IOHIDDeviceRef dev) {
*/
void USBMonitor::detach_callback(void *context, IOReturn r, void *hid_mgr, IOHIDDeviceRef dev)
{
qDebug() << "USBMonitor: Device detached event";
instance()->removeDevice(dev);
}
@ -136,6 +136,8 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID
deviceInfo.dev_handle = dev;
qDebug() << "USBMonitor: Device attached event";
// Populate the device info structure
got_properties &= HID_GetIntProperty(dev, CFSTR( kIOHIDVendorIDKey ), &deviceInfo.vendorID);
got_properties &= HID_GetIntProperty(dev, CFSTR( kIOHIDProductIDKey ), &deviceInfo.productID);
@ -149,6 +151,7 @@ void USBMonitor::attach_callback(void *context, IOReturn r, void *hid_mgr, IOHID
// Currently only enumerating objects that have the complete list of properties
if(got_properties) {
qDebug() << "USBMonitor: Adding device";
instance()->addDevice(deviceInfo);
}
}

View File

@ -80,29 +80,26 @@ DFUObject::DFUObject(bool _debug,bool _use_serial,QString portname):
}
else
{
send_delay=10;
use_delay=true;
// int numDevices=0;
QList<USBPortInfo> devices;
int count=0;
while((devices.length()==0) && count < 10)
{
if (debug)
qDebug() << ".";
delay::msleep(500);
// processEvents enables XP to process the system
// plug/unplug events, otherwise it will not process
// those events before the end of the call!
QApplication::processEvents();
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
count++;
}
if (devices.length()==1) {
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
} else {
qDebug() << devices.length() << " device(s) detected, don't know what to do!";
mready = false;
}
// Wait for the board to appear on the USB bus:
QEventLoop m_eventloop;
connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&m_eventloop, SLOT(quit()));
QTimer::singleShot(5000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
delay::msleep(2000); // Let the USB Subsystem settle (especially important on Mac!)
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
}
else {
qDebug() << devices.length() << " device(s) detected, don't know what to do!";
mready = false;
}
}
}
}

View File

@ -17,6 +17,7 @@
#include "delay.h"
#include <qextserialport/src/qextserialport.h>
#include <QTime>
#include <QTimer>
#include "SSP/qssp.h"
#include "SSP/port.h"
#include "SSP/qsspt.h"

View File

@ -235,9 +235,7 @@ void UploaderGadgetWidget::goToBootloader(UAVObject* callerObj, bool success)
currentStep = IAP_STATE_BOOTLOADER;
// Tell the mainboard to get into bootloader state:
log("Detecting devices, please wait 5 seconds...");
this->repaint();
delay::msleep(5100); // Required to let the board(s) settle
log("Detecting devices, please wait a few seconds...");
if (!dfu) {
if (dlj.startsWith("USB"))
dfu = new DFUObject(DFU_DEBUG, false, QString());