Merge pull request #6222 from ZappoMan/hardwareChanged

Handle input plugin register/remove when activated/deactivated by menus
This commit is contained in:
Brad Davis 2015-10-29 12:24:17 -07:00
commit f21633e368
7 changed files with 55 additions and 10 deletions

View file

@ -91,5 +91,11 @@ Object.keys(Controller.Actions).forEach(function (actionName) {
Controller.hardwareChanged.connect(function () {
print("hardwareChanged");
print("hardwareChanged ---------------------------------------------------");
Object.keys(Controller.Hardware).forEach(function (deviceName) {
Object.keys(Controller.Hardware[deviceName]).forEach(function (input) {
print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]);
});
});
print("-------------------------------------------------------------------");
});

View file

@ -204,25 +204,24 @@ namespace controller {
}
void ScriptingInterface::updateMaps() {
QVariantMap newHardware;
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
auto devices = userInputMapper->getDevices();
QSet<QString> foundDevices;
for (const auto& deviceMapping : devices) {
auto deviceID = deviceMapping.first;
if (deviceID != userInputMapper->getStandardDeviceID()) {
auto device = deviceMapping.second;
auto deviceName = QString(device->getName()).remove(SANITIZE_NAME_EXPRESSION);
qCDebug(controllers) << "Device" << deviceMapping.first << ":" << deviceName;
foundDevices.insert(device->getName());
if (_hardware.contains(deviceName)) {
if (newHardware.contains(deviceName)) {
continue;
}
// Expose the IDs to JS
_hardware.insert(deviceName, createDeviceMap(device));
newHardware.insert(deviceName, createDeviceMap(device));
}
}
_hardware = newHardware;
}

View file

@ -74,6 +74,27 @@ void SDL2Manager::deinit() {
#endif
}
void SDL2Manager::activate() {
#ifdef HAVE_SDL2
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
for (auto joystick : _openJoysticks) {
userInputMapper->registerDevice(joystick);
emit joystickAdded(joystick.get());
}
#endif
}
void SDL2Manager::deactivate() {
#ifdef HAVE_SDL2
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
for (auto joystick : _openJoysticks) {
userInputMapper->removeDevice(joystick->getDeviceID());
emit joystickRemoved(joystick.get());
}
#endif
}
bool SDL2Manager::isSupported() const {
#ifdef HAVE_SDL2
return true;

View file

@ -34,7 +34,12 @@ public:
virtual void init() override;
virtual void deinit() override;
/// Called when a plugin is being activated for use. May be called multiple times.
virtual void activate() override;
/// Called when a plugin is no longer being used. May be called multiple times.
virtual void deactivate() override;
virtual void pluginFocusOutEvent() override;
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override;

View file

@ -126,6 +126,7 @@ void SixenseManager::activate() {
void SixenseManager::deactivate() {
InputPlugin::deactivate();
#ifdef HAVE_SIXENSE
CONTAINER->removeMenuItem(MENU_NAME, TOGGLE_SMOOTH);
CONTAINER->removeMenu(MENU_PATH);
@ -136,7 +137,6 @@ void SixenseManager::deactivate() {
if (_deviceID != controller::Input::INVALID_DEVICE) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->removeDevice(_deviceID);
_deviceID = controller::Input::INVALID_DEVICE;
}
#ifdef __APPLE__

View file

@ -135,6 +135,11 @@ void ViveControllerManager::activate() {
_renderControllers = true;
}
#endif
// unregister with UserInputMapper
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->registerDevice(instance);
_registeredWithInputMapper = true;
}
void ViveControllerManager::deactivate() {
@ -152,6 +157,11 @@ void ViveControllerManager::deactivate() {
}
_poseStateMap.clear();
#endif
// unregister with UserInputMapper
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->removeDevice(_deviceID);
_registeredWithInputMapper = false;
}
void ViveControllerManager::updateRendering(RenderArgs* args, render::ScenePointer scene, render::PendingChanges pendingChanges) {
@ -272,15 +282,16 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
if (numTrackedControllers == 0) {
if (_deviceID != 0) {
if (_registeredWithInputMapper) {
userInputMapper->removeDevice(_deviceID);
_deviceID = 0;
_registeredWithInputMapper = false;
_poseStateMap.clear();
}
}
if (_trackedControllers == 0 && numTrackedControllers > 0) {
userInputMapper->registerDevice(instance);
_registeredWithInputMapper = true;
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "steamVR");
}

View file

@ -69,6 +69,9 @@ private:
bool _renderControllers;
static const QString NAME;
bool _registeredWithInputMapper { false };
};
#endif // hifi__ViveControllerManager