ngscopeclient 0.1-dev+51fbda87c
HID.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ANTIKERNEL *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
36#ifndef HID_h
37#define HID_h
38
39#include "../log/log.h"
40#include <string>
41#ifdef __APPLE__
42#include <hidapi.h>
43#else
44#include <hidapi/hidapi.h>
45#endif
46
50class HID
51{
52public:
53
54 HID();
55 bool Connect(unsigned short vendorId, unsigned short productId, const char* serialNumber = NULL);
56 void Close();
57 virtual ~HID();
58
59 int Read(unsigned char* data, int len);
60 int Write(const unsigned char* data, int len);
61
62 hid_device* GetHandle()
63 { return m_handle; }
64
65 std::string GetManufacturerName()
66 { return m_manufacturerName; }
67
68 std::string GetProductName()
69 { return m_productName; }
70
71 std::string GetSerialNumber()
72 { return m_serialNumber; }
73
74 bool IsValid() const
75 {
76 return (m_handle != NULL);
77 }
78
79protected:
80 hid_device* m_handle;
81 std::string m_manufacturerName;
82 std::string m_productName;
83 std::string m_serialNumber;
84};
85
86#endif
Wrapper class for a USB HID connection.
Definition: HID.h:51
bool Connect(unsigned short vendorId, unsigned short productId, const char *serialNumber=NULL)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
Definition: HID.cpp:74
void Close()
Disconnects from the serial port.
Definition: HID.cpp:147
virtual ~HID()
Destructor.
Definition: HID.cpp:55
HID()
Constructor.
Definition: HID.cpp:47