3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-26 11:15:23 +02:00

Removing overrides / loopback support, adding route debugging

This commit is contained in:
Brad Davis 2015-10-22 15:52:10 -07:00
parent d1da2f5aab
commit e40741b5cb
3 changed files with 39 additions and 28 deletions
libraries/controllers/src/controllers

View file

@ -24,6 +24,8 @@ namespace controller {
Endpoint::Pointer destination;
Conditional::Pointer conditional;
Filter::List filters;
QString json;
bool debug { false };
using Pointer = std::shared_ptr<Route>;
using List = std::list<Pointer>;

View file

@ -655,7 +655,6 @@ Input UserInputMapper::makeStandardInput(controller::StandardPoseChannel pose) {
void UserInputMapper::runMappings() {
static auto deviceNames = getDeviceNames();
_overrides.clear();
for (auto endpointEntry : this->_endpointsByInput) {
endpointEntry.second->reset();
@ -680,55 +679,55 @@ void UserInputMapper::runMappings() {
void UserInputMapper::applyRoute(const Route::Pointer& route) {
if (route->debug) {
qCDebug(controllers) << "Applying route " << route->json;
}
if (route->conditional) {
if (!route->conditional->satisfied()) {
if (route->debug) {
qCDebug(controllers) << "Conditional failed";
}
return;
}
}
auto source = route->source;
if (_overrides.count(source)) {
source = _overrides[source];
}
// Endpoints can only be read once (though a given mapping can route them to
// Most endpoints can only be read once (though a given mapping can route them to
// multiple places). Consider... If the default is to wire the A button to JUMP
// and someone else wires it to CONTEXT_MENU, I don't want both to occur when
// I press the button. The exception is if I'm wiring a control back to itself
// in order to adjust my interface, like inverting the Y axis on an analog stick
if (!source->readable()) {
if (route->debug) {
qCDebug(controllers) << "Source unreadable";
}
return;
}
auto input = source->getInput();
float value = source->value();
if (value != 0.0) {
int i = 0;
}
auto destination = route->destination;
// THis could happen if the route destination failed to create
// FIXME: Maybe do not create the route if the destination failed and avoid this case ?
if (!destination) {
if (route->debug) {
qCDebug(controllers) << "Bad Destination";
}
return;
}
// FIXME?, should come before or after the override logic?
if (!destination->writeable()) {
if (route->debug) {
qCDebug(controllers) << "Destination unwritable";
}
return;
}
// Only consume the input if the route isn't a loopback.
// This allows mappings like `mapping.from(xbox.RY).invert().to(xbox.RY);`
bool loopback = (source->getInput() == destination->getInput()) && (source->getInput() != Input::INVALID_INPUT);
// Each time we loop back we re-write the override
if (loopback) {
_overrides[source] = destination = std::make_shared<StandardEndpoint>(source->getInput());
}
// Fetch the value, may have been overriden by previous loopback routes
if (source->isPose()) {
if (route->debug) {
qCDebug(controllers) << "Applying pose";
}
Pose value = getPose(source);
// no filters yet for pose
destination->apply(value, Pose(), source);
@ -736,11 +735,18 @@ void UserInputMapper::applyRoute(const Route::Pointer& route) {
// Fetch the value, may have been overriden by previous loopback routes
float value = getValue(source);
if (route->debug) {
qCDebug(controllers) << "Value was " << value;
}
// Apply each of the filters.
for (const auto& filter : route->filters) {
value = filter->apply(value);
}
if (route->debug) {
qCDebug(controllers) << "Filtered value was " << value;
}
destination->apply(value, 0, source);
}
}
@ -850,11 +856,6 @@ void UserInputMapper::enableMapping(const QString& mappingName, bool enable) {
float UserInputMapper::getValue(const Endpoint::Pointer& endpoint) const {
Locker locker(_lock);
auto valuesIterator = _overrides.find(endpoint);
if (_overrides.end() != valuesIterator) {
return valuesIterator->second->value();
}
return endpoint->value();
}
@ -900,6 +901,7 @@ Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile) {
static const QString JSON_NAME = QStringLiteral("name");
static const QString JSON_CHANNELS = QStringLiteral("channels");
static const QString JSON_CHANNEL_FROM = QStringLiteral("from");
static const QString JSON_CHANNEL_DEBUG = QStringLiteral("debug");
static const QString JSON_CHANNEL_WHEN = QStringLiteral("when");
static const QString JSON_CHANNEL_TO = QStringLiteral("to");
static const QString JSON_CHANNEL_FILTERS = QStringLiteral("filters");
@ -1052,9 +1054,12 @@ Route::Pointer UserInputMapper::parseRoute(const QJsonValue& value) {
return Route::Pointer();
}
const auto& obj = value.toObject();
auto obj = value.toObject();
Route::Pointer result = std::make_shared<Route>();
result->json = QString(QJsonDocument(obj).toJson());
result->source = parseSource(obj[JSON_CHANNEL_FROM]);
result->debug = obj[JSON_CHANNEL_DEBUG].toBool();
if (!result->source) {
qWarning() << "Invalid route source " << obj[JSON_CHANNEL_FROM];
return Route::Pointer();
@ -1067,6 +1072,11 @@ Route::Pointer UserInputMapper::parseRoute(const QJsonValue& value) {
return Route::Pointer();
}
if (result->source == result->destination) {
qWarning() << "Loopback routes not supported " << obj;
return Route::Pointer();
}
if (obj.contains(JSON_CHANNEL_WHEN)) {
auto conditionalsValue = obj[JSON_CHANNEL_WHEN];
result->conditional = parseConditional(conditionalsValue);

View file

@ -165,7 +165,6 @@ namespace controller {
EndpointToInputMap _inputsByEndpoint;
EndpointPairMap _compositeEndpoints;
EndpointOverrideMap _overrides;
MappingNameMap _mappingsByName;
MappingDeviceMap _mappingsByDevice;