HidDevice.h
author sl
Mon, 25 Aug 2014 22:05:30 +0200
changeset 11 2d749a2bea34
parent 0 0f874d9e4130
child 35 638eb0763e20
permissions -rw-r--r--
Now having only one generic request API.
That will help us support different display types.
     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