Merge pull request #6237 from ZappoMan/comfortTweaks

add makeAxis support to JSON parsing
This commit is contained in:
Brad Davis 2015-10-29 22:46:34 -07:00
commit 5233577d24
5 changed files with 73 additions and 29 deletions

View file

@ -2,17 +2,23 @@
"name": "Keyboard/Mouse to Actions",
"channels": [
{ "from": ["Keyboard.A", "Keyboard.Left", "Keyboard.TouchpadLeft"],
"when": [ "Application.InHMD", "Application.ComfortMode" ],
{ "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] },
"when": [ "Application.InHMD", "Application.ComfortMode", "Keyboard.RightMouseClick" ],
"to": "Actions.StepYaw",
"filters":
[
"constrainToInteger",
{ "type": "pulse", "interval": 0.5 },
{ "type": "scale", "scale": -15 }
{ "type": "scale", "scale": 15 }
]
},
{ "from": ["Keyboard.D", "Keyboard.Right", "Keyboard.TouchpadRight"],
{ "from": { "makeAxis" : [
["Keyboard.A", "Keyboard.Left", "Keyboard.TouchpadLeft"],
["Keyboard.D", "Keyboard.Right", "Keyboard.TouchpadRight"]
]
},
"when": [ "Application.InHMD", "Application.ComfortMode" ],
"to": "Actions.StepYaw",
"filters":
@ -22,24 +28,17 @@
]
},
{ "from": "Keyboard.MouseMoveLeft",
"when": [ "Application.InHMD", "Application.ComfortMode", "Keyboard.RightMouseClick" ],
"to": "Actions.StepYaw",
"filters":
[
{ "type": "pulse", "interval": 0.5 },
{ "type": "scale", "scale": -15 }
{ "from": { "makeAxis" : [
["Keyboard.A", "Keyboard.Left", "Keyboard.TouchpadLeft"],
["Keyboard.D", "Keyboard.Right", "Keyboard.TouchpadRight"]
]
},
"to": "Actions.Yaw"
},
{ "from": "Keyboard.MouseMoveRight",
"when": [ "Application.InHMD", "Application.ComfortMode", "Keyboard.RightMouseClick" ],
"to": "Actions.StepYaw",
"filters":
[
{ "type": "pulse", "interval": 0.5 },
{ "type": "scale", "scale": 15 }
]
{ "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] },
"when": "Keyboard.RightMouseClick",
"to": "Actions.Yaw",
},
{ "from": "Keyboard.A", "when": "Keyboard.Shift", "to": "Actions.LATERAL_LEFT" },
@ -53,8 +52,6 @@
{ "from": "Keyboard.W", "to": "Actions.LONGITUDINAL_FORWARD" },
{ "from": "Keyboard.S", "to": "Actions.LONGITUDINAL_BACKWARD" },
{ "from": "Keyboard.A", "to": "Actions.YAW_LEFT" },
{ "from": "Keyboard.D", "to": "Actions.YAW_RIGHT" },
{ "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" },
{ "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" },
@ -67,21 +64,15 @@
{ "from": "Keyboard.Up", "to": "Actions.LONGITUDINAL_FORWARD" },
{ "from": "Keyboard.Down", "to": "Actions.LONGITUDINAL_BACKWARD" },
{ "from": "Keyboard.Left", "to": "Actions.YAW_LEFT" },
{ "from": "Keyboard.Right", "to": "Actions.YAW_RIGHT" },
{ "from": "Keyboard.PgDown", "to": "Actions.VERTICAL_DOWN" },
{ "from": "Keyboard.PgUp", "to": "Actions.VERTICAL_UP" },
{ "from": "Keyboard.MouseMoveLeft", "when": "Keyboard.RightMouseClick", "to": "Actions.YAW_LEFT" },
{ "from": "Keyboard.MouseMoveRight", "when": "Keyboard.RightMouseClick", "to": "Actions.YAW_RIGHT" },
{ "from": "Keyboard.MouseMoveUp", "when": "Keyboard.RightMouseClick", "to": "Actions.PITCH_UP" },
{ "from": "Keyboard.MouseMoveDown", "when": "Keyboard.RightMouseClick", "to": "Actions.PITCH_DOWN" },
{ "from": "Keyboard.TouchpadDown", "to": "Actions.PITCH_DOWN" },
{ "from": "Keyboard.TouchpadUp", "to": "Actions.PITCH_UP" },
{ "from": "Keyboard.TouchpadLeft", "to": "Actions.YAW_LEFT" },
{ "from": "Keyboard.TouchpadRight", "to": "Actions.YAW_RIGHT" },
{ "from": "Keyboard.MouseWheelUp", "to": "Actions.LATERAL_RIGHT" },
{ "from": "Keyboard.MouseWheelDown", "to": "Actions.LATERAL_LEFT" },

View file

@ -489,7 +489,11 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
// If the source hasn't been written yet, defer processing of this route
auto source = route->source;
if (!force && source->writeable()) {
auto sourceInput = source->getInput();
if (sourceInput.device == STANDARD_DEVICE && !force && source->writeable()) {
if (debugRoutes && route->debug) {
qCDebug(controllers) << "Source not yet written, deferring";
}
return false;
}
@ -747,7 +751,15 @@ Endpoint::Pointer UserInputMapper::parseEndpoint(const QJsonValue& value) {
if (value.isString()) {
auto input = findDeviceInput(value.toString());
result = endpointFor(input);
} else if (value.isArray()) {
return parseAny(value);
} else if (value.isObject()) {
auto axisEndpoint = parseAxis(value);
if (axisEndpoint) {
return axisEndpoint;
}
// if we have other types of endpoints that are objects, follow the axisEndpoint example, and place them here
// Endpoint is defined as an object, we expect a js function then
return Endpoint::Pointer();
}
@ -881,7 +893,28 @@ Endpoint::Pointer UserInputMapper::parseDestination(const QJsonValue& value) {
return parseEndpoint(value);
}
Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
Endpoint::Pointer UserInputMapper::parseAxis(const QJsonValue& value) {
if (value.isObject()) {
auto object = value.toObject();
if (object.contains("makeAxis")) {
auto axisValue = object.value("makeAxis");
if (axisValue.isArray()) {
auto axisArray = axisValue.toArray();
static const int AXIS_ARRAY_SIZE = 2; // axis can only have 2 children
if (axisArray.size() == AXIS_ARRAY_SIZE) {
Endpoint::Pointer first = parseEndpoint(axisArray.first());
Endpoint::Pointer second = parseEndpoint(axisArray.last());
if (first && second) {
return std::make_shared<CompositeEndpoint>(first, second);
}
}
}
}
}
return Endpoint::Pointer();
}
Endpoint::Pointer UserInputMapper::parseAny(const QJsonValue& value) {
if (value.isArray()) {
Endpoint::List children;
for (auto arrayItem : value.toArray()) {
@ -893,7 +926,19 @@ Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
}
return std::make_shared<AnyEndpoint>(children);
}
return Endpoint::Pointer();
}
Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
if (value.isObject()) {
auto axisEndpoint = parseAxis(value);
if (axisEndpoint) {
return axisEndpoint;
}
// if we have other types of endpoints that are objects, follow the axisEndpoint example, and place them here
} else if (value.isArray()) {
return parseAny(value);
}
return parseEndpoint(value);
}

View file

@ -159,6 +159,8 @@ namespace controller {
RoutePointer parseRoute(const QJsonValue& value);
EndpointPointer parseDestination(const QJsonValue& value);
EndpointPointer parseSource(const QJsonValue& value);
EndpointPointer parseAxis(const QJsonValue& value);
EndpointPointer parseAny(const QJsonValue& value);
EndpointPointer parseEndpoint(const QJsonValue& value);
ConditionalPointer parseConditional(const QJsonValue& value);

View file

@ -20,6 +20,10 @@ CompositeEndpoint::CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer
}
}
bool CompositeEndpoint::readable() const {
return first->readable() && second->readable();
}
float CompositeEndpoint::value() {
float result = first->value() * -1.0f + second->value();
return result;

View file

@ -19,6 +19,8 @@ namespace controller {
virtual float value() override;
virtual void apply(float newValue, const Pointer& source) override;
virtual bool readable() const override;
};
}