|
|
@ -55,10 +55,22 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox) |
|
|
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); |
|
|
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void JoystickManager::discoverJoysticks() |
|
|
|
void JoystickManager::init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (JoystickSDL::init()) { |
|
|
|
|
|
|
|
_setActiveJoystickFromSettings(); |
|
|
|
|
|
|
|
connect(&_joystickCheckTimer, &QTimer::timeout, this, &JoystickManager::_updateAvailableJoysticks); |
|
|
|
|
|
|
|
_joystickCheckTimer.start(250); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JoystickManager::_setActiveJoystickFromSettings(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QMap<QString,Joystick*> newMap; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __sdljoystick__ |
|
|
|
#ifdef __sdljoystick__ |
|
|
|
_name2JoystickMap = JoystickSDL::discover(_multiVehicleManager); |
|
|
|
// Get the latest joystick mapping
|
|
|
|
|
|
|
|
newMap = JoystickSDL::discover(_multiVehicleManager); |
|
|
|
#elif defined(__android__) |
|
|
|
#elif defined(__android__) |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Android Joystick not yet supported |
|
|
|
* Android Joystick not yet supported |
|
|
@ -66,16 +78,30 @@ void JoystickManager::discoverJoysticks() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (!_name2JoystickMap.count()) { |
|
|
|
// Check to see if our current mapping contains any joysticks that are not in the new mapping
|
|
|
|
qCDebug(JoystickManagerLog) << "\tnone found"; |
|
|
|
// If so, those joysticks have been unplugged, and need to be cleaned up
|
|
|
|
return; |
|
|
|
QMap<QString, Joystick*>::iterator i; |
|
|
|
|
|
|
|
for (i = _name2JoystickMap.begin(); i != _name2JoystickMap.end(); ++i) { |
|
|
|
|
|
|
|
if (!newMap.contains(i.key())) { |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "Releasing joystick:" << i.key(); |
|
|
|
|
|
|
|
if (_activeJoystick && !newMap.contains(_activeJoystick->name())) { |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "\twas active"; |
|
|
|
|
|
|
|
_activeJoystick->stopPolling(); |
|
|
|
|
|
|
|
_activeJoystick = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// FIXME: Don't leave this hanging! We need to free the object.
|
|
|
|
|
|
|
|
//i.value()->deleteLater();
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_setActiveJoystickFromSettings(); |
|
|
|
_name2JoystickMap = newMap; |
|
|
|
|
|
|
|
emit availableJoysticksChanged(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_name2JoystickMap.count()) { |
|
|
|
|
|
|
|
setActiveJoystick(NULL); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void JoystickManager::_setActiveJoystickFromSettings(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QSettings settings; |
|
|
|
QSettings settings; |
|
|
|
|
|
|
|
|
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
@ -98,23 +124,30 @@ void JoystickManager::setActiveJoystick(Joystick* joystick) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QSettings settings; |
|
|
|
QSettings settings; |
|
|
|
|
|
|
|
|
|
|
|
if (!_name2JoystickMap.contains(joystick->name())) { |
|
|
|
if (joystick != NULL && !_name2JoystickMap.contains(joystick->name())) { |
|
|
|
qCWarning(JoystickManagerLog) << "Set active not in map" << joystick->name(); |
|
|
|
qCWarning(JoystickManagerLog) << "Set active not in map" << joystick->name(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_activeJoystick == joystick) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_activeJoystick) { |
|
|
|
if (_activeJoystick) { |
|
|
|
_activeJoystick->stopPolling(); |
|
|
|
_activeJoystick->stopPolling(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_activeJoystick = joystick; |
|
|
|
_activeJoystick = joystick; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_activeJoystick != NULL) { |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "Set active:" << _activeJoystick->name(); |
|
|
|
|
|
|
|
|
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); |
|
|
|
settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); |
|
|
|
|
|
|
|
|
|
|
|
emit activeJoystickChanged(_activeJoystick); |
|
|
|
emit activeJoystickChanged(_activeJoystick); |
|
|
|
emit activeJoystickNameChanged(_activeJoystick->name()); |
|
|
|
emit activeJoystickNameChanged(_activeJoystick->name()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QVariantList JoystickManager::joysticks(void) |
|
|
|
QVariantList JoystickManager::joysticks(void) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -146,3 +179,25 @@ void JoystickManager::setActiveJoystickName(const QString& name) |
|
|
|
|
|
|
|
|
|
|
|
setActiveJoystick(_name2JoystickMap[name]); |
|
|
|
setActiveJoystick(_name2JoystickMap[name]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JoystickManager::_updateAvailableJoysticks(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SDL_Event event; |
|
|
|
|
|
|
|
while (SDL_PollEvent(&event)) { |
|
|
|
|
|
|
|
switch(event.type) { |
|
|
|
|
|
|
|
case SDL_QUIT: |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "SDL ERROR:" << SDL_GetError(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case SDL_JOYDEVICEADDED: |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "Joystick added:" << event.jdevice.which; |
|
|
|
|
|
|
|
_setActiveJoystickFromSettings(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case SDL_JOYDEVICEREMOVED: |
|
|
|
|
|
|
|
qCDebug(JoystickManagerLog) << "Joystick removed:" << event.jdevice.which; |
|
|
|
|
|
|
|
_setActiveJoystickFromSettings(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|