diff options
author | Eike Ziller <git@eikeziller.de> | 2017-11-19 21:18:26 +0100 |
---|---|---|
committer | Eike Ziller <git@eikeziller.de> | 2017-11-23 20:23:28 +0100 |
commit | 7bacbdf10b97040c9ed282a22485759bd082fa63 (patch) | |
tree | 2a02884f633ddbc7ede387a5bf2aa8d7b0396e5f /proto-iokit-foohid/foohidjoystick.h | |
parent | f548847ea43006b2dc540e84d11d3c3662a94148 (diff) |
Add virtual joystick output for macOS
Based of the foohid IOKit driver for implementing virtual HID devices.
Issue: #236
Diffstat (limited to 'proto-iokit-foohid/foohidjoystick.h')
-rw-r--r-- | proto-iokit-foohid/foohidjoystick.h | 51 |
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; +}; |