diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-08 16:12:18 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-08 16:14:12 +0200 |
commit | 744574a36be2914c6d4641a9fa6e76359a4e218e (patch) | |
tree | f85c0c028f93bb1362e95d4b636faaa4e0bc35da /proto-vjoystick/vjoystick.h | |
parent | 5598520e24e978b55428f6da4a5dd9617844f152 (diff) |
proto/vjoystick: add new vjoystick protocol to replace vjoy
Diffstat (limited to 'proto-vjoystick/vjoystick.h')
-rw-r--r-- | proto-vjoystick/vjoystick.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/proto-vjoystick/vjoystick.h b/proto-vjoystick/vjoystick.h new file mode 100644 index 00000000..c4cb7e69 --- /dev/null +++ b/proto-vjoystick/vjoystick.h @@ -0,0 +1,79 @@ +/* Copyright (c) 2016, Stanislaw Halik <sthalik@misaki.pl> + + * 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 "ui_vjoystick.h" +#include "opentrack/plugin-api.hpp" + +#include <windows.h> + +enum state : signed char +{ + state_notent = -1, + state_fail = -2, + state_success = 1, +}; + +class handle final +{ +public: + static constexpr unsigned axis_count = 6; + static const unsigned char axis_ids[axis_count]; + +private: + state joy_state; + LONG axis_min[6]; + LONG axis_max[6]; + + static constexpr double val_minmax[6] = + { + 50, + 50, + 50, + 180, + 180, + 180 + }; + + void init(); +public: + handle(); + ~handle(); + state get_state() { return joy_state; } + LONG to_axis_value(unsigned axis_id, double val); +}; + +class vjoystick_proto : public IProtocol +{ + handle h; +public: + vjoystick_proto(); + ~vjoystick_proto() override; + bool correct() override { return h.get_state() == state_success; } + void pose( const double *headpose ) override; + QString game_name() override { return "Virtual joystick"; } +private: +}; + +class vjoystick_dialog final : public IProtocolDialog +{ + Q_OBJECT +public: + + vjoystick_dialog(); + void register_protocol(IProtocol *) override {} + void unregister_protocol() override {} +private: + Ui::vjoystick ui; +}; + +class vjoystick_metadata : public Metadata +{ +public: + QString name() { return QString("Joystick emulation -- vjoystick"); } + QIcon icon() { return QIcon(":/images/vjoystick.png"); } +}; |