Introduce the concept of loading the default Mapping

This commit is contained in:
samcake 2015-10-29 13:05:29 -07:00
parent 8f908f9877
commit e902e5e97a
3 changed files with 26 additions and 0 deletions

View file

@ -648,6 +648,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

@ -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;