inc/HidDevice.h
author sl
Thu, 22 May 2014 08:45:14 +0200
changeset 16 21033ded8f86
parent 15 e5b84f315be7
child 17 63972dc16350
permissions -rw-r--r--
Adding vendor/product/serial number strings support to our HidDevice.
     1 //
     2 //
     3 //
     4 
     5 #ifndef HID_DEVICE_H
     6 #define HID_DEVICE_H
     7 
     8 #include "HidReport.h"
     9 #include "hidapi.h"
    10 
    11 const int KMaxHidStringChar=256;
    12 
    13 /**
    14 TODO: move to another header
    15 */
    16 class HidDevice
    17     {
    18 public:
    19     HidDevice();
    20     int Open(const char* aPath);
    21     int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
    22     void Close();
    23     bool IsOpen();
    24     //
    25     int SetNonBlocking(int aNonBlocking);
    26     //
    27     template<int S>
    28     int Write(const HidReport<S>& aOutputReport);
    29     //
    30     const wchar_t* Error();
    31     //
    32     wchar_t* Vendor();
    33     wchar_t* Product();
    34     wchar_t* SerialNumber();
    35 
    36 private:
    37     void FetchStrings();
    38 
    39 private:
    40     ///Our USB HID device
    41     hid_device* iHidDevice;
    42     //
    43     wchar_t iVendor[KMaxHidStringChar];
    44     wchar_t iProduct[KMaxHidStringChar];
    45     wchar_t iSerialNumber[KMaxHidStringChar];
    46     };
    47 
    48 
    49 /**
    50 */
    51 template<int S>
    52 int HidDevice::Write(const HidReport<S>& aOutputReport)
    53     {
    54     return hid_write(iHidDevice,aOutputReport.Buffer(),S);
    55     }
    56 
    57 
    58 #endif