author | StephaneLenclud |
Thu, 05 Feb 2015 14:26:29 +0100 | |
changeset 29 | 9b44c6e1651c |
parent 0 | 0f874d9e4130 |
child 35 | 638eb0763e20 |
permissions | -rw-r--r-- |
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@7 | 20 |
virtual ~HidDevice(); |
sl@7 | 21 |
// |
sl@0 | 22 |
int Open(const char* aPath); |
sl@0 | 23 |
int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber); |
sl@0 | 24 |
void Close(); |
sl@0 | 25 |
bool IsOpen(); |
sl@0 | 26 |
// |
sl@0 | 27 |
int SetNonBlocking(int aNonBlocking); |
sl@0 | 28 |
//Read |
sl@0 | 29 |
template<int S> |
sl@0 | 30 |
int Read(HidReport<S>& aInputReport); |
sl@0 | 31 |
//Write |
sl@0 | 32 |
template<int S> |
sl@0 | 33 |
int Write(const HidReport<S>& aOutputReport); |
sl@0 | 34 |
// |
sl@0 | 35 |
const wchar_t* Error(); |
sl@0 | 36 |
// |
sl@0 | 37 |
wchar_t* Vendor(); |
sl@0 | 38 |
wchar_t* Product(); |
sl@0 | 39 |
wchar_t* SerialNumber(); |
sl@0 | 40 |
|
sl@0 | 41 |
private: |
sl@0 | 42 |
void FetchStrings(); |
sl@0 | 43 |
|
sl@0 | 44 |
private: |
sl@0 | 45 |
///Our USB HID device |
sl@0 | 46 |
hid_device* iHidDevice; |
sl@0 | 47 |
// |
sl@0 | 48 |
wchar_t iVendor[KMaxHidStringChar]; |
sl@0 | 49 |
wchar_t iProduct[KMaxHidStringChar]; |
sl@0 | 50 |
wchar_t iSerialNumber[KMaxHidStringChar]; |
sl@0 | 51 |
}; |
sl@0 | 52 |
|
sl@0 | 53 |
|
sl@0 | 54 |
/** |
sl@0 | 55 |
*/ |
sl@0 | 56 |
template<int S> |
sl@0 | 57 |
int HidDevice::Write(const HidReport<S>& aOutputReport) |
sl@0 | 58 |
{ |
sl@0 | 59 |
return hid_write(iHidDevice,aOutputReport.Buffer(),S); |
sl@0 | 60 |
} |
sl@0 | 61 |
|
sl@0 | 62 |
/** |
sl@0 | 63 |
*/ |
sl@0 | 64 |
template<int S> |
sl@0 | 65 |
int HidDevice::Read(HidReport<S>& aInputReport) |
sl@0 | 66 |
{ |
sl@0 | 67 |
return hid_read(iHidDevice,aInputReport.Buffer(),S); |
sl@0 | 68 |
} |
sl@0 | 69 |
|
sl@0 | 70 |
|
sl@0 | 71 |
#endif |