Commit 184af37c authored by Don Gagne's avatar Don Gagne

Joystick message fixes

When on Joystick config page:
- Not calibrating: If joystick is enabled, joystick messages should
continue to go to vehicle
parent d14444a5
......@@ -57,10 +57,9 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
: _sdlIndex(sdlIndex)
, _exitThread(false)
, _name(name)
, _calibrated(false)
, _calibrating(false)
, _axisCount(axisCount)
, _buttonCount(buttonCount)
, _calibrationMode(CalibrationModeOff)
, _lastButtonBits(0)
, _throttleMode(ThrottleModeCenterZero)
, _activeVehicle(NULL)
......@@ -273,7 +272,7 @@ void Joystick::run(void)
}
}
if (_calibrated && !_calibrating) {
if (_calibrationMode != CalibrationModeCalibrating) {
int axis = _rgFunctionAxis[rollFunction];
float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]);
......@@ -355,8 +354,14 @@ void Joystick::run(void)
void Joystick::startPolling(Vehicle* vehicle)
{
if (isRunning()) {
if (_calibrating && vehicle != _activeVehicle) {
if (vehicle != _activeVehicle) {
// Joystick was previously disabled, but now enabled from config screen
if (_calibrationMode == CalibrationModeOff) {
qWarning() << "Incorrect usage pattern";
return;
}
_activeVehicle = vehicle;
_pollingStartedForCalibration = false;
}
......@@ -489,9 +494,14 @@ void Joystick::setThrottleMode(int mode)
emit throttleModeChanged(_throttleMode);
}
void Joystick::startCalibration(void)
void Joystick::startCalibrationMode(CalibrationMode_t mode)
{
_calibrating = true;
if (mode == CalibrationModeOff) {
qWarning() << "Incorrect mode CalibrationModeOff";
return;
}
_calibrationMode = mode;
if (!isRunning()) {
_pollingStartedForCalibration = true;
......@@ -499,11 +509,20 @@ void Joystick::startCalibration(void)
}
}
void Joystick::stopCalibration(void)
void Joystick::stopCalibrationMode(CalibrationMode_t mode)
{
if (_calibrating) {
_calibrating = false;
if (mode == CalibrationModeOff) {
qWarning() << "Incorrect mode: CalibrationModeOff";
return;
} else if (mode != _calibrationMode) {
qWarning() << "Incorrect mode sequence request:active" << mode << _calibrationMode;
return;
}
if (mode == CalibrationModeCalibrating) {
_calibrationMode = CalibrationModeMonitor;
} else {
_calibrationMode = CalibrationModeOff;
if (_pollingStartedForCalibration) {
stopPolling();
}
......
......@@ -96,11 +96,17 @@ public:
int throttleMode(void);
void setThrottleMode(int mode);
/// Calibration is about to start
void startCalibration(void);
typedef enum {
CalibrationModeOff, // Not calibrating
CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling
CalibrationModeCalibrating, // Calibrating, stop sending joystick to vehicle
} CalibrationMode_t;
/// Set the current calibration mode
void startCalibrationMode(CalibrationMode_t mode);
/// Calibration has ended
void stopCalibration(void);
/// Clear the current calibration mode
void stopCalibrationMode(CalibrationMode_t mode);
signals:
void calibratedChanged(bool calibrated);
......@@ -140,10 +146,11 @@ private:
QString _name;
bool _calibrated;
bool _calibrating;
int _axisCount;
int _buttonCount;
CalibrationMode_t _calibrationMode;
static const int _cAxes = 4;
int _rgAxisValues[_cAxes];
Calibration_t _rgCalibration[_cAxes];
......
......@@ -73,7 +73,7 @@ JoystickConfigController::JoystickConfigController(void)
_activeJoystickChanged(joystickManager->activeJoystick());
_loadSettings();
_resetInternalCalibrationValues();
_activeJoystick->startCalibration();
_activeJoystick->startCalibrationMode(Joystick::CalibrationModeMonitor);
}
void JoystickConfigController::start(void)
......@@ -84,7 +84,7 @@ void JoystickConfigController::start(void)
JoystickConfigController::~JoystickConfigController()
{
_activeJoystick->stopCalibration();
_activeJoystick->stopCalibrationMode(Joystick::CalibrationModeMonitor);
_storeSettings();
}
......@@ -548,6 +548,7 @@ void JoystickConfigController::_startCalibration(void)
{
Q_ASSERT(_axisCount >= _axisMinimum);
_activeJoystick->startCalibrationMode(Joystick::CalibrationModeCalibrating);
_resetInternalCalibrationValues();
_nextButton->setProperty("text", "Next");
......@@ -562,6 +563,7 @@ void JoystickConfigController::_stopCalibration(void)
{
_currentStep = -1;
_activeJoystick->stopCalibrationMode(Joystick::CalibrationModeCalibrating);
_setInternalCalibrationValuesFromSettings();
_statusText->setProperty("text", "");
......
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