HidDevice.h
author sl
Sun, 29 Jun 2014 20:38:15 +0200
changeset 1 dd5eef0de75a
child 7 8bac7aac665c
permissions -rw-r--r--
Adding CMake file.
     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     //Read
    27     template<int S>
    28     int Read(HidReport<S>& aInputReport);
    29     //Write
    30     template<int S>
    31     int Write(const HidReport<S>& aOutputReport);
    32     //
    33     const wchar_t* Error();
    34     //
    35     wchar_t* Vendor();
    36     wchar_t* Product();
    37     wchar_t* SerialNumber();
    38 
    39 private:
    40     void FetchStrings();
    41 
    42 private:
    43     ///Our USB HID device
    44     hid_device* iHidDevice;
    45     //
    46     wchar_t iVendor[KMaxHidStringChar];
    47     wchar_t iProduct[KMaxHidStringChar];
    48     wchar_t iSerialNumber[KMaxHidStringChar];
    49     };
    50 
    51 
    52 /**
    53 */
    54 template<int S>
    55 int HidDevice::Write(const HidReport<S>& aOutputReport)
    56     {
    57     return hid_write(iHidDevice,aOutputReport.Buffer(),S);
    58     }
    59 
    60 /**
    61 */
    62 template<int S>
    63 int HidDevice::Read(HidReport<S>& aInputReport)
    64     {
    65     return hid_read(iHidDevice,aInputReport.Buffer(),S);
    66     }
    67 
    68 
    69 #endif