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