HidDevice.h
author sl
Mon, 07 Jul 2014 22:27:56 +0200
changeset 3 d235c10ff460
child 7 8bac7aac665c
permissions -rw-r--r--
Adding APIs for size and set pixel.
sl@0
     1
//
sl@0
     2
//
sl@0
     3
//
sl@0
     4
sl@0
     5
#ifndef HID_DEVICE_H
sl@0
     6
#define HID_DEVICE_H
sl@0
     7
sl@0
     8
#include "HidReport.h"
sl@0
     9
#include "hidapi.h"
sl@0
    10
sl@0
    11
const int KMaxHidStringChar=256;
sl@0
    12
sl@0
    13
/**
sl@0
    14
TODO: move to another header
sl@0
    15
*/
sl@0
    16
class HidDevice
sl@0
    17
    {
sl@0
    18
public:
sl@0
    19
    HidDevice();
sl@0
    20
    int Open(const char* aPath);
sl@0
    21
    int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
sl@0
    22
    void Close();
sl@0
    23
    bool IsOpen();
sl@0
    24
    //
sl@0
    25
    int SetNonBlocking(int aNonBlocking);
sl@0
    26
    //Read
sl@0
    27
    template<int S>
sl@0
    28
    int Read(HidReport<S>& aInputReport);
sl@0
    29
    //Write
sl@0
    30
    template<int S>
sl@0
    31
    int Write(const HidReport<S>& aOutputReport);
sl@0
    32
    //
sl@0
    33
    const wchar_t* Error();
sl@0
    34
    //
sl@0
    35
    wchar_t* Vendor();
sl@0
    36
    wchar_t* Product();
sl@0
    37
    wchar_t* SerialNumber();
sl@0
    38
sl@0
    39
private:
sl@0
    40
    void FetchStrings();
sl@0
    41
sl@0
    42
private:
sl@0
    43
    ///Our USB HID device
sl@0
    44
    hid_device* iHidDevice;
sl@0
    45
    //
sl@0
    46
    wchar_t iVendor[KMaxHidStringChar];
sl@0
    47
    wchar_t iProduct[KMaxHidStringChar];
sl@0
    48
    wchar_t iSerialNumber[KMaxHidStringChar];
sl@0
    49
    };
sl@0
    50
sl@0
    51
sl@0
    52
/**
sl@0
    53
*/
sl@0
    54
template<int S>
sl@0
    55
int HidDevice::Write(const HidReport<S>& aOutputReport)
sl@0
    56
    {
sl@0
    57
    return hid_write(iHidDevice,aOutputReport.Buffer(),S);
sl@0
    58
    }
sl@0
    59
sl@0
    60
/**
sl@0
    61
*/
sl@0
    62
template<int S>
sl@0
    63
int HidDevice::Read(HidReport<S>& aInputReport)
sl@0
    64
    {
sl@0
    65
    return hid_read(iHidDevice,aInputReport.Buffer(),S);
sl@0
    66
    }
sl@0
    67
sl@0
    68
sl@0
    69
#endif