HidDevice.h
author StephaneLenclud
Sat, 26 Sep 2015 11:45:26 +0200
changeset 39 c32f4955c166
parent 7 8bac7aac665c
permissions -rw-r--r--
More fixes to our NuGet package targets file.
     1 //
     2 // Copyright (C) 2014-2015 Stéphane Lenclud.
     3 //
     4 // This file is part of MiniDisplay.
     5 //
     6 // MiniDisplay is free software: you can redistribute it and/or modify
     7 // it under the terms of the GNU General Public License as published by
     8 // the Free Software Foundation, either version 3 of the License, or
     9 // (at your option) any later version.
    10 //
    11 // MiniDisplay is distributed in the hope that it will be useful,
    12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 // GNU General Public License for more details.
    15 //
    16 // You should have received a copy of the GNU General Public License
    17 // along with MiniDisplay.  If not, see <http://www.gnu.org/licenses/>.
    18 //
    19 
    20 #ifndef HID_DEVICE_H
    21 #define HID_DEVICE_H
    22 
    23 #include "HidReport.h"
    24 #include "hidapi.h"
    25 
    26 const int KMaxHidStringChar=256;
    27 
    28 /**
    29 TODO: move to another header
    30 */
    31 class HidDevice
    32     {
    33 public:
    34     HidDevice();
    35 	virtual ~HidDevice();
    36 	//
    37     int Open(const char* aPath);
    38     int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
    39     void Close();
    40     bool IsOpen();
    41     //
    42     int SetNonBlocking(int aNonBlocking);
    43     //Read
    44     template<int S>
    45     int Read(HidReport<S>& aInputReport);
    46     //Write
    47     template<int S>
    48     int Write(const HidReport<S>& aOutputReport);
    49     //
    50     const wchar_t* Error();
    51     //
    52     wchar_t* Vendor();
    53     wchar_t* Product();
    54     wchar_t* SerialNumber();
    55 
    56 private:
    57     void FetchStrings();
    58 
    59 private:
    60     ///Our USB HID device
    61     hid_device* iHidDevice;
    62     //
    63     wchar_t iVendor[KMaxHidStringChar];
    64     wchar_t iProduct[KMaxHidStringChar];
    65     wchar_t iSerialNumber[KMaxHidStringChar];
    66     };
    67 
    68 
    69 /**
    70 */
    71 template<int S>
    72 int HidDevice::Write(const HidReport<S>& aOutputReport)
    73     {
    74     return hid_write(iHidDevice,aOutputReport.Buffer(),S);
    75     }
    76 
    77 /**
    78 */
    79 template<int S>
    80 int HidDevice::Read(HidReport<S>& aInputReport)
    81     {
    82     return hid_read(iHidDevice,aInputReport.Buffer(),S);
    83     }
    84 
    85 
    86 #endif