1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Some tweaks to detection and connection timings. Should fix some issues with "halt".

This commit is contained in:
zedamota 2011-11-26 00:06:45 +00:00
parent 77058807b4
commit 27de9fcb08
2 changed files with 28 additions and 7 deletions

View File

@ -28,7 +28,8 @@
#include <QMetaType>
#include <QString>
#include <initguid.h>
#include <QEventLoop>
#include <QTimer>
#include "usbmonitor.h"
#include <QDebug>
#define printf qDebug
@ -78,9 +79,9 @@ QList<USBPortInfo> USBMonitor::availableDevices(int vid, int pid, int bcdDeviceM
{
QList<USBPortInfo> allPorts = availableDevices();
QList<USBPortInfo> thePortsWeWant;
qDebug()<<"USBMonitor::availableDevices bcdLSB="<<bcdDeviceLSB;
foreach (USBPortInfo port, allPorts) {
//qDebug()<<"USBMonitorWin:Port VID="<<port.vendorID<<"PID="<<port.productID<<"bcddevice="<<port.bcdDevice;
qDebug()<<"USBMonitorWin:Port VID="<<port.vendorID<<"PID="<<port.productID<<"bcddevice="<<port.bcdDevice;
if((port.vendorID==vid || vid==-1) && (port.productID==pid || pid==-1) && ((port.bcdDevice>>8)==bcdDeviceMSB || bcdDeviceMSB==-1) &&
( (port.bcdDevice&0x00ff) ==bcdDeviceLSB || bcdDeviceLSB==-1))
thePortsWeWant.append(port);
@ -178,9 +179,23 @@ bool USBMonitor::matchAndDispatchChangedDevice(const QString & deviceID, const G
if( wParam == DBT_DEVICEARRIVAL )
{
qDebug()<<"INSERTION";
if(infoFromHandle(guid,info,devInfo,i)==0)
QEventLoop m_eventloop;
QTimer::singleShot(1000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
if(infoFromHandle(guid,info,devInfo,i)!=1)
{
qDebug()<<"USB_MONITOR infoFromHandle failed on matchAndDispatchChangedDevice";
break;
}
bool m_break=false;
foreach (USBPortInfo m_info, knowndevices) {
if(m_info.serialNumber==info.serialNumber && m_info.productID==info.productID)
m_break=true;
}
if(m_break)
break;
knowndevices.append(info);
qDebug()<<"USB_MONITOR emit device discovered on device:"<<info.product<<info.bcdDevice;
emit deviceDiscovered(info);
break;

View File

@ -80,20 +80,26 @@ DFUObject::DFUObject(bool _debug,bool _use_serial,QString portname):
}
else
{
QEventLoop m_eventloop;
QTimer::singleShot(200,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
QList<USBPortInfo> devices;
devices = USBMonitor::instance()->availableDevices(0x20a0,-1,-1,USBMonitor::Bootloader);
if (devices.length()==1) {
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
qDebug()<<"OP_DFU detected first time";
} else {
// 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()));
QTimer::singleShot(15000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&m_eventloop, SLOT(quit()));
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!)
QTimer::singleShot(1000,&m_eventloop, SLOT(quit()));
m_eventloop.exec();
hidHandle.open(1,devices.first().vendorID,devices.first().productID,0,0);
qDebug()<<"OP_DFU detected after delay";
}
else {
qDebug() << devices.length() << " device(s) detected, don't know what to do!";