Merge branch 'controllers' of https://github.com/highfidelity/hifi into myAvatarPalmTweaks

This commit is contained in:
Brad Hefta-Gaub 2015-10-27 16:47:36 -07:00
commit 7f313e7f86
2 changed files with 28 additions and 33 deletions

View file

@ -67,11 +67,7 @@ const float DEFAULT_REACH_LENGTH = 1.5f;
SixenseManager::SixenseManager() : SixenseManager::SixenseManager() :
InputDevice("Hydra"), InputDevice("Hydra"),
_reachLength(DEFAULT_REACH_LENGTH), _reachLength(DEFAULT_REACH_LENGTH)
#ifdef __APPLE__
_sixenseLibrary(nullptr),
#endif
_hydrasConnected(false)
{ {
} }
@ -94,6 +90,9 @@ void SixenseManager::activate() {
[this] (bool clicked) { this->setSixenseFilter(clicked); }, [this] (bool clicked) { this->setSixenseFilter(clicked); },
true, true); true, true);
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->registerDevice(this);
#ifdef __APPLE__ #ifdef __APPLE__
if (!_sixenseLibrary) { if (!_sixenseLibrary) {
@ -121,9 +120,6 @@ void SixenseManager::activate() {
#endif #endif
loadSettings(); loadSettings();
sixenseInit(); sixenseInit();
_activated = true;
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->registerDevice(this);
#endif #endif
} }
@ -134,13 +130,19 @@ void SixenseManager::deactivate() {
CONTAINER->removeMenu(MENU_PATH); CONTAINER->removeMenu(MENU_PATH);
_poseStateMap.clear(); _poseStateMap.clear();
_collectedSamples.clear();
if (_deviceID != controller::Input::INVALID_DEVICE) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->removeDevice(_deviceID);
_deviceID = controller::Input::INVALID_DEVICE;
}
#ifdef __APPLE__ #ifdef __APPLE__
SixenseBaseFunction sixenseExit = (SixenseBaseFunction)_sixenseLibrary->resolve("sixenseExit"); SixenseBaseFunction sixenseExit = (SixenseBaseFunction)_sixenseLibrary->resolve("sixenseExit");
#endif #endif
sixenseExit(); sixenseExit();
_activated = false;
#ifdef __APPLE__ #ifdef __APPLE__
delete _sixenseLibrary; delete _sixenseLibrary;
@ -176,30 +178,32 @@ void SixenseManager::update(float deltaTime, bool jointsCaptured) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
static const float MAX_DISCONNECTED_TIME = 2.0f;
static bool disconnected { false };
static float disconnectedInterval { 0.0f };
if (sixenseGetNumActiveControllers() == 0) { if (sixenseGetNumActiveControllers() == 0) {
if (_hydrasConnected) { if (!disconnected) {
qCDebug(inputplugins) << "hydra disconnected" << _badDataCount; disconnectedInterval += deltaTime;
if (_badDataCount++ < _allowedBadDataCount) { // gotta get some no-active in a row before we shut things down
return;
}
} }
_hydrasConnected = false; if (disconnectedInterval > MAX_DISCONNECTED_TIME) {
if (_deviceID != 0) { disconnected = true;
userInputMapper->removeDevice(_deviceID); _axisStateMap.clear();
_deviceID = 0; _buttonPressedMap.clear();
_poseStateMap.clear(); _poseStateMap.clear();
_collectedSamples.clear(); _collectedSamples.clear();
} }
return; return;
} }
PerformanceTimer perfTimer("sixense"); if (disconnected) {
if (!_hydrasConnected) { disconnected = 0;
_hydrasConnected = true; disconnectedInterval = 0.0f;
_badDataCount = 0;
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra");
} }
PerformanceTimer perfTimer("sixense");
// FIXME send this message once when we've positively identified hydra hardware
//UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra");
#ifdef __APPLE__ #ifdef __APPLE__
SixenseBaseFunction sixenseGetMaxControllers = SixenseBaseFunction sixenseGetMaxControllers =
(SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetMaxControllers"); (SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetMaxControllers");
@ -600,7 +604,6 @@ void SixenseManager::saveSettings() const {
settings.setVec3Value(QString("avatarPosition"), _avatarPosition); settings.setVec3Value(QString("avatarPosition"), _avatarPosition);
settings.setQuatValue(QString("avatarRotation"), _avatarRotation); settings.setQuatValue(QString("avatarRotation"), _avatarRotation);
settings.setValue(QString("reachLength"), QVariant(_reachLength)); settings.setValue(QString("reachLength"), QVariant(_reachLength));
settings.setValue(QString("allowedHydraFailures"), 120);
} }
settings.endGroup(); settings.endGroup();
} }
@ -613,7 +616,6 @@ void SixenseManager::loadSettings() {
settings.getVec3ValueIfValid(QString("avatarPosition"), _avatarPosition); settings.getVec3ValueIfValid(QString("avatarPosition"), _avatarPosition);
settings.getQuatValueIfValid(QString("avatarRotation"), _avatarRotation); settings.getQuatValueIfValid(QString("avatarRotation"), _avatarRotation);
settings.getFloatValueIfValid(QString("reachLength"), _reachLength); settings.getFloatValueIfValid(QString("reachLength"), _reachLength);
_allowedBadDataCount = settings.value(QString("allowedHydraFailures"), 120).toInt();
} }
settings.endGroup(); settings.endGroup();
} }

View file

@ -104,18 +104,11 @@ private:
MovingAverageMap _collectedSamples; MovingAverageMap _collectedSamples;
#ifdef __APPLE__ #ifdef __APPLE__
QLibrary* _sixenseLibrary; QLibrary* _sixenseLibrary { nullptr };
#endif #endif
bool _hydrasConnected;
int _badDataCount;
int _allowedBadDataCount;
static const QString NAME; static const QString NAME;
static const QString HYDRA_ID_STRING; static const QString HYDRA_ID_STRING;
bool _activated = false;
}; };
#endif // hifi_SixenseManager_h #endif // hifi_SixenseManager_h