Merge pull request #6230 from samcake/controllers

Controllers : Comfort mode is working through the stanadrd mapping
This commit is contained in:
Brad Hefta-Gaub 2015-10-29 14:59:42 -07:00
commit c962697b18
6 changed files with 43 additions and 6 deletions

View file

@ -3,6 +3,7 @@
"channels": [
{ "from": "Standard.LY", "to": "Actions.TranslateZ" },
{ "from": "Standard.LX", "to": "Actions.TranslateX" },
{ "from": "Standard.RX", "when": [ "Application.InHMD", "Application.ComfortMode" ], "to": "Actions.StepYaw" },
{ "from": "Standard.RX", "to": "Actions.Yaw" },
{ "from": "Standard.RY", "to": "Actions.Pitch" },

View file

@ -637,10 +637,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// A new controllerInput device used to reflect current values from the application state
_applicationStateDevice = std::make_shared<controller::StateController>();
auto InHMDLambda = controller::StateController::ReadLambda([]() -> float {
return (float) qApp->getAvatarUpdater()->isHMDMode();
});
_applicationStateDevice->addInputVariant("InHMD", InHMDLambda);
_applicationStateDevice->addInputVariant(QString("InHMD"), controller::StateController::ReadLambda([]() -> float {
return (float)qApp->getAvatarUpdater()->isHMDMode();
}));
_applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float {
return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode);
}));
userInputMapper->registerDevice(_applicationStateDevice);
@ -648,6 +651,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
userInputMapper->registerDevice(_keyboardMouseDevice);
userInputMapper->loadDefaultMapping(userInputMapper->getStandardDeviceID());
// check first run...
if (_firstRun.get()) {
qCDebug(interfaceapp) << "This is a first run...";

View file

@ -29,7 +29,7 @@ void StateController::update(float deltaTime, bool jointsCaptured) {}
void StateController::focusOutEvent() {}
void StateController::addInputVariant(QString name, ReadLambda& lambda) {
void StateController::addInputVariant(QString name, ReadLambda lambda) {
_namedReadLambdas.push_back(NamedReadLambda(name, lambda));
}
@ -43,4 +43,8 @@ Input::NamedVector StateController::getAvailableInputs() const {
return availableInputs;
}
EndpointPointer StateController::createEndpoint(const Input& input) const {
return std::make_shared<LambdaEndpoint>(_namedReadLambdas[input.getChannel()].second);
}
}

View file

@ -37,7 +37,10 @@ public:
using ReadLambda = std::function<float()>;
using NamedReadLambda = QPair<QString, ReadLambda>;
void addInputVariant(QString name, ReadLambda& lambda);
void addInputVariant(QString name, ReadLambda lambda);
virtual EndpointPointer createEndpoint(const Input& input) const override;
protected:
QVector<NamedReadLambda> _namedReadLambdas;

View file

@ -129,6 +129,27 @@ void UserInputMapper::removeDevice(int deviceID) {
}
void UserInputMapper::loadDefaultMapping(uint16 deviceID) {
Locker locker(_lock);
auto proxyEntry = _registeredDevices.find(deviceID);
if (_registeredDevices.end() == proxyEntry) {
qCWarning(controllers) << "Unknown deviceID " << deviceID;
return;
}
auto mapping = loadMapping(proxyEntry->second->getDefaultMappingConfig());
if (mapping) {
auto prevMapping = _mappingsByDevice[deviceID];
disableMapping(prevMapping);
_mappingsByDevice[deviceID] = mapping;
enableMapping(mapping);
}
emit hardwareChanged();
}
InputDevice::Pointer UserInputMapper::getDevice(const Input& input) {
Locker locker(_lock);
auto device = _registeredDevices.find(input.getDevice());
@ -711,6 +732,8 @@ Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile) {
return parseMapping(json);
}
static const QString JSON_NAME = QStringLiteral("name");
static const QString JSON_CHANNELS = QStringLiteral("channels");
static const QString JSON_CHANNEL_FROM = QStringLiteral("from");

View file

@ -108,6 +108,7 @@ namespace controller {
MappingPointer parseMapping(const QString& json);
MappingPointer loadMapping(const QString& jsonFile);
void loadDefaultMapping(uint16 deviceID);
void enableMapping(const QString& mappingName, bool enable = true);
float getValue(const Input& input) const;
Pose getPose(const Input& input) const;