MiniDisplay/HidDevice.h
author sl
Thu, 29 May 2014 19:46:57 +0200
changeset 18 79801cc3bc94
permissions -rw-r--r--
Restoring some of our on-screen functionality for debug purposes.
We could prove that updating a single pixel is much faster than updating our
whole screen. Single pixel updates runs at full 24 FPS.
sl@4
     1
//
sl@4
     2
//
sl@4
     3
//
sl@4
     4
sl@4
     5
#ifndef HID_DEVICE_H
sl@4
     6
#define HID_DEVICE_H
sl@4
     7
sl@4
     8
#include "HidReport.h"
sl@4
     9
#include "hidapi.h"
sl@4
    10
sl@4
    11
const int KMaxHidStringChar=256;
sl@4
    12
sl@4
    13
/**
sl@4
    14
TODO: move to another header
sl@4
    15
*/
sl@4
    16
class HidDevice
sl@4
    17
    {
sl@4
    18
public:
sl@4
    19
    HidDevice();
sl@4
    20
    int Open(const char* aPath);
sl@4
    21
    int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
sl@4
    22
    void Close();
sl@4
    23
    bool IsOpen();
sl@4
    24
    //
sl@4
    25
    int SetNonBlocking(int aNonBlocking);
sl@4
    26
    //Read
sl@4
    27
    template<int S>
sl@4
    28
    int Read(HidReport<S>& aInputReport);
sl@4
    29
    //Write
sl@4
    30
    template<int S>
sl@4
    31
    int Write(const HidReport<S>& aOutputReport);
sl@4
    32
    //
sl@4
    33
    const wchar_t* Error();
sl@4
    34
    //
sl@4
    35
    wchar_t* Vendor();
sl@4
    36
    wchar_t* Product();
sl@4
    37
    wchar_t* SerialNumber();
sl@4
    38
sl@4
    39
private:
sl@4
    40
    void FetchStrings();
sl@4
    41
sl@4
    42
private:
sl@4
    43
    ///Our USB HID device
sl@4
    44
    hid_device* iHidDevice;
sl@4
    45
    //
sl@4
    46
    wchar_t iVendor[KMaxHidStringChar];
sl@4
    47
    wchar_t iProduct[KMaxHidStringChar];
sl@4
    48
    wchar_t iSerialNumber[KMaxHidStringChar];
sl@4
    49
    };
sl@4
    50
sl@4
    51
sl@4
    52
/**
sl@4
    53
*/
sl@4
    54
template<int S>
sl@4
    55
int HidDevice::Write(const HidReport<S>& aOutputReport)
sl@4
    56
    {
sl@4
    57
    return hid_write(iHidDevice,aOutputReport.Buffer(),S);
sl@4
    58
    }
sl@4
    59
sl@4
    60
/**
sl@4
    61
*/
sl@4
    62
template<int S>
sl@4
    63
int HidDevice::Read(HidReport<S>& aInputReport)
sl@4
    64
    {
sl@4
    65
    return hid_read(iHidDevice,aInputReport.Buffer(),S);
sl@4
    66
    }
sl@4
    67
sl@4
    68
sl@4
    69
#endif