HidDevice.h
author StephaneLenclud
Sat, 07 Feb 2015 13:50:11 +0100
changeset 32 2c844ef1ff4b
parent 0 0f874d9e4130
child 35 638eb0763e20
permissions -rw-r--r--
MDM166AA: Improved icon APIs.
     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 	virtual ~HidDevice();
    21 	//
    22     int Open(const char* aPath);
    23     int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
    24     void Close();
    25     bool IsOpen();
    26     //
    27     int SetNonBlocking(int aNonBlocking);
    28     //Read
    29     template<int S>
    30     int Read(HidReport<S>& aInputReport);
    31     //Write
    32     template<int S>
    33     int Write(const HidReport<S>& aOutputReport);
    34     //
    35     const wchar_t* Error();
    36     //
    37     wchar_t* Vendor();
    38     wchar_t* Product();
    39     wchar_t* SerialNumber();
    40 
    41 private:
    42     void FetchStrings();
    43 
    44 private:
    45     ///Our USB HID device
    46     hid_device* iHidDevice;
    47     //
    48     wchar_t iVendor[KMaxHidStringChar];
    49     wchar_t iProduct[KMaxHidStringChar];
    50     wchar_t iSerialNumber[KMaxHidStringChar];
    51     };
    52 
    53 
    54 /**
    55 */
    56 template<int S>
    57 int HidDevice::Write(const HidReport<S>& aOutputReport)
    58     {
    59     return hid_write(iHidDevice,aOutputReport.Buffer(),S);
    60     }
    61 
    62 /**
    63 */
    64 template<int S>
    65 int HidDevice::Read(HidReport<S>& aInputReport)
    66     {
    67     return hid_read(iHidDevice,aInputReport.Buffer(),S);
    68     }
    69 
    70 
    71 #endif