From 9348888ae5a2498b5adcced641a73ef99f1cc7e8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 Sep 2014 17:42:48 -0700 Subject: [PATCH] map PrioVR to new JoystickScriptingInterface --- interface/src/devices/Joystick.h | 3 +++ interface/src/devices/PrioVR.cpp | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/interface/src/devices/Joystick.h b/interface/src/devices/Joystick.h index 63386db5c5..228e993204 100644 --- a/interface/src/devices/Joystick.h +++ b/interface/src/devices/Joystick.h @@ -39,6 +39,9 @@ public: const QString& getName() const { return _name; } + const QVector& getAxes() const { return _axes; } + const QVector& getButtons() const { return _buttons; } + int getNumAxes() const { return _axes.size(); } int getNumButtons() const { return _buttons.size(); } diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index 30c5d74ce1..e810f9e370 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -17,6 +17,7 @@ #include "Application.h" #include "PrioVR.h" +#include "scripting/JoystickScriptingInterface.h" #include "ui/TextRenderer.h" #ifdef HAVE_PRIOVR @@ -61,18 +62,22 @@ static void setPalm(float deltaTime, int index) { palm->setActive(true); // Read controller buttons and joystick into the hand - if (!Application::getInstance()->getJoystickManager()->getJoysticks().isEmpty()) { - const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at(0); - if (state.axes.size() >= 4 && state.buttons.size() >= 4) { + const QString PRIO_JOYSTICK_NAME = "PrioVR"; + Joystick* prioJoystick = JoystickScriptingInterface::getInstance().joystickWithName(PRIO_JOYSTICK_NAME); + if (prioJoystick) { + const QVector axes = prioJoystick->getAxes(); + const QVector buttons = prioJoystick->getButtons(); + + if (axes.size() >= 4 && buttons.size() >= 4) { if (index == LEFT_HAND_INDEX) { - palm->setControllerButtons(state.buttons.at(1) ? BUTTON_FWD : 0); - palm->setTrigger(state.buttons.at(0) ? 1.0f : 0.0f); - palm->setJoystick(state.axes.at(0), -state.axes.at(1)); + palm->setControllerButtons(buttons[1] ? BUTTON_FWD : 0); + palm->setTrigger(buttons[0] ? 1.0f : 0.0f); + palm->setJoystick(axes[0], -axes[1]); } else { - palm->setControllerButtons(state.buttons.at(3) ? BUTTON_FWD : 0); - palm->setTrigger(state.buttons.at(2) ? 1.0f : 0.0f); - palm->setJoystick(state.axes.at(2), -state.axes.at(3)); + palm->setControllerButtons(buttons[3] ? BUTTON_FWD : 0); + palm->setTrigger(buttons[2] ? 1.0f : 0.0f); + palm->setJoystick(axes[2], -axes[3]); } } }