summaryrefslogtreecommitdiffhomepage
path: root/proto-iokit-foohid/foohidjoystick.h
diff options
context:
space:
mode:
Diffstat (limited to 'proto-iokit-foohid/foohidjoystick.h')
-rw-r--r--proto-iokit-foohid/foohidjoystick.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/proto-iokit-foohid/foohidjoystick.h b/proto-iokit-foohid/foohidjoystick.h
new file mode 100644
index 00000000..a1f74304
--- /dev/null
+++ b/proto-iokit-foohid/foohidjoystick.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2017, Eike Ziller *
+ * *
+ * Permission to use, copy, modify, and/or distribute this software for any *
+ * purpose with or without fee is hereby granted, provided that the above *
+ * copyright notice and this permission notice appear in all copies. *
+ */
+
+#pragma once
+
+#include <QByteArray>
+#include <QString>
+
+#include <IOKit/IOKitLib.h>
+
+struct JoystickValues {
+ uint8_t x;
+ uint8_t y;
+ uint8_t z;
+ uint8_t rx;
+ uint8_t ry;
+ uint8_t rz;
+};
+
+class FooHIDJoystick
+{
+public:
+ FooHIDJoystick(const QByteArray &name, const QByteArray &serialNumber);
+ ~FooHIDJoystick();
+
+ bool hasError() const;
+ QString errorMessage() const;
+
+ int minValue() const { return 0; }
+ int range() const { return 255; }
+
+ void setValue(JoystickValues newValues);
+
+private:
+ bool createDevice() const;
+ bool sendToDevice() const;
+ void destroyDevice() const;
+
+ const QByteArray name;
+ const QByteArray serialNumber;
+ io_connect_t connection = 0;
+ JoystickValues values = {127, 127};
+ QString _errorMessage;
+ bool _hasError = true;
+ bool connectionOpened = false;
+ bool deviceCreated = false;
+};