Commit 8849a2d7 authored by Don Gagne's avatar Don Gagne

Fix multi-joystick bugs and validation bug

parent e5a94ef2
...@@ -334,7 +334,7 @@ void Joystick::run(void) ...@@ -334,7 +334,7 @@ void Joystick::run(void)
_lastButtonBits = newButtonBits; _lastButtonBits = newButtonBits;
qCDebug(JoystickValuesLog) << "roll:pitch:yaw:throttle" << roll << -pitch << yaw << throttle; qCDebug(JoystickValuesLog) << "name:roll:pitch:yaw:throttle" << name() << roll << -pitch << yaw << throttle;
emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode()); emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode());
} }
......
...@@ -381,7 +381,16 @@ QGCView { ...@@ -381,7 +381,16 @@ QGCView {
width: parent.width - activeJoystickLabel.width - parent.spacing width: parent.width - activeJoystickLabel.width - parent.spacing
model: joystickManager.joystickNames model: joystickManager.joystickNames
onActivated: _activeJoystick.setActiveJoystickName(textAt(index)) onActivated: joystickManager.activeJoystickName = textAt(index)
Component.onCompleted: {
var index = joystickCombo.find(joystickManager.activeJoystickName)
if (index == -1) {
console.warn("Active joystick name not in combo", joystickManager.activeJoystickName)
} else {
joystickCombo.currentIndex = index
}
}
} }
} }
......
...@@ -54,8 +54,6 @@ const char* JoystickConfigController::_imageRollRight = "joystickRollRight.p ...@@ -54,8 +54,6 @@ const char* JoystickConfigController::_imageRollRight = "joystickRollRight.p
const char* JoystickConfigController::_imagePitchUp = "joystickPitchUp.png"; const char* JoystickConfigController::_imagePitchUp = "joystickPitchUp.png";
const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.png"; const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.png";
const char* JoystickConfigController::_settingsGroup = "Joysticks";
JoystickConfigController::JoystickConfigController(void) JoystickConfigController::JoystickConfigController(void)
: _activeJoystick(NULL) : _activeJoystick(NULL)
, _currentStep(-1) , _currentStep(-1)
...@@ -71,21 +69,17 @@ JoystickConfigController::JoystickConfigController(void) ...@@ -71,21 +69,17 @@ JoystickConfigController::JoystickConfigController(void)
connect(joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged); connect(joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged);
_activeJoystickChanged(joystickManager->activeJoystick()); _activeJoystickChanged(joystickManager->activeJoystick());
_loadSettings();
_resetInternalCalibrationValues(); _resetInternalCalibrationValues();
_activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor);
} }
void JoystickConfigController::start(void) void JoystickConfigController::start(void)
{ {
_stopCalibration(); _stopCalibration();
_setInternalCalibrationValuesFromSettings();
} }
JoystickConfigController::~JoystickConfigController() JoystickConfigController::~JoystickConfigController()
{ {
_activeJoystick->stopCalibrationMode(Joystick::CalibrationModeMonitor); _activeJoystick->stopCalibrationMode(Joystick::CalibrationModeMonitor);
_storeSettings();
} }
/// @brief Returns the state machine entry for the specified state. /// @brief Returns the state machine entry for the specified state.
...@@ -460,7 +454,7 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) ...@@ -460,7 +454,7 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void)
info->axisMax = calibration.max; info->axisMax = calibration.max;
info->reversed = calibration.reversed; info->reversed = calibration.reversed;
qCDebug(JoystickConfigControllerLog) << "Read settings axis:min:max:trim:reversed" << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed; qCDebug(JoystickConfigControllerLog) << "Read settings name:axis:min:max:trim:reversed" << joystick->name() << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed;
} }
for (int function=0; function<Joystick::maxFunction; function++) { for (int function=0; function<Joystick::maxFunction; function++) {
...@@ -484,30 +478,29 @@ void JoystickConfigController::_validateCalibration(void) ...@@ -484,30 +478,29 @@ void JoystickConfigController::_validateCalibration(void)
if (chan < _axisCount) { if (chan < _axisCount) {
// Validate Min/Max values. Although the axis appears as available we still may // Validate Min/Max values. Although the axis appears as available we still may
// not have good min/max/trim values for it. Set to defaults if needed. // not have good min/max/trim values for it. Set to defaults if needed.
if (info->axisMin > _calValidMinValue || info->axisMax < _calValidMaxValue) { if (info->axisMin < _calValidMinValue || info->axisMax > _calValidMaxValue) {
qCDebug(JoystickConfigControllerLog) << "_validateCalibration resetting axis" << chan; qCDebug(JoystickConfigControllerLog) << "_validateCalibration resetting axis" << chan;
info->axisMin = _calDefaultMinValue; info->axisMin = _calDefaultMinValue;
info->axisMax = _calDefaultMaxValue; info->axisMax = _calDefaultMaxValue;
info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2);
} else { }
switch (_rgAxisInfo[chan].function) {
case Joystick::throttleFunction: switch (_rgAxisInfo[chan].function) {
case Joystick::yawFunction: case Joystick::throttleFunction:
case Joystick::rollFunction: case Joystick::yawFunction:
case Joystick::pitchFunction: case Joystick::rollFunction:
// Make sure trim is within min/max case Joystick::pitchFunction:
if (info->axisTrim < info->axisMin) { // Make sure trim is within min/max
info->axisTrim = info->axisMin; if (info->axisTrim < info->axisMin) {
} else if (info->axisTrim > info->axisMax) { info->axisTrim = info->axisMin;
info->axisTrim = info->axisMax; } else if (info->axisTrim > info->axisMax) {
} info->axisTrim = info->axisMax;
break; }
default: break;
// Non-attitude control axiss have calculated trim default:
info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); // Non-attitude control axis have calculated trim
break; info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2);
} break;
} }
} else { } else {
// Unavailable axiss are set to defaults // Unavailable axiss are set to defaults
...@@ -610,20 +603,6 @@ void JoystickConfigController::_calSave(void) ...@@ -610,20 +603,6 @@ void JoystickConfigController::_calSave(void)
_validateCalibration(); _validateCalibration();
} }
void JoystickConfigController::_loadSettings(void)
{
QSettings settings;
settings.beginGroup(_settingsGroup);
}
void JoystickConfigController::_storeSettings(void)
{
QSettings settings;
settings.beginGroup(_settingsGroup);
}
void JoystickConfigController::_setHelpImage(const char* imageFile) void JoystickConfigController::_setHelpImage(const char* imageFile)
{ {
QString file = _imageFilePrefix; QString file = _imageFilePrefix;
...@@ -749,13 +728,20 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void) ...@@ -749,13 +728,20 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void)
void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) void JoystickConfigController::_activeJoystickChanged(Joystick* joystick)
{ {
bool joystickTransition = false;
if (_activeJoystick) { if (_activeJoystick) {
joystickTransition = true;
disconnect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged); disconnect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged);
_activeJoystick = NULL; _activeJoystick = NULL;
} }
if (joystick) { if (joystick) {
_activeJoystick = joystick; _activeJoystick = joystick;
if (joystickTransition) {
_stopCalibration();
}
_activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor);
connect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged); connect(_activeJoystick, &Joystick::rawAxisValueChanged, this, &JoystickConfigController::_axisValueChanged);
} }
} }
...@@ -197,9 +197,6 @@ private: ...@@ -197,9 +197,6 @@ private:
void _setHelpImage(const char* imageFile); void _setHelpImage(const char* imageFile);
void _loadSettings(void);
void _storeSettings(void);
void _signalAllAttiudeValueChanges(void); void _signalAllAttiudeValueChanges(void);
// Member variables // Member variables
...@@ -216,8 +213,6 @@ private: ...@@ -216,8 +213,6 @@ private:
static const char* _imagePitchUp; static const char* _imagePitchUp;
static const char* _imagePitchDown; static const char* _imagePitchDown;
static const char* _settingsGroup;
static const int _updateInterval; ///< Interval for ui update timer static const int _updateInterval; ///< Interval for ui update timer
int _rgFunctionAxisMapping[Joystick::maxFunction]; ///< Maps from joystick function to axis index. _axisMax indicates axis not set for this function. int _rgFunctionAxisMapping[Joystick::maxFunction]; ///< Maps from joystick function to axis index. _axisMax indicates axis not set for this function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment