inc/HidDevice.h
author sl
Thu, 22 May 2014 09:31:23 +0200
changeset 18 14662967f913
parent 16 21033ded8f86
permissions -rw-r--r--
Implementing Futaba GP1212A01A brightness support.
Test application now using Futaba class to send some of our commands.
     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