From 660e6434ad20776aef06d4d3627f4a8fb06a99ef Mon Sep 17 00:00:00 2001 From: noorus Date: Tue, 4 Feb 2014 15:27:55 +0200 Subject: [PATCH] Added some USB vendor identification --- include/nilHID.h | 12 ++++++++++++ src/Device.cpp | 3 +++ src/HIDRecord.cpp | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/nilHID.h b/include/nilHID.h index 433241d..13394a8 100644 --- a/include/nilHID.h +++ b/include/nilHID.h @@ -10,6 +10,14 @@ extern "C" { namespace nil { + //! Known USB vendor IDs that might be important. + enum USBKnownVendor: uint16_t { + USBVendor_Microsoft = 0x045E, + USBVendor_Logitech = 0x046D + }; + + //! \class HIDRecord + //! A Human Interface Device instance currently present in the system. class HIDRecord { protected: String mPath; @@ -25,6 +33,8 @@ namespace nil { public: HIDRecord( const String& path, HANDLE handle ); bool isXInput() const; + bool isMicrosoft() const; + bool isLogitech() const; const String& getPath() const; const String& getName() const; const String& getManufacturer() const; @@ -37,6 +47,8 @@ namespace nil { typedef list HIDRecordList; + //! \class HIDManager + //! Manages a list of connected Human Interface Devices. class HIDManager: public PnPListener { protected: HIDRecordList mRecords; diff --git a/src/Device.cpp b/src/Device.cpp index 7181017..30c226c 100644 --- a/src/Device.cpp +++ b/src/Device.cpp @@ -12,6 +12,9 @@ namespace nil { void Device::create() { + if ( mInstance ) + return; + if ( getHandler() == Handler_XInput ) { XInputDevice* xDevice = dynamic_cast( this ); diff --git a/src/HIDRecord.cpp b/src/HIDRecord.cpp index 8e2f489..88fbea6 100644 --- a/src/HIDRecord.cpp +++ b/src/HIDRecord.cpp @@ -47,6 +47,16 @@ namespace nil { return mIsXInput; } + bool HIDRecord::isMicrosoft() const + { + return ( mVendorID == USBVendor_Microsoft ); + } + + bool HIDRecord::isLogitech() const + { + return ( mVendorID == USBVendor_Logitech ); + } + uint32_t HIDRecord::getIdentifier() const { return mIdentifier;