From c0da74ccd25837186ebb48af5e21ec250d2a6bdf Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 11 Feb 2019 22:12:47 +0100 Subject: proto/vjoystick: fix threading issue Acquiring given joystick id must be done on the same thread as the feeder apparently. Provide diagnostics on failure. Issue: #860 --- proto-vjoystick/vjoystick.h | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'proto-vjoystick/vjoystick.h') diff --git a/proto-vjoystick/vjoystick.h b/proto-vjoystick/vjoystick.h index 96d10e9e..7e119b21 100644 --- a/proto-vjoystick/vjoystick.h +++ b/proto-vjoystick/vjoystick.h @@ -10,45 +10,32 @@ #include "api/plugin-api.hpp" #include "compat/macros.hpp" -#include - -enum class state : int +enum status { - notent = -1, - fail = -2, - success = 1, }; -class handle final +class vjoystick : public TR, public IProtocol { + Q_OBJECT + public: - static constexpr unsigned axis_count = 6; - static const unsigned char axis_ids[axis_count]; + vjoystick(); + ~vjoystick() override; + module_status initialize() override; + void pose( const double *headpose ) override; + QString game_name() override { return tr("Virtual joystick"); } private: - state joy_state = state::notent; long axis_min[6] {}; long axis_max[6] {}; [[nodiscard]] bool init(); -public: - handle(); - ~handle(); - state get_state() const { return joy_state; } - [[nodiscard]] bool to_axis_value(unsigned axis_id, double val, int& ret) const; -}; + int to_axis_value(unsigned axis_id, double val) const; -class vjoystick_proto : public TR, public IProtocol -{ - Q_OBJECT + static constexpr unsigned axis_count = 6; + static const unsigned char axis_ids[axis_count]; - std::optional h; -public: - vjoystick_proto(); - ~vjoystick_proto() override; - module_status initialize() override; - void pose( const double *headpose ) override; - QString game_name() override { return tr("Virtual joystick"); } -private: + bool status = false; + bool first_run = true; }; class vjoystick_dialog final : public IProtocolDialog -- cgit v1.2.3