src/cadMousePro.cpp
author František Kučera <franta-hg@frantovo.cz>
Wed, 14 Aug 2019 16:16:58 +0200
branchv_0
changeset 0 6ff501639c23
child 1 29cbe171cd43
permissions -rw-r--r--
project skeleton, open USB HID device

#include <iostream>

#include <hidapi/hidapi.h>

class HIDException {
private:
	std::wstring message;
public:

	HIDException(std::wstring message) : message(message) {
	}

	virtual ~HIDException() {
	}
	
	const std::wstring getMessage() const {
		return message;
	}

};

class HIDDevice {
private:
	hid_device* handle;
public:

	HIDDevice(unsigned short vendorId, unsigned short productId, const wchar_t *serialNumber) {
		handle = hid_open(vendorId, productId, serialNumber);
		if (handle == nullptr) throw HIDException(L"Unable to open HID device. Are you root? Is mouse present?");
	}

	virtual ~HIDDevice() {
		hid_close(handle);
	}


};

int main(int argc, char** argv) {
	try {

		std::wcout << L"cadMousePro" << std::endl;
		HIDDevice mouse(0x256f, 0xc652, nullptr);
		std::wcout << L"mouse opened" << std::endl;
	} catch (const HIDException& e) {
		std::wcout << L"HIDException: " << e.getMessage() << std::endl;
	
	}
}