1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP GCS/HID - Added functions to allow already connected devices to trigger the signals.

For this to work, signals have to be subscribed before calling "setUpNotifications()".

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2921 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2011-02-28 21:01:02 +00:00 committed by zedamota
parent 4eec350318
commit 53e18382b3
2 changed files with 30 additions and 3 deletions

View File

@ -128,7 +128,7 @@ class RAWHID_EXPORT pjrc_rawhid: public QObject
#ifdef Q_OS_WIN
public:
LRESULT onDeviceChangeWin( WPARAM wParam, LPARAM lParam );
static QList<USBPortInfo> getPorts();//should exhist for every plattform
private:
/*!
* Get specific property from registry.
@ -143,6 +143,7 @@ private:
static bool getDeviceDetailsWin( USBPortInfo* portInfo, HDEVINFO devInfo,
PSP_DEVINFO_DATA devData, WPARAM wParam = DBT_DEVICEARRIVAL );
static void enumerateDevicesWin( const GUID & guidDev, QList<USBPortInfo>* infoList );
bool matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam);
#ifdef QT_GUI_LIB
USBRegistrationWidget* notificationWidget;

View File

@ -45,7 +45,7 @@
pjrc_rawhid::pjrc_rawhid()
{
if( !QMetaType::isRegistered( QMetaType::type("USVPortInfo") ) )
if( !QMetaType::isRegistered( QMetaType::type("USBPortInfo") ) )
qRegisterMetaType<USBPortInfo>("USBPortInfo");
#if (defined QT_GUI_LIB)
notificationWidget = 0;
@ -519,6 +519,8 @@ void pjrc_rawhid::setUpNotifications( )
qWarning() << "RegisterDeviceNotification failed:" << GetLastError();
// setting up notifications doesn't tell us about devices already connected
// so get those manually
foreach( USBPortInfo port, getPorts() )
emit deviceDiscovered( port );
#else
qWarning("GUI not enabled - can't register for device notifications.");
#endif // QT_GUI_LIB
@ -567,7 +569,7 @@ bool pjrc_rawhid::matchAndDispatchChangedDevice(const QString & deviceID, const
{
rv = true;
USBPortInfo info;
//info.productID = info.vendorID = 0;
info.productID = info.vendorID = 0;
getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
if( wParam == DBT_DEVICEARRIVAL )
emit deviceDiscovered(info);
@ -594,6 +596,7 @@ bool pjrc_rawhid::getDeviceDetailsWin( USBPortInfo* portInfo, HDEVINFO devInfo,
portInfo->vendorID = idRx.cap(1).toInt(&dummy, 16);
portInfo->productID = idRx.cap(2).toInt(&dummy, 16);
}
qDebug()<<portInfo->productID;
return true;
}
QString pjrc_rawhid::getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property)
@ -606,3 +609,26 @@ QString pjrc_rawhid::getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devDat
delete [] buff;
return result;
}
QList<USBPortInfo> pjrc_rawhid::getPorts()
{
QList<USBPortInfo> ports;
enumerateDevicesWin(GUID_DEVCLASS_PORTS, &ports);
return ports;
}
void pjrc_rawhid::enumerateDevicesWin( const GUID & guid, QList<USBPortInfo>* infoList )
{
HDEVINFO devInfo;
if( (devInfo = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT)) != INVALID_HANDLE_VALUE)
{
SP_DEVINFO_DATA devInfoData;
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for(int i = 0; SetupDiEnumDeviceInfo(devInfo, i, &devInfoData); i++)
{
USBPortInfo info;
info.productID = info.vendorID = 0;
getDeviceDetailsWin( &info, devInfo, &devInfoData );
infoList->append(info);
}
SetupDiDestroyDeviceInfoList(devInfo);
}
}