Commit cdde6b74 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #4470 from bluerobotics/calibration

Rework joystick calibration (2)
parents 7688c667 cc180856
......@@ -254,17 +254,6 @@
<file alias="radioThrottleDown.png">resources/calibration/mode2/radioThrottleDown.png</file>
<file alias="radioSwitchMinMax.png">resources/calibration/mode2/radioSwitchMinMax.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick">
<file alias="joystickCenter.png">resources/calibration/joystick/joystickCenter.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/joystickRollRight.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/joystickPitchUp.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/joystickPitchDown.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/joystickYawRight.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/joystickThrottleUp.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/joystickThrottleDown.png</file>
</qresource>
<qresource prefix="/db/mapping/joystick">
<file alias="gamecontrollerdb.txt">resources/SDL_GameControllerDB/gamecontrollerdb.txt</file>
</qresource>
......@@ -278,4 +267,48 @@
<qresource prefix="/opengl">
<file>resources/opengl/buglist.json</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode1">
<file alias="joystickCenter.png">resources/calibration/joystick/mode1/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode1/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode1/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode1/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode1/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode1/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode1/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode1/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode1/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode2">
<file alias="joystickCenter.png">resources/calibration/joystick/mode2/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode2/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode2/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode2/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode2/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode2/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode2/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode2/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode2/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode3">
<file alias="joystickCenter.png">resources/calibration/joystick/mode3/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode3/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode3/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode3/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode3/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode3/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode3/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode3/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode3/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode4">
<file alias="joystickCenter.png">resources/calibration/joystick/mode4/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode4/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode4/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode4/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode4/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode4/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode4/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode4/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode4/joystickYawRight.png</file>
</qresource>
</RCC>
......@@ -69,6 +69,8 @@ public:
// Overrides from FirmwarePlugin
int manualControlReservedButtonCount(void);
int defaultJoystickTXMode(void) final { return 3; }
bool supportsThrottleModeCenterZero(void);
bool supportsManualControl(void);
......
......@@ -106,6 +106,11 @@ int FirmwarePlugin::manualControlReservedButtonCount(void)
return -1;
}
int FirmwarePlugin::defaultJoystickTXMode(void)
{
return 2;
}
bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{
// By default, this is supported
......
......@@ -142,6 +142,10 @@ public:
/// @return -1: reserver all buttons, >0 number of buttons to reserve
virtual int manualControlReservedButtonCount(void);
/// Default tx mode to apply to joystick axes
/// TX modes are as outlined here: http://www.rc-airplane-world.com/rc-transmitter-modes.html
virtual int defaultJoystickTXMode(void);
/// Returns true if the vehicle and firmware supports the use of a throttle joystick that
/// is zero when centered. Typically not supported on vehicles that have bidirectional
/// throttle.
......
......@@ -18,13 +18,19 @@
QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog")
QGC_LOGGING_CATEGORY(JoystickValuesLog, "JoystickValuesLog")
const char* Joystick::_settingsGroup = "Joysticks";
const char* Joystick::_calibratedSettingsKey = "Calibrated1"; // Increment number to force recalibration
const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1";
const char* Joystick::_throttleModeSettingsKey = "ThrottleMode";
const char* Joystick::_exponentialSettingsKey = "Exponential";
const char* Joystick::_accumulatorSettingsKey = "Accumulator";
const char* Joystick::_deadbandSettingsKey = "Deadband";
const char* Joystick::_settingsGroup = "Joysticks";
const char* Joystick::_calibratedSettingsKey = "Calibrated2"; // Increment number to force recalibration
const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1";
const char* Joystick::_throttleModeSettingsKey = "ThrottleMode";
const char* Joystick::_exponentialSettingsKey = "Exponential";
const char* Joystick::_accumulatorSettingsKey = "Accumulator";
const char* Joystick::_deadbandSettingsKey = "Deadband";
const char* Joystick::_txModeSettingsKey = NULL;
const char* Joystick::_fixedWingTXModeSettingsKey = "TXMode_FixedWing";
const char* Joystick::_multiRotorTXModeSettingsKey = "TXMode_MultiRotor";
const char* Joystick::_roverTXModeSettingsKey = "TXMode_Rover";
const char* Joystick::_vtolTXModeSettingsKey = "TXMode_VTOL";
const char* Joystick::_submarineTXModeSettingsKey = "TXMode_Submarine";
const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"RollAxis",
......@@ -33,6 +39,8 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis"
};
int Joystick::_transmitterMode = 2;
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager)
: _exitThread(false)
, _name(name)
......@@ -67,6 +75,8 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
}
_loadSettings();
connect(_multiVehicleManager, &MultiVehicleManager::activeVehicleChanged, this, &Joystick::_activeVehicleChanged);
}
Joystick::~Joystick()
......@@ -76,11 +86,74 @@ Joystick::~Joystick()
delete _rgButtonValues;
}
void Joystick::_setDefaultCalibration(void) {
QSettings settings;
settings.beginGroup(_settingsGroup);
settings.beginGroup(_name);
_calibrated = settings.value(_calibratedSettingsKey, false).toBool();
// Only set default calibrations if we do not have a calibration for this gamecontroller
if(_calibrated) return;
for(int axis = 0; axis < _axisCount; axis++) {
Joystick::Calibration_t calibration;
_rgCalibration[axis] = calibration;
}
_rgCalibration[1].reversed = true;
_rgCalibration[3].reversed = true;
// Default TX Mode 2 axis assignments for gamecontrollers
_rgFunctionAxis[rollFunction] = 2;
_rgFunctionAxis[pitchFunction] = 3;
_rgFunctionAxis[yawFunction] = 0;
_rgFunctionAxis[throttleFunction] = 1;
_exponential = false;
_accumulator = false;
_deadband = false;
_throttleMode = ThrottleModeCenterZero;
_calibrated = true;
_saveSettings();
}
void Joystick::_activeVehicleChanged(Vehicle *activeVehicle)
{
if(activeVehicle) {
if(activeVehicle->fixedWing()) {
_txModeSettingsKey = _fixedWingTXModeSettingsKey;
} else if(activeVehicle->multiRotor()) {
_txModeSettingsKey = _multiRotorTXModeSettingsKey;
} else if(activeVehicle->rover()) {
_txModeSettingsKey = _roverTXModeSettingsKey;
} else if(activeVehicle->vtol()) {
_txModeSettingsKey = _vtolTXModeSettingsKey;
} else if(activeVehicle->sub()) {
_txModeSettingsKey = _submarineTXModeSettingsKey;
} else {
_txModeSettingsKey = NULL;
qWarning() << "No valid joystick TXmode settings key for selected vehicle";
return;
}
QSettings settings;
settings.beginGroup(_settingsGroup);
int mode = settings.value(_txModeSettingsKey, activeVehicle->firmwarePlugin()->defaultJoystickTXMode()).toInt();
setTXMode(mode);
}
}
void Joystick::_loadSettings(void)
{
QSettings settings;
settings.beginGroup(_settingsGroup);
if(_txModeSettingsKey)
_transmitterMode = settings.value(_txModeSettingsKey, 2).toInt();
settings.beginGroup(_name);
bool badSettings = false;
......@@ -96,7 +169,7 @@ void Joystick::_loadSettings(void)
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk);
badSettings |= !convertOk;
qCDebug(JoystickLog) << "_loadSettings calibrated:throttlemode:exponential:deadband:badsettings" << _calibrated << _throttleMode << _exponential << _deadband << badSettings;
qCDebug(JoystickLog) << "_loadSettings calibrated:txmode:throttlemode:exponential:deadband:badsettings" << _calibrated << _transmitterMode << _throttleMode << _exponential << _deadband << badSettings;
QString minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max");
......@@ -136,6 +209,10 @@ void Joystick::_loadSettings(void)
qCDebug(JoystickLog) << "_loadSettings function:axis:badsettings" << function << functionAxis << badSettings;
}
// FunctionAxis mappings are always stored in TX mode 2
// Remap to stored TX mode in settings
_remapAxes(2, _transmitterMode, _rgFunctionAxis);
for (int button=0; button<_totalButtonCount; button++) {
_rgButtonActions << settings.value(QString(_buttonActionSettingsKey).arg(button), QString()).toString();
qCDebug(JoystickLog) << "_loadSettings button:action" << button << _rgButtonActions[button];
......@@ -152,6 +229,12 @@ void Joystick::_saveSettings(void)
QSettings settings;
settings.beginGroup(_settingsGroup);
// Transmitter mode is static
// Save the mode we are using
if(_txModeSettingsKey)
settings.setValue(_txModeSettingsKey, _transmitterMode);
settings.beginGroup(_name);
settings.setValue(_calibratedSettingsKey, _calibrated);
......@@ -160,7 +243,7 @@ void Joystick::_saveSettings(void)
settings.setValue(_deadbandSettingsKey, _deadband);
settings.setValue(_throttleModeSettingsKey, _throttleMode);
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband" << _calibrated << _throttleMode << _deadband;
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband:txmode" << _calibrated << _throttleMode << _deadband << _transmitterMode;
QString minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max");
......@@ -187,8 +270,13 @@ void Joystick::_saveSettings(void)
<< calibration->deadband;
}
// Always save function Axis mappings in TX Mode 2
// Write mode 2 mappings without changing mapping currently in use
int temp[maxFunction];
_remapAxes(_transmitterMode, 2, temp);
for (int function=0; function<maxFunction; function++) {
settings.setValue(_rgFunctionSettingsKey[function], _rgFunctionAxis[function]);
settings.setValue(_rgFunctionSettingsKey[function], temp[function]);
qCDebug(JoystickLog) << "_saveSettings name:function:axis" << _name << function << _rgFunctionSettingsKey[function];
}
......@@ -198,6 +286,42 @@ void Joystick::_saveSettings(void)
}
}
// Relative mappings of axis functions between different TX modes
int Joystick::_mapFunctionMode(int mode, int function) {
static const int mapping[][4] = {
{ 2, 1, 0, 3 },
{ 2, 3, 0, 1 },
{ 0, 1, 2, 3 },
{ 0, 3, 2, 1 }};
return mapping[mode-1][function];
}
// Remap current axis functions from current TX mode to new TX mode
void Joystick::_remapAxes(int currentMode, int newMode, int (&newMapping)[maxFunction]) {
int temp[maxFunction];
for(int function = 0; function < maxFunction; function++) {
temp[_mapFunctionMode(newMode, function)] = _rgFunctionAxis[_mapFunctionMode(currentMode, function)];
}
for(int function = 0; function < maxFunction; function++) {
newMapping[function] = temp[function];
}
}
void Joystick::setTXMode(int mode) {
if(mode > 0 && mode <= 4) {
_remapAxes(_transmitterMode, mode, _rgFunctionAxis);
_transmitterMode = mode;
_saveSettings();
} else {
qCWarning(JoystickLog) << "Invalid mode:" << mode;
}
}
/// Adjust the raw axis value to the -1:1 range given calibration information
float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDeadbands)
{
......@@ -471,6 +595,7 @@ void Joystick::setFunctionAxis(AxisFunction_t function, int axis)
_calibrated = true;
_rgFunctionAxis[function] = axis;
_saveSettings();
emit calibratedChanged(_calibrated);
}
......
......@@ -30,12 +30,18 @@ public:
~Joystick();
typedef struct {
typedef struct Calibration_t {
int min;
int max;
int center;
int deadband;
bool reversed;
Calibration_t()
: min(-32767)
, max(32767)
, center(0)
, deadband(0)
, reversed(false) {}
} Calibration_t;
typedef enum {
......@@ -68,7 +74,8 @@ public:
Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged)
Q_PROPERTY(bool exponential READ exponential WRITE setExponential NOTIFY exponentialChanged)
Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged)
Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT)
// Property accessors
int axisCount(void) { return _axisCount; }
......@@ -89,6 +96,8 @@ public:
QString name(void) { return _name; }
virtual bool requiresCalibration(void) { return true; }
int throttleMode(void);
void setThrottleMode(int mode);
......@@ -101,6 +110,9 @@ public:
bool deadband(void);
void setDeadband(bool accu);
void setTXMode(int mode);
int getTXMode(void) { return _transmitterMode; }
typedef enum {
CalibrationModeOff, // Not calibrating
CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling
......@@ -141,12 +153,13 @@ signals:
void buttonActionTriggered(int action);
protected:
void _saveSettings(void);
void _loadSettings(void);
float _adjustRange(int value, Calibration_t calibration, bool withDeadbands);
void _buttonAction(const QString& action);
bool _validAxis(int axis);
bool _validButton(int button);
void _setDefaultCalibration(void);
void _saveSettings(void);
void _loadSettings(void);
float _adjustRange(int value, Calibration_t calibration, bool withDeadbands);
void _buttonAction(const QString& action);
bool _validAxis(int axis);
bool _validButton(int button);
private:
virtual bool _open() = 0;
......@@ -157,6 +170,9 @@ private:
virtual int _getAxis(int i) = 0;
virtual uint8_t _getHat(int hat,int i) = 0;
int _mapFunctionMode(int mode, int function);
void _remapAxes(int currentMode, int newMode, int (&newMapping)[maxFunction]);
// Override from QThread
virtual void run(void);
......@@ -172,6 +188,7 @@ protected:
int _hatButtonCount;
int _totalButtonCount;
static int _transmitterMode;
CalibrationMode_t _calibrationMode;
int* _rgAxisValues;
......@@ -203,6 +220,15 @@ private:
static const char* _exponentialSettingsKey;
static const char* _accumulatorSettingsKey;
static const char* _deadbandSettingsKey;
static const char* _txModeSettingsKey;
static const char* _fixedWingTXModeSettingsKey;
static const char* _multiRotorTXModeSettingsKey;
static const char* _roverTXModeSettingsKey;
static const char* _vtolTXModeSettingsKey;
static const char* _submarineTXModeSettingsKey;
private slots:
void _activeVehicleChanged(Vehicle* activeVehicle);
};
#endif
......@@ -10,6 +10,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in
, _isGameController(isGameController)
, _index(index)
{
if(_isGameController) _setDefaultCalibration();
}
QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) {
......
......@@ -12,7 +12,10 @@ class JoystickSDL : public Joystick
public:
JoystickSDL(const QString& name, int axisCount, int buttonCount, int hatCount, int index, bool isGameController, MultiVehicleManager* multiVehicleManager);
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
// This can be uncommented to hide the calibration buttons for gamecontrollers in the future
// bool requiresCalibration(void) final { return !_isGameController; }
private:
static void _loadGameControllerMappings();
......
......@@ -176,7 +176,7 @@ SetupPage {
QGCLabel {
id: rollLabel
width: defaultTextWidth * 10
text: qsTr("Roll")
text: _activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
}
Loader {
......@@ -208,7 +208,7 @@ SetupPage {
QGCLabel {
id: pitchLabel
width: defaultTextWidth * 10
text: qsTr("Pitch")
text: _activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
}
Loader {
......@@ -302,6 +302,7 @@ SetupPage {
// Command Buttons
Row {
spacing: 10
visible: _activeJoystick.requiresCalibration
QGCButton {
id: skipButton
......@@ -643,12 +644,57 @@ SetupPage {
id: rightColumn
anchors.top: parent.top
anchors.right: parent.right
width: defaultTextWidth * 35
spacing: 10
width: Math.min(joystickPage.defaultTextWidth * 35, availableWidth * 0.4)
spacing: ScreenTools.defaultFontPixelHeight / 2
Row {
spacing: ScreenTools.defaultFontPixelWidth
ExclusiveGroup { id: modeGroup }
QGCLabel {
text: "TX Mode:"
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "1"
checked: controller.transmitterMode == 1
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 1
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "2"
checked: controller.transmitterMode == 2
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 2
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "3"
checked: controller.transmitterMode == 3
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 3
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "4"
checked: controller.transmitterMode == 4
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 4
}
}
Image {
//width: parent.width
height: defaultTextHeight * 15
width: parent.width
fillMode: Image.PreserveAspectFit
smooth: true
source: controller.imageHelp
......
......@@ -29,8 +29,11 @@ const int JoystickConfigController::_calMinDelta = 1000; ///< Amo
const int JoystickConfigController::_stickDetectSettleMSecs = 500;
const char* JoystickConfigController::_imageFilePrefix = "calibration/";
const char* JoystickConfigController::_imageFileMode2Dir = "joystick/";
const char* JoystickConfigController::_imageFilePrefix = "calibration/joystick/";
const char* JoystickConfigController::_imageFileMode1Dir = "mode1/";
const char* JoystickConfigController::_imageFileMode2Dir = "mode2/";
const char* JoystickConfigController::_imageFileMode3Dir = "mode3/";
const char* JoystickConfigController::_imageFileMode4Dir = "mode4/";
const char* JoystickConfigController::_imageCenter = "joystickCenter.png";
const char* JoystickConfigController::_imageThrottleUp = "joystickThrottleUp.png";
const char* JoystickConfigController::_imageThrottleDown = "joystickThrottleDown.png";
......@@ -43,6 +46,7 @@ const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.p
JoystickConfigController::JoystickConfigController(void)
: _activeJoystick(NULL)
, _transmitterMode(2)
, _currentStep(-1)
, _axisCount(0)
, _rgAxisInfo(NULL)
......@@ -495,6 +499,8 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void)
_rgFunctionAxisMapping[function] = paramAxis;
_rgAxisInfo[paramAxis].function = (Joystick::AxisFunction_t)function;
}
_transmitterMode = joystick->getTXMode();
_signalAllAttiudeValueChanges();
}
......@@ -591,6 +597,7 @@ void JoystickConfigController::_startCalibration(void)
_currentStep = 0;
_setupCurrentState();
emit calibratingChanged();
}
/// @brief Cancels the calibration process, setting things back to initial state.
......@@ -609,6 +616,7 @@ void JoystickConfigController::_stopCalibration(void)
_skipButton->setEnabled(false);
_setHelpImage(_imageCenter);
emit calibratingChanged();
}
/// @brief Saves the current axis values, so that we can detect when the use moves an input.
......@@ -642,7 +650,23 @@ void JoystickConfigController::_setHelpImage(const char* imageFile)
{
QString file = _imageFilePrefix;
file += _imageFileMode2Dir;
switch(_transmitterMode) {
case 1:
file += _imageFileMode1Dir;
break;
case 2:
file += _imageFileMode2Dir;
break;
case 3:
file += _imageFileMode3Dir;
break;
case 4:
file += _imageFileMode4Dir;
break;
default:
Q_ASSERT(false);
}
file += imageFile;
qCDebug(JoystickConfigControllerLog) << "_setHelpImage" << file;
......@@ -784,6 +808,20 @@ bool JoystickConfigController::throttleAxisReversed(void)
}
}
void JoystickConfigController::setTransmitterMode(int mode)
{
if (mode > 0 && mode <= 4) {
_transmitterMode = mode;
if (_currentStep != -1) { // This should never be true, mode selection is disabled during calibration
const stateMachineEntry* state = _getStateMachineEntry(_currentStep);
_setHelpImage(state->image);
} else {
_activeJoystick->setTXMode(mode);
_setInternalCalibrationValuesFromSettings();
}
}
}
void JoystickConfigController::_signalAllAttiudeValueChanges(void)
{
emit rollAxisMappedChanged(rollAxisMapped());
......@@ -800,6 +838,8 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void)
emit pitchAxisDeadbandChanged(pitchAxisDeadband());
emit yawAxisDeadbandChanged(yawAxisDeadband());
emit throttleAxisDeadbandChanged(throttleAxisDeadband());
emit transmitterModeChanged(_transmitterMode);
}
void JoystickConfigController::_activeJoystickChanged(Joystick* joystick)
......
......@@ -69,7 +69,9 @@ public:
Q_PROPERTY(bool deadbandToggle READ getDeadbandToggle WRITE setDeadbandToggle NOTIFY deadbandToggled)
Q_PROPERTY(int transmitterMode READ transmitterMode WRITE setTransmitterMode NOTIFY transmitterModeChanged)
Q_PROPERTY(QString imageHelp MEMBER _imageHelp NOTIFY imageHelpChanged)
Q_PROPERTY(bool calibrating READ calibrating NOTIFY calibratingChanged)
Q_INVOKABLE void cancelButtonClicked(void);
Q_INVOKABLE void skipButtonClicked(void);
......@@ -100,6 +102,11 @@ public:
void setDeadbandToggle(bool);
int axisCount(void);
int transmitterMode(void) { return _transmitterMode; }
void setTransmitterMode(int mode);
bool calibrating(void) { return _currentStep != -1; }
signals:
void axisValueChanged(int axis, int value);
......@@ -127,6 +134,8 @@ signals:
void deadbandToggled(bool value);
void imageHelpChanged(QString source);
void transmitterModeChanged(int mode);
void calibratingChanged(void);
// @brief Signalled when in unit test mode and a message box should be displayed by the next button
void nextButtonMessageBoxDisplayed(void);
......@@ -172,6 +181,7 @@ private:
Joystick* _activeJoystick;
int _transmitterMode;
int _currentStep; ///< Current step of state machine
const struct stateMachineEntry* _getStateMachineEntry(int step);
......@@ -211,7 +221,10 @@ private:
// Member variables
static const char* _imageFileMode1Dir;
static const char* _imageFileMode2Dir;
static const char* _imageFileMode3Dir;
static const char* _imageFileMode4Dir;
static const char* _imageFilePrefix;
static const char* _imageCenter;
static const char* _imageThrottleUp;
......
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