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