Adding C# interop project and NuGet package.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of MiniDisplay.
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.
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.
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/>.
20 #include "HidDevice.h"
26 HidDevice::HidDevice():iHidDevice(NULL)
33 HidDevice::~HidDevice()
41 int HidDevice::Open(const char* aPath)
45 iHidDevice = hid_open_path(aPath);
49 //Fail to connect our device
59 See hidapi documentation.
61 int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber)
65 iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber);
69 //Fail to connect our device
81 void HidDevice::Close()
83 hid_close(iHidDevice); //No effect if device is null
86 memset(iVendor,0,sizeof(iVendor));
87 memset(iProduct,0,sizeof(iProduct));
88 memset(iSerialNumber,0,sizeof(iSerialNumber));
93 bool HidDevice::IsOpen()
95 return iHidDevice!=NULL;
101 const wchar_t* HidDevice::Error()
103 return hid_error(iHidDevice);
108 int HidDevice::SetNonBlocking(int aNonBlocking)
110 //Success we are now connected to our HID device
111 //Set read operation as non blocking
112 return hid_set_nonblocking(iHidDevice, aNonBlocking);
117 wchar_t* HidDevice::Vendor()
124 wchar_t* HidDevice::Product()
131 wchar_t* HidDevice::SerialNumber()
133 return iSerialNumber;
139 void HidDevice::FetchStrings()
141 hid_get_manufacturer_string(iHidDevice,iVendor,sizeof(iVendor));
142 hid_get_product_string(iHidDevice,iProduct,sizeof(iProduct));
143 hid_get_serial_number_string(iHidDevice,iSerialNumber,sizeof(iSerialNumber));