sl@0: // StephaneLenclud@35: // Copyright (C) 2014-2015 Stéphane Lenclud. sl@0: // StephaneLenclud@35: // This file is part of MiniDisplay. StephaneLenclud@35: // StephaneLenclud@35: // MiniDisplay is free software: you can redistribute it and/or modify StephaneLenclud@35: // it under the terms of the GNU General Public License as published by StephaneLenclud@35: // the Free Software Foundation, either version 3 of the License, or StephaneLenclud@35: // (at your option) any later version. StephaneLenclud@35: // StephaneLenclud@35: // MiniDisplay is distributed in the hope that it will be useful, StephaneLenclud@35: // but WITHOUT ANY WARRANTY; without even the implied warranty of StephaneLenclud@35: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the StephaneLenclud@35: // GNU General Public License for more details. StephaneLenclud@35: // StephaneLenclud@35: // You should have received a copy of the GNU General Public License StephaneLenclud@35: // along with MiniDisplay. If not, see . sl@0: // sl@0: sl@0: #ifndef HID_DEVICE_H sl@0: #define HID_DEVICE_H sl@0: sl@0: #include "HidReport.h" sl@0: #include "hidapi.h" sl@0: sl@0: const int KMaxHidStringChar=256; sl@0: sl@0: /** sl@0: TODO: move to another header sl@0: */ sl@0: class HidDevice sl@0: { sl@0: public: sl@0: HidDevice(); sl@7: virtual ~HidDevice(); sl@7: // sl@0: int Open(const char* aPath); sl@0: int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber); sl@0: void Close(); sl@0: bool IsOpen(); sl@0: // sl@0: int SetNonBlocking(int aNonBlocking); sl@0: //Read sl@0: template sl@0: int Read(HidReport& aInputReport); sl@0: //Write sl@0: template sl@0: int Write(const HidReport& aOutputReport); sl@0: // sl@0: const wchar_t* Error(); sl@0: // sl@0: wchar_t* Vendor(); sl@0: wchar_t* Product(); sl@0: wchar_t* SerialNumber(); sl@0: sl@0: private: sl@0: void FetchStrings(); sl@0: sl@0: private: sl@0: ///Our USB HID device sl@0: hid_device* iHidDevice; sl@0: // sl@0: wchar_t iVendor[KMaxHidStringChar]; sl@0: wchar_t iProduct[KMaxHidStringChar]; sl@0: wchar_t iSerialNumber[KMaxHidStringChar]; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: */ sl@0: template sl@0: int HidDevice::Write(const HidReport& aOutputReport) sl@0: { sl@0: return hid_write(iHidDevice,aOutputReport.Buffer(),S); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: template sl@0: int HidDevice::Read(HidReport& aInputReport) sl@0: { sl@0: return hid_read(iHidDevice,aInputReport.Buffer(),S); sl@0: } sl@0: sl@0: sl@0: #endif