From 7bacbdf10b97040c9ed282a22485759bd082fa63 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Sun, 19 Nov 2017 21:18:26 +0100 Subject: Add virtual joystick output for macOS Based of the foohid IOKit driver for implementing virtual HID devices. Issue: #236 --- proto-iokit-foohid/foohidjoystick.h | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 proto-iokit-foohid/foohidjoystick.h (limited to 'proto-iokit-foohid/foohidjoystick.h') 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 +#include + +#include + +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; +}; -- cgit v1.2.3