Update connected device detection implementation

This commit is contained in:
Ryan Huffman 2016-06-21 16:37:58 -07:00
parent 0ea9c5c26d
commit da71fcb57f
9 changed files with 56 additions and 1 deletions

View file

@ -15,6 +15,7 @@
#include "Forward.h"
class Plugin : public QObject {
Q_OBJECT
public:
/// \return human-readable name
virtual const QString& getName() const = 0;
@ -63,6 +64,13 @@ public:
virtual void saveSettings() const {}
virtual void loadSettings() {}
signals:
// These signals should be emitted when a device is first known to be available. In some cases this will
// be in `init()`, in other cases, like Neuron, this isn't known until activation.
// SDL2 isn't a device itself, but can have 0+ subdevices. subdeviceConnected is used in this case.
void deviceConnected(QString pluginName) const;
void subdeviceConnected(QString pluginName, QString subdeviceName) const;
protected:
bool _active { false };
PluginContainer* _container { nullptr };

View file

@ -69,6 +69,15 @@ static DisplayPluginList displayPlugins;
const DisplayPluginList& PluginManager::getDisplayPlugins() {
static std::once_flag once;
static auto deviceAddedCallback = [](QString deviceName) {
qDebug() << "Added device: " << deviceName;
UserActivityLogger::getInstance().connectedDevice("display", deviceName);
};
static auto subdeviceAddedCallback = [](QString pluginName, QString deviceName) {
qDebug() << "Added subdevice: " << deviceName;
UserActivityLogger::getInstance().connectedDevice("display", pluginName + " | " + deviceName);
};
std::call_once(once, [&] {
// Grab the built in plugins
displayPlugins = ::getDisplayPlugins();
@ -84,7 +93,8 @@ const DisplayPluginList& PluginManager::getDisplayPlugins() {
}
auto& container = PluginContainer::getInstance();
for (auto plugin : displayPlugins) {
UserActivityLogger::getInstance().connectedDevice("display", plugin->getName());
connect(plugin.get(), &Plugin::deviceConnected, this, deviceAddedCallback);
connect(plugin.get(), &Plugin::subdeviceConnected, this, subdeviceAddedCallback);
plugin->setContainer(&container);
plugin->init();
}
@ -106,6 +116,15 @@ void PluginManager::disableDisplayPlugin(const QString& name) {
const InputPluginList& PluginManager::getInputPlugins() {
static InputPluginList inputPlugins;
static std::once_flag once;
static auto deviceAddedCallback = [](QString deviceName) {
qDebug() << "Added device: " << deviceName;
UserActivityLogger::getInstance().connectedDevice("input", deviceName);
};
static auto subdeviceAddedCallback = [](QString pluginName, QString deviceName) {
qDebug() << "Added subdevice: " << deviceName;
UserActivityLogger::getInstance().connectedDevice("input", pluginName + " | " + deviceName);
};
std::call_once(once, [&] {
inputPlugins = ::getInputPlugins();
@ -122,6 +141,8 @@ const InputPluginList& PluginManager::getInputPlugins() {
auto& container = PluginContainer::getInstance();
for (auto plugin : inputPlugins) {
UserActivityLogger::getInstance().connectedDevice("input", plugin->getName());
connect(plugin.get(), &Plugin::deviceConnected, this, deviceAddedCallback);
connect(plugin.get(), &Plugin::subdeviceConnected, this, subdeviceAddedCallback);
plugin->setContainer(&container);
plugin->init();
}

View file

@ -387,6 +387,8 @@ bool NeuronPlugin::activate() {
} else {
qCDebug(inputplugins) << "NeuronPlugin: success connecting to " << _serverAddress.c_str() << ":" << _serverPort;
emit deviceConnected(getName());
BRRegisterAutoSyncParmeter(_socketRef, Cmd_CombinationMode);
return true;
}

View file

@ -66,6 +66,7 @@ void SDL2Manager::init() {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->registerDevice(joystick);
emit joystickAdded(joystick.get());
emit subdeviceConnected(getName(), SDL_GameControllerName(controller));
}
}
}
@ -157,6 +158,7 @@ void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrati
_openJoysticks[id] = joystick;
userInputMapper->registerDevice(joystick);
emit joystickAdded(joystick.get());
emit subdeviceConnected(getName(), SDL_GameControllerName(controller));
}
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
if (_openJoysticks.contains(event.cdevice.which)) {

View file

@ -137,6 +137,12 @@ void SixenseManager::setSixenseFilter(bool filter) {
void SixenseManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
BAIL_IF_NOT_LOADED
static bool sixenseHasBeenConnected { false };
if (!sixenseHasBeenConnected && sixenseIsBaseConnected(0)) {
sixenseHasBeenConnected = true;
emit deviceConnected(getName());
}
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->withLock([&, this]() {
_inputDevice->update(deltaTime, inputCalibrationData);

View file

@ -28,6 +28,12 @@ bool OculusDisplayPlugin::internalActivate() {
return result;
}
void OculusDisplayPlugin::init() {
Plugin::init();
emit deviceConnected(getName());
}
void OculusDisplayPlugin::cycleDebugOutput() {
if (_session) {
currentDebugMode = static_cast<ovrPerfHudMode>((currentDebugMode + 1) % ovrPerfHud_Count);

View file

@ -17,6 +17,8 @@ class OculusDisplayPlugin : public OculusBaseDisplayPlugin {
public:
const QString& getName() const override { return NAME; }
void init() override;
QString getPreferredAudioInDevice() const override;
QString getPreferredAudioOutDevice() const override;

View file

@ -41,6 +41,12 @@ bool OpenVrDisplayPlugin::isSupported() const {
return openVrSupported();
}
void OpenVrDisplayPlugin::init() {
Plugin::init();
emit deviceConnected(getName());
}
bool OpenVrDisplayPlugin::internalActivate() {
_container->setIsOptionChecked(StandingHMDSensorMode, true);

View file

@ -21,6 +21,8 @@ public:
bool isSupported() const override;
const QString& getName() const override { return NAME; }
void init() override;
float getTargetFrameRate() const override { return TARGET_RATE_OpenVr; }
void customizeContext() override;