src/cadMousePro.cpp
branchv_0
changeset 0 6ff501639c23
child 1 29cbe171cd43
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cadMousePro.cpp	Wed Aug 14 16:16:58 2019 +0200
@@ -0,0 +1,49 @@
+#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;
+	
+	}
+}
\ No newline at end of file