Fixing line endings

This commit is contained in:
Brad Davis 2015-10-19 10:00:16 -07:00
parent edd2ce27f8
commit 22602fb6f6
4 changed files with 1006 additions and 1006 deletions

View file

@ -1,218 +1,218 @@
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0 import QtQuick.Dialogs 1.0
import "controller" import "controller"
import "controls" as HifiControls import "controls" as HifiControls
import "styles" import "styles"
HifiControls.VrDialog { HifiControls.VrDialog {
id: root id: root
HifiConstants { id: hifi } HifiConstants { id: hifi }
title: "Controller Test" title: "Controller Test"
resizable: true resizable: true
contentImplicitWidth: clientArea.implicitWidth contentImplicitWidth: clientArea.implicitWidth
contentImplicitHeight: clientArea.implicitHeight contentImplicitHeight: clientArea.implicitHeight
backgroundColor: "beige" backgroundColor: "beige"
property var actions: Controller.Actions property var actions: Controller.Actions
property var standard: Controller.Standard property var standard: Controller.Standard
property var hydra: null property var hydra: null
property var testMapping: null property var testMapping: null
property var xbox: null property var xbox: null
Component.onCompleted: { Component.onCompleted: {
enabled = true enabled = true
var xboxRegex = /^X360Controller/; var xboxRegex = /^X360Controller/;
var hydraRegex = /^Hydra/; var hydraRegex = /^Hydra/;
for (var prop in Controller.Hardware) { for (var prop in Controller.Hardware) {
if(xboxRegex.test(prop)) { if(xboxRegex.test(prop)) {
root.xbox = Controller.Hardware[prop] root.xbox = Controller.Hardware[prop]
print("found xbox") print("found xbox")
continue continue
} }
if (hydraRegex.test(prop)) { if (hydraRegex.test(prop)) {
root.hydra = Controller.Hardware[prop] root.hydra = Controller.Hardware[prop]
print("found hydra") print("found hydra")
continue continue
} }
} }
} }
Column { Column {
id: clientArea id: clientArea
spacing: 12 spacing: 12
x: root.clientX x: root.clientX
y: root.clientY y: root.clientY
Row { Row {
spacing: 8 spacing: 8
Button { Button {
text: "Standard Mapping" text: "Standard Mapping"
onClicked: { onClicked: {
var mapping = Controller.newMapping("Default"); var mapping = Controller.newMapping("Default");
mapping.from(standard.LX).to(actions.TranslateX); mapping.from(standard.LX).to(actions.TranslateX);
mapping.from(standard.LY).to(actions.TranslateZ); mapping.from(standard.LY).to(actions.TranslateZ);
mapping.from(standard.RY).to(actions.Pitch); mapping.from(standard.RY).to(actions.Pitch);
mapping.from(standard.RX).to(actions.Yaw); mapping.from(standard.RX).to(actions.Yaw);
mapping.from(standard.DU).scale(0.5).to(actions.LONGITUDINAL_FORWARD); mapping.from(standard.DU).scale(0.5).to(actions.LONGITUDINAL_FORWARD);
mapping.from(standard.DD).scale(0.5).to(actions.LONGITUDINAL_BACKWARD); mapping.from(standard.DD).scale(0.5).to(actions.LONGITUDINAL_BACKWARD);
mapping.from(standard.DL).scale(0.5).to(actions.LATERAL_LEFT); mapping.from(standard.DL).scale(0.5).to(actions.LATERAL_LEFT);
mapping.from(standard.DR).scale(0.5).to(actions.LATERAL_RIGHT); mapping.from(standard.DR).scale(0.5).to(actions.LATERAL_RIGHT);
mapping.from(standard.X).to(actions.VERTICAL_DOWN); mapping.from(standard.X).to(actions.VERTICAL_DOWN);
mapping.from(standard.Y).to(actions.VERTICAL_UP); mapping.from(standard.Y).to(actions.VERTICAL_UP);
mapping.from(standard.RT).scale(0.1).to(actions.BOOM_IN); mapping.from(standard.RT).scale(0.1).to(actions.BOOM_IN);
mapping.from(standard.LT).scale(0.1).to(actions.BOOM_OUT); mapping.from(standard.LT).scale(0.1).to(actions.BOOM_OUT);
mapping.from(standard.B).to(actions.ACTION1); mapping.from(standard.B).to(actions.ACTION1);
mapping.from(standard.A).to(actions.ACTION2); mapping.from(standard.A).to(actions.ACTION2);
mapping.from(standard.RB).to(actions.SHIFT); mapping.from(standard.RB).to(actions.SHIFT);
mapping.from(standard.Back).to(actions.TOGGLE_MUTE); mapping.from(standard.Back).to(actions.TOGGLE_MUTE);
mapping.from(standard.Start).to(actions.CONTEXT_MENU); mapping.from(standard.Start).to(actions.CONTEXT_MENU);
Controller.enableMapping("Default"); Controller.enableMapping("Default");
enabled = false; enabled = false;
text = "Standard Built" text = "Standard Built"
} }
} }
Button { Button {
text: root.xbox ? "XBox Mapping" : "XBox not found" text: root.xbox ? "XBox Mapping" : "XBox not found"
property bool built: false property bool built: false
enabled: root.xbox && !built enabled: root.xbox && !built
onClicked: { onClicked: {
var mapping = Controller.newMapping(); var mapping = Controller.newMapping();
mapping.from(xbox.A).to(standard.A); mapping.from(xbox.A).to(standard.A);
mapping.from(xbox.B).to(standard.B); mapping.from(xbox.B).to(standard.B);
mapping.from(xbox.X).to(standard.X); mapping.from(xbox.X).to(standard.X);
mapping.from(xbox.Y).to(standard.Y); mapping.from(xbox.Y).to(standard.Y);
mapping.from(xbox.Up).to(standard.DU); mapping.from(xbox.Up).to(standard.DU);
mapping.from(xbox.Down).to(standard.DD); mapping.from(xbox.Down).to(standard.DD);
mapping.from(xbox.Left).to(standard.DL); mapping.from(xbox.Left).to(standard.DL);
mapping.from(xbox.Right).to(standard.Right); mapping.from(xbox.Right).to(standard.Right);
mapping.from(xbox.LB).to(standard.LB); mapping.from(xbox.LB).to(standard.LB);
mapping.from(xbox.RB).to(standard.RB); mapping.from(xbox.RB).to(standard.RB);
mapping.from(xbox.LS).to(standard.LS); mapping.from(xbox.LS).to(standard.LS);
mapping.from(xbox.RS).to(standard.RS); mapping.from(xbox.RS).to(standard.RS);
mapping.from(xbox.Start).to(standard.Start); mapping.from(xbox.Start).to(standard.Start);
mapping.from(xbox.Back).to(standard.Back); mapping.from(xbox.Back).to(standard.Back);
mapping.from(xbox.LY).to(standard.LY); mapping.from(xbox.LY).to(standard.LY);
mapping.from(xbox.LX).to(standard.LX); mapping.from(xbox.LX).to(standard.LX);
mapping.from(xbox.RY).to(standard.RY); mapping.from(xbox.RY).to(standard.RY);
mapping.from(xbox.RX).to(standard.RX); mapping.from(xbox.RX).to(standard.RX);
mapping.from(xbox.LT).to(standard.LT); mapping.from(xbox.LT).to(standard.LT);
mapping.from(xbox.RT).to(standard.RT); mapping.from(xbox.RT).to(standard.RT);
mapping.enable(); mapping.enable();
built = false; built = false;
text = "XBox Built" text = "XBox Built"
} }
} }
Button { Button {
text: root.hydra ? "Hydra Mapping" : "Hydra Not Found" text: root.hydra ? "Hydra Mapping" : "Hydra Not Found"
property bool built: false property bool built: false
enabled: root.hydra && !built enabled: root.hydra && !built
onClicked: { onClicked: {
var mapping = Controller.newMapping(); var mapping = Controller.newMapping();
mapping.from(hydra.LY).invert().to(standard.LY); mapping.from(hydra.LY).invert().to(standard.LY);
mapping.from(hydra.LX).to(standard.LX); mapping.from(hydra.LX).to(standard.LX);
mapping.from(hydra.RY).invert().to(standard.RY); mapping.from(hydra.RY).invert().to(standard.RY);
mapping.from(hydra.RX).to(standard.RX); mapping.from(hydra.RX).to(standard.RX);
mapping.from(hydra.LT).to(standard.LT); mapping.from(hydra.LT).to(standard.LT);
mapping.from(hydra.RT).to(standard.RT); mapping.from(hydra.RT).to(standard.RT);
mapping.enable(); mapping.enable();
built = false; built = false;
text = "Hydra Built" text = "Hydra Built"
} }
} }
Button { Button {
text: "Test Mapping" text: "Test Mapping"
onClicked: { onClicked: {
var mapping = Controller.newMapping(); var mapping = Controller.newMapping();
// Inverting a value // Inverting a value
mapping.from(hydra.RY).invert().to(standard.RY); mapping.from(hydra.RY).invert().to(standard.RY);
mapping.from(hydra.RX).to(standard.RX); mapping.from(hydra.RX).to(standard.RX);
mapping.from(hydra.LY).to(standard.LY); mapping.from(hydra.LY).to(standard.LY);
mapping.from(hydra.LX).to(standard.LX); mapping.from(hydra.LX).to(standard.LX);
// Assigning a value from a function // Assigning a value from a function
// mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX); // mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX);
// Constrainting a value to -1, 0, or 1, with a deadzone // Constrainting a value to -1, 0, or 1, with a deadzone
// mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY); // mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw); mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
// mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT); // mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
// mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT); // mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
// mapping.modifier(keyboard.Ctrl).scale(2.0) // mapping.modifier(keyboard.Ctrl).scale(2.0)
// mapping.from(keyboard.A).to(actions.TranslateLeft) // mapping.from(keyboard.A).to(actions.TranslateLeft)
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) // mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft) // mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft)
// // First loopbacks // // First loopbacks
// // Then non-loopbacks by constraint level (number of inputs) // // Then non-loopbacks by constraint level (number of inputs)
// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX) // mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX)
// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft) // mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) // mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward) // mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward)
testMapping = mapping; testMapping = mapping;
enabled = false enabled = false
text = "Built" text = "Built"
} }
} }
Button { Button {
text: "Enable Mapping" text: "Enable Mapping"
onClicked: root.testMapping.enable() onClicked: root.testMapping.enable()
} }
Button { Button {
text: "Disable Mapping" text: "Disable Mapping"
onClicked: root.testMapping.disable() onClicked: root.testMapping.disable()
} }
Button { Button {
text: "Enable Mapping" text: "Enable Mapping"
onClicked: print(Controller.getValue(root.xbox.LY)); onClicked: print(Controller.getValue(root.xbox.LY));
} }
} }
Row { Row {
Xbox { device: root.standard; label: "Standard"; width: 360 } Xbox { device: root.standard; label: "Standard"; width: 360 }
} }
Row { Row {
spacing: 8 spacing: 8
Xbox { device: root.xbox; label: "XBox"; width: 360 } Xbox { device: root.xbox; label: "XBox"; width: 360 }
Hydra { device: root.hydra; width: 360 } Hydra { device: root.hydra; width: 360 }
} }
// Row { // Row {
// spacing: 8 // spacing: 8
// ScrollingGraph { // ScrollingGraph {
// controlId: Controller.Actions.Yaw // controlId: Controller.Actions.Yaw
// label: "Yaw" // label: "Yaw"
// min: -3.0 // min: -3.0
// max: 3.0 // max: 3.0
// size: 128 // size: 128
// } // }
// //
// ScrollingGraph { // ScrollingGraph {
// controlId: Controller.Actions.YAW_LEFT // controlId: Controller.Actions.YAW_LEFT
// label: "Yaw Left" // label: "Yaw Left"
// min: -3.0 // min: -3.0
// max: 3.0 // max: 3.0
// size: 128 // size: 128
// } // }
// //
// ScrollingGraph { // ScrollingGraph {
// controlId: Controller.Actions.YAW_RIGHT // controlId: Controller.Actions.YAW_RIGHT
// label: "Yaw Right" // label: "Yaw Right"
// min: -3.0 // min: -3.0
// max: 3.0 // max: 3.0
// size: 128 // size: 128
// } // }
// } // }
} }
} // dialog } // dialog

File diff suppressed because it is too large Load diff

View file

@ -1,207 +1,207 @@
// //
// Joystick.cpp // Joystick.cpp
// input-plugins/src/input-plugins // input-plugins/src/input-plugins
// //
// Created by Stephen Birarda on 2014-09-23. // Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "Joystick.h" #include "Joystick.h"
#include <limits> #include <limits>
#include <glm/glm.hpp> #include <glm/glm.hpp>
const float CONTROLLER_THRESHOLD = 0.3f; const float CONTROLLER_THRESHOLD = 0.3f;
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
const float MAX_AXIS = 32768.0f; const float MAX_AXIS = 32768.0f;
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) : Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
InputDevice(name), InputDevice(name),
_sdlGameController(sdlGameController), _sdlGameController(sdlGameController),
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)), _sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
_instanceId(instanceId) _instanceId(instanceId)
{ {
} }
#endif #endif
Joystick::~Joystick() { Joystick::~Joystick() {
closeJoystick(); closeJoystick();
} }
void Joystick::closeJoystick() { void Joystick::closeJoystick() {
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
SDL_GameControllerClose(_sdlGameController); SDL_GameControllerClose(_sdlGameController);
#endif #endif
} }
void Joystick::update(float deltaTime, bool jointsCaptured) { void Joystick::update(float deltaTime, bool jointsCaptured) {
for (auto axisState : _axisStateMap) { for (auto axisState : _axisStateMap) {
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) { if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
_axisStateMap[axisState.first] = 0.0f; _axisStateMap[axisState.first] = 0.0f;
} }
} }
} }
void Joystick::focusOutEvent() { void Joystick::focusOutEvent() {
_axisStateMap.clear(); _axisStateMap.clear();
_buttonPressedMap.clear(); _buttonPressedMap.clear();
}; };
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) { void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis; SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
_axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS; _axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
} }
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) { void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
auto input = makeInput((controller::StandardButtonChannel)event.button); auto input = makeInput((controller::StandardButtonChannel)event.button);
bool newValue = event.state == SDL_PRESSED; bool newValue = event.state == SDL_PRESSED;
if (newValue) { if (newValue) {
_buttonPressedMap.insert(input.getChannel()); _buttonPressedMap.insert(input.getChannel());
} else { } else {
_buttonPressedMap.erase(input.getChannel()); _buttonPressedMap.erase(input.getChannel());
} }
} }
#endif #endif
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) { void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
// Grab the current free device ID // Grab the current free device ID
_deviceID = mapper.getFreeDeviceID(); _deviceID = mapper.getFreeDeviceID();
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name); auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> { proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs; QVector<UserInputMapper::InputPair> availableInputs;
// Buttons // Buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
// DPad // DPad
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
// Bumpers // Bumpers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
// Stick press // Stick press
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
// Center buttons // Center buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
// Analog sticks // Analog sticks
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
// Triggers // Triggers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
// Aliases, PlayStation style names // Aliases, PlayStation style names
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right")); availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
return availableInputs; return availableInputs;
}; };
proxy->resetDeviceBindings = [this, &mapper] () -> bool { proxy->resetDeviceBindings = [this, &mapper] () -> bool {
mapper.removeAllInputChannelsForDevice(_deviceID); mapper.removeAllInputChannelsForDevice(_deviceID);
this->assignDefaultInputMapping(mapper); this->assignDefaultInputMapping(mapper);
return true; return true;
}; };
mapper.registerDevice(_deviceID, proxy); mapper.registerDevice(_deviceID, proxy);
} }
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) { void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
#if 0 #if 0
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
const float JOYSTICK_MOVE_SPEED = 1.0f; const float JOYSTICK_MOVE_SPEED = 1.0f;
const float DPAD_MOVE_SPEED = 0.5f; const float DPAD_MOVE_SPEED = 0.5f;
const float JOYSTICK_YAW_SPEED = 0.5f; const float JOYSTICK_YAW_SPEED = 0.5f;
const float JOYSTICK_PITCH_SPEED = 0.25f; const float JOYSTICK_PITCH_SPEED = 0.25f;
const float BOOM_SPEED = 0.1f; const float BOOM_SPEED = 0.1f;
// Y axes are flipped (up is negative) // Y axes are flipped (up is negative)
// Left Joystick: Movement, strafing // Left Joystick: Movement, strafing
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), JOYSTICK_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), JOYSTICK_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LX), JOYSTICK_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LX), JOYSTICK_MOVE_SPEED);
// Right Joystick: Camera orientation // Right Joystick: Camera orientation
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), JOYSTICK_YAW_SPEED); mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), JOYSTICK_YAW_SPEED);
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), JOYSTICK_PITCH_SPEED); mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), JOYSTICK_PITCH_SPEED);
// Dpad movement // Dpad movement
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), DPAD_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), DPAD_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), DPAD_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), DPAD_MOVE_SPEED);
// Button controls // Button controls
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), DPAD_MOVE_SPEED);
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), DPAD_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), DPAD_MOVE_SPEED);
// Zoom // Zoom
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), BOOM_SPEED); mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), BOOM_SPEED);
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), BOOM_SPEED); mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), BOOM_SPEED);
// Hold front right shoulder button for precision controls // Hold front right shoulder button for precision controls
// Left Joystick: Movement, strafing // Left Joystick: Movement, strafing
mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::TRANSLATE_Z, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::TRANSLATE_X, makeInput(controller::LY), makeInput(controller::RB), JOYSTICK_MOVE_SPEED / 2.0f);
// Right Joystick: Camera orientation // Right Joystick: Camera orientation
mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), makeInput(controller::RB), JOYSTICK_YAW_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::YAW, makeInput(controller::RX), makeInput(controller::RB), JOYSTICK_YAW_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), makeInput(controller::RB), JOYSTICK_PITCH_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::PITCH, makeInput(controller::RY), makeInput(controller::RB), JOYSTICK_PITCH_SPEED / 2.0f);
// Dpad movement // Dpad movement
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(controller::DU), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(controller::DD), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(controller::DR), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(controller::DL), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
// Button controls // Button controls
mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(controller::Y), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(controller::X), makeInput(controller::RB), DPAD_MOVE_SPEED / 2.0f);
// Zoom // Zoom
mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), makeInput(controller::RB), BOOM_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(controller::RT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), makeInput(controller::RB), BOOM_SPEED / 2.0f); mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(controller::LT), makeInput(controller::RB), BOOM_SPEED / 2.0f);
mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(controller::RB)); mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(controller::RB));
mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(controller::B)); mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(controller::B));
mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(controller::A)); mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(controller::A));
#endif #endif
#endif #endif
} }

View file

@ -1,70 +1,70 @@
// //
// Joystick.h // Joystick.h
// input-plugins/src/input-plugins // input-plugins/src/input-plugins
// //
// Created by Stephen Birarda on 2014-09-23. // Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_Joystick_h #ifndef hifi_Joystick_h
#define hifi_Joystick_h #define hifi_Joystick_h
#include <qobject.h> #include <qobject.h>
#include <qvector.h> #include <qvector.h>
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
#include <SDL.h> #include <SDL.h>
#undef main #undef main
#endif #endif
#include <controllers/InputDevice.h> #include <controllers/InputDevice.h>
#include <controllers/StandardControls.h> #include <controllers/StandardControls.h>
class Joystick : public QObject, public InputDevice { class Joystick : public QObject, public InputDevice {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name READ getName) Q_PROPERTY(QString name READ getName)
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
Q_PROPERTY(int instanceId READ getInstanceId) Q_PROPERTY(int instanceId READ getInstanceId)
#endif #endif
public: public:
const QString& getName() const { return _name; } const QString& getName() const { return _name; }
// Device functions // Device functions
virtual void registerToUserInputMapper(UserInputMapper& mapper) override; virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override; virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
virtual void update(float deltaTime, bool jointsCaptured) override; virtual void update(float deltaTime, bool jointsCaptured) override;
virtual void focusOutEvent() override; virtual void focusOutEvent() override;
Joystick() : InputDevice("Joystick") {} Joystick() : InputDevice("Joystick") {}
~Joystick(); ~Joystick();
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController); Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
#endif #endif
void closeJoystick(); void closeJoystick();
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
void handleAxisEvent(const SDL_ControllerAxisEvent& event); void handleAxisEvent(const SDL_ControllerAxisEvent& event);
void handleButtonEvent(const SDL_ControllerButtonEvent& event); void handleButtonEvent(const SDL_ControllerButtonEvent& event);
#endif #endif
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
int getInstanceId() const { return _instanceId; } int getInstanceId() const { return _instanceId; }
#endif #endif
private: private:
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
SDL_GameController* _sdlGameController; SDL_GameController* _sdlGameController;
SDL_Joystick* _sdlJoystick; SDL_Joystick* _sdlJoystick;
SDL_JoystickID _instanceId; SDL_JoystickID _instanceId;
#endif #endif
}; };
#endif // hifi_Joystick_h #endif // hifi_Joystick_h