Fixing function based routes, makeAxis

This commit is contained in:
Brad Davis 2015-10-21 23:58:36 -07:00
parent 7c746462fa
commit 4938e5ea84
7 changed files with 46 additions and 18 deletions

View file

@ -4,10 +4,29 @@ ControllerTest = function() {
this.mappingEnabled = false;
this.mapping = Controller.newMapping();
this.mapping.from(standard.RX).to(actions.StepYaw);
this.mapping.from(standard.RY).invert().to(actions.Pitch);
var testMakeAxis = false;
if (testMakeAxis) {
this.mapping.makeAxis(standard.LB, standard.RB).pulse(0.25).scale(40.0).to(actions.StepYaw);
}
var testStepYaw = false;
if (!testMakeAxis && testStepYaw){
this.mapping.from(standard.LB).pulse(0.10).invert().scale(40.0).to(actions.StepYaw);
this.mapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
}
var testFunctionSource = false;
if (testFunctionSource) {
this.mapping.fromFunction(function(){
return Math.sin(Date.now() / 250);
}).to(actions.Yaw);
}
this.mapping.enable();
this.mappingEnabled = true;
print("Actions");
for (var prop in Controller.Actions) {
print("\t" + prop);

View file

@ -26,10 +26,13 @@ HifiControls.VrDialog {
function buildMapping() {
testMapping = Controller.newMapping();
testMapping.from(standard.RY).invert().to(actions.Pitch);
testMapping.fromQmlFunction(function(){
return Math.sin(Date.now() / 250);
}).to(actions.Yaw);
//testMapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
// Step yaw takes a number of degrees
testMapping.from(standard.LB).invert().scale(15.0).to(actions.StepYaw);
testMapping.from(standard.RB).scale(15.0).to(actions.StepYaw);
testMapping.from(standard.LB).pulse(0.10).invert().scale(40.0).to(actions.StepYaw);
testMapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
testMapping.from(standard.RX).scale(15.0).to(actions.StepYaw);
}

View file

@ -10,10 +10,9 @@
namespace controller {
const Input Input::INVALID_INPUT = Input(UINT32_MAX);
const uint16_t Input::INVALID_DEVICE = INVALID_INPUT.getDevice();
const uint16_t Input::INVALID_CHANNEL = INVALID_INPUT.getChannel();
const uint16_t Input::INVALID_TYPE = (uint16_t)INVALID_INPUT.getType();
const uint16_t Input::INVALID_DEVICE = 0xffff;
const uint16_t Input::INVALID_CHANNEL = 0x1fff;
const uint16_t Input::INVALID_TYPE = (uint16_t)ChannelType::INVALID;
const Input Input::INVALID_INPUT = Input(INVALID_DEVICE, INVALID_CHANNEL, ChannelType::INVALID);
}

View file

@ -16,7 +16,7 @@
namespace controller {
enum class ChannelType {
UNKNOWN = 0,
INVALID = 0,
BUTTON = 1,
AXIS,
POSE,

View file

@ -145,10 +145,17 @@ void ScriptEndpoint::internalApply(float newValue, float oldValue, int sourceID)
QScriptValueList({ QScriptValue(newValue), QScriptValue(oldValue), QScriptValue(sourceID) }));
}
static const Input INVALID_STANDARD_INPUT = Input(UserInputMapper::STANDARD_DEVICE, Input::INVALID_CHANNEL, ChannelType::INVALID);
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
public:
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
: Endpoint(Input::INVALID_INPUT), Pair(first, second) { }
: Endpoint(Input::INVALID_INPUT), Pair(first, second) {
if (first->getInput().device == UserInputMapper::STANDARD_DEVICE &&
second->getInput().device == UserInputMapper::STANDARD_DEVICE) {
this->_input = INVALID_STANDARD_INPUT;
}
}
virtual float value() {
float result = first->value() * -1.0f + second->value();

View file

@ -26,13 +26,13 @@ QObject* MappingBuilderProxy::from(int input) {
return from(sourceEndpoint);
}
QObject* MappingBuilderProxy::from(const QJSValue& source) {
QObject* MappingBuilderProxy::fromQmlFunction(const QJSValue& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
auto sourceEndpoint = _parent.endpointFor(source);
return from(sourceEndpoint);
}
QObject* MappingBuilderProxy::from(const QScriptValue& source) {
QObject* MappingBuilderProxy::fromFunction(const QScriptValue& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
auto sourceEndpoint = _parent.endpointFor(source);
return from(sourceEndpoint);
@ -49,9 +49,9 @@ QObject* MappingBuilderProxy::from(const Endpoint::Pointer& source) {
}
}
QObject* MappingBuilderProxy::makeAxis(const QJSValue& source1, const QJSValue& source2) {
auto source1Endpoint = _parent.endpointFor(source1);
auto source2Endpoint = _parent.endpointFor(source2);
QObject* MappingBuilderProxy::makeAxis(int source1, int source2) {
auto source1Endpoint = _parent.endpointFor(Input(source1));
auto source2Endpoint = _parent.endpointFor(Input(source2));
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
}

View file

@ -33,9 +33,9 @@ public:
: _parent(parent), _mapping(mapping) { }
Q_INVOKABLE QObject* from(int sourceInput);
Q_INVOKABLE QObject* from(const QJSValue& source);
Q_INVOKABLE QObject* from(const QScriptValue& source);
Q_INVOKABLE QObject* makeAxis(const QJSValue& source1, const QJSValue& source2);
Q_INVOKABLE QObject* fromQmlFunction(const QJSValue& source);
Q_INVOKABLE QObject* fromFunction(const QScriptValue& source);
Q_INVOKABLE QObject* makeAxis(int source1, const int source2);
Q_INVOKABLE QObject* enable(bool enable = true);
Q_INVOKABLE QObject* disable() { return enable(false); }