From 53e18382b3bc45415bc9cb7ed4aac7c009403053 Mon Sep 17 00:00:00 2001 From: zedamota Date: Mon, 28 Feb 2011 21:01:02 +0000 Subject: [PATCH] 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 --- .../src/plugins/rawhid/pjrc_rawhid.h | 3 +- .../src/plugins/rawhid/pjrc_rawhid_win.cpp | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid.h b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid.h index 1f5896eb5..eda529246 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid.h +++ b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid.h @@ -128,7 +128,7 @@ class RAWHID_EXPORT pjrc_rawhid: public QObject #ifdef Q_OS_WIN public: LRESULT onDeviceChangeWin( WPARAM wParam, LPARAM lParam ); - + static QList 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* infoList ); bool matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam); #ifdef QT_GUI_LIB USBRegistrationWidget* notificationWidget; diff --git a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp index e09d6460d..d392fc468 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp @@ -45,7 +45,7 @@ pjrc_rawhid::pjrc_rawhid() { - if( !QMetaType::isRegistered( QMetaType::type("USVPortInfo") ) ) + if( !QMetaType::isRegistered( QMetaType::type("USBPortInfo") ) ) qRegisterMetaType("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()<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 pjrc_rawhid::getPorts() +{ + QList ports; + enumerateDevicesWin(GUID_DEVCLASS_PORTS, &ports); + return ports; +} +void pjrc_rawhid::enumerateDevicesWin( const GUID & guid, QList* 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); + } +}