From 086f78b6b885809968570c22b66b6e90e50ab215 Mon Sep 17 00:00:00 2001 From: edouard Date: Thu, 3 Mar 2011 21:00:37 +0000 Subject: [PATCH] OP-334 Progress on USB Monitor, compatible with both Win32 and Linux git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2954 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/rawhid/usbmonitor.h | 74 +++++++++++++++---- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/rawhid/usbmonitor.h b/ground/openpilotgcs/src/plugins/rawhid/usbmonitor.h index e740d3cfa..4bb7e8a3c 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/usbmonitor.h +++ b/ground/openpilotgcs/src/plugins/rawhid/usbmonitor.h @@ -32,8 +32,14 @@ #include -//TODO: temporary, will have to remove -#include "pjrc_rawhid.h" +struct USBPortInfo { + QString friendName; ///< Friendly name. + QString physName; + QString enumName; ///< It seems its the only one with meaning + QString serialNumber; // As a string as it can be anything, really... + int vendorID; ///< Vendor ID. + int productID; ///< Product ID +}; // Depending on the OS, we'll need different things: #if defined( Q_OS_MAC) @@ -46,27 +52,43 @@ #include #elif defined (Q_OS_WIN32) -//TODO + +#include +#include +#include +#include +#include #endif -/* -struct USBPortInfo { - QString friendName; ///< Friendly name. - QString physName; - QString enumName; ///< It seems its the only one with meaning - int vendorID; ///< Vendor ID. - int productID; ///< Product ID -}; -*/ +#ifdef Q_OS_WIN +#ifdef QT_GUI_LIB +#include +class USBMonitor; + +class USBRegistrationWidget : public QWidget +{ + Q_OBJECT +public: + USBRegistrationWidget( USBMonitor* qese ) { + this->qese = qese; + } + ~USBRegistrationWidget( ) {} + +protected: + USBMonitor* qese; + bool winEvent( MSG* message, long* result ); +}; +#endif +#endif + /** * A monitoring thread which will wait for device events. */ class USBMonitor : public QThread { - Q_OBJECT - + Q_OBJECT public: USBMonitor(QObject *parent = 0); @@ -74,7 +96,9 @@ public: ~USBMonitor(); QList availableDevices(); QList availableDevices(int vid, int pid, int bcdDevice); - + #if defined (Q_OS_WIN32) + LRESULT onDeviceChangeWin( WPARAM wParam, LPARAM lParam ); + #endif signals: /*! A new device has been connected to the system. @@ -113,7 +137,25 @@ private: QSocketNotifier *monitorNotifier; USBPortInfo makePortInfo(struct udev_device *dev); #elif defined (Q_OS_WIN32) - //TODO + void setUpNotifications(); + /*! + * Get specific property from registry. + * \param devInfo pointer to the device information set that contains the interface + * and its underlying device. Returned by SetupDiGetClassDevs() function. + * \param devData pointer to an SP_DEVINFO_DATA structure that defines the device instance. + * this is returned by SetupDiGetDeviceInterfaceDetail() function. + * \param property registry property. One of defined SPDRP_* constants. + * \return property string. + */ + static QString getDeviceProperty(HDEVINFO devInfo, PSP_DEVINFO_DATA devData, DWORD property); + + 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; +#endif #endif };