mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-01 18:29:16 +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:
parent
4eec350318
commit
53e18382b3
@ -128,7 +128,7 @@ class RAWHID_EXPORT pjrc_rawhid: public QObject
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
public:
|
public:
|
||||||
LRESULT onDeviceChangeWin( WPARAM wParam, LPARAM lParam );
|
LRESULT onDeviceChangeWin( WPARAM wParam, LPARAM lParam );
|
||||||
|
static QList<USBPortInfo> getPorts();//should exhist for every plattform
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
* Get specific property from registry.
|
* Get specific property from registry.
|
||||||
@ -143,6 +143,7 @@ private:
|
|||||||
|
|
||||||
static bool getDeviceDetailsWin( USBPortInfo* portInfo, HDEVINFO devInfo,
|
static bool getDeviceDetailsWin( USBPortInfo* portInfo, HDEVINFO devInfo,
|
||||||
PSP_DEVINFO_DATA devData, WPARAM wParam = DBT_DEVICEARRIVAL );
|
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);
|
bool matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam);
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
USBRegistrationWidget* notificationWidget;
|
USBRegistrationWidget* notificationWidget;
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
pjrc_rawhid::pjrc_rawhid()
|
pjrc_rawhid::pjrc_rawhid()
|
||||||
{
|
{
|
||||||
if( !QMetaType::isRegistered( QMetaType::type("USVPortInfo") ) )
|
if( !QMetaType::isRegistered( QMetaType::type("USBPortInfo") ) )
|
||||||
qRegisterMetaType<USBPortInfo>("USBPortInfo");
|
qRegisterMetaType<USBPortInfo>("USBPortInfo");
|
||||||
#if (defined QT_GUI_LIB)
|
#if (defined QT_GUI_LIB)
|
||||||
notificationWidget = 0;
|
notificationWidget = 0;
|
||||||
@ -519,6 +519,8 @@ void pjrc_rawhid::setUpNotifications( )
|
|||||||
qWarning() << "RegisterDeviceNotification failed:" << GetLastError();
|
qWarning() << "RegisterDeviceNotification failed:" << GetLastError();
|
||||||
// setting up notifications doesn't tell us about devices already connected
|
// setting up notifications doesn't tell us about devices already connected
|
||||||
// so get those manually
|
// so get those manually
|
||||||
|
foreach( USBPortInfo port, getPorts() )
|
||||||
|
emit deviceDiscovered( port );
|
||||||
#else
|
#else
|
||||||
qWarning("GUI not enabled - can't register for device notifications.");
|
qWarning("GUI not enabled - can't register for device notifications.");
|
||||||
#endif // QT_GUI_LIB
|
#endif // QT_GUI_LIB
|
||||||
@ -567,7 +569,7 @@ bool pjrc_rawhid::matchAndDispatchChangedDevice(const QString & deviceID, const
|
|||||||
{
|
{
|
||||||
rv = true;
|
rv = true;
|
||||||
USBPortInfo info;
|
USBPortInfo info;
|
||||||
//info.productID = info.vendorID = 0;
|
info.productID = info.vendorID = 0;
|
||||||
getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
|
getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
|
||||||
if( wParam == DBT_DEVICEARRIVAL )
|
if( wParam == DBT_DEVICEARRIVAL )
|
||||||
emit deviceDiscovered(info);
|
emit deviceDiscovered(info);
|
||||||
@ -594,6 +596,7 @@ bool pjrc_rawhid::getDeviceDetailsWin( USBPortInfo* portInfo, HDEVINFO devInfo,
|
|||||||
portInfo->vendorID = idRx.cap(1).toInt(&dummy, 16);
|
portInfo->vendorID = idRx.cap(1).toInt(&dummy, 16);
|
||||||
portInfo->productID = idRx.cap(2).toInt(&dummy, 16);
|
portInfo->productID = idRx.cap(2).toInt(&dummy, 16);
|
||||||
}
|
}
|
||||||
|
qDebug()<<portInfo->productID;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QString pjrc_rawhid::getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property)
|
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;
|
delete [] buff;
|
||||||
return result;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user