1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/MiniDisplay/HidDevice.h Tue May 27 19:50:28 2014 +0200
1.3 @@ -0,0 +1,69 @@
1.4 +//
1.5 +//
1.6 +//
1.7 +
1.8 +#ifndef HID_DEVICE_H
1.9 +#define HID_DEVICE_H
1.10 +
1.11 +#include "HidReport.h"
1.12 +#include "hidapi.h"
1.13 +
1.14 +const int KMaxHidStringChar=256;
1.15 +
1.16 +/**
1.17 +TODO: move to another header
1.18 +*/
1.19 +class HidDevice
1.20 + {
1.21 +public:
1.22 + HidDevice();
1.23 + int Open(const char* aPath);
1.24 + int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
1.25 + void Close();
1.26 + bool IsOpen();
1.27 + //
1.28 + int SetNonBlocking(int aNonBlocking);
1.29 + //Read
1.30 + template<int S>
1.31 + int Read(HidReport<S>& aInputReport);
1.32 + //Write
1.33 + template<int S>
1.34 + int Write(const HidReport<S>& aOutputReport);
1.35 + //
1.36 + const wchar_t* Error();
1.37 + //
1.38 + wchar_t* Vendor();
1.39 + wchar_t* Product();
1.40 + wchar_t* SerialNumber();
1.41 +
1.42 +private:
1.43 + void FetchStrings();
1.44 +
1.45 +private:
1.46 + ///Our USB HID device
1.47 + hid_device* iHidDevice;
1.48 + //
1.49 + wchar_t iVendor[KMaxHidStringChar];
1.50 + wchar_t iProduct[KMaxHidStringChar];
1.51 + wchar_t iSerialNumber[KMaxHidStringChar];
1.52 + };
1.53 +
1.54 +
1.55 +/**
1.56 +*/
1.57 +template<int S>
1.58 +int HidDevice::Write(const HidReport<S>& aOutputReport)
1.59 + {
1.60 + return hid_write(iHidDevice,aOutputReport.Buffer(),S);
1.61 + }
1.62 +
1.63 +/**
1.64 +*/
1.65 +template<int S>
1.66 +int HidDevice::Read(HidReport<S>& aInputReport)
1.67 + {
1.68 + return hid_read(iHidDevice,aInputReport.Buffer(),S);
1.69 + }
1.70 +
1.71 +
1.72 +#endif
1.73 \ No newline at end of file