Skip to content

Commit

Permalink
Add firmware-specific joystick TX mode settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxzer committed Jan 25, 2017
1 parent 0b2af26 commit bffe803
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class ArduSubFirmwarePlugin : public APMFirmwarePlugin
// Overrides from FirmwarePlugin
int manualControlReservedButtonCount(void);

int defaultJoystickTXMode(void) final { return 3; }

bool supportsThrottleModeCenterZero(void);

bool supportsManualControl(void);
Expand Down
5 changes: 5 additions & 0 deletions src/FirmwarePlugin/FirmwarePlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/FirmwarePlugin/FirmwarePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class FirmwarePlugin : public QObject
/// @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.
Expand Down
64 changes: 51 additions & 13 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +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::_txModeSettingsKey = "TXMode";
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::_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",
Expand Down Expand Up @@ -70,6 +75,8 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
}

_loadSettings();

connect(_multiVehicleManager, &MultiVehicleManager::activeVehicleChanged, this, &Joystick::_activeVehicleChanged);
}

Joystick::~Joystick()
Expand All @@ -96,9 +103,11 @@ void Joystick::_setDefaultCalibration(void) {
_rgCalibration[1].reversed = true;
_rgCalibration[3].reversed = true;

for(int function = 0; function < maxFunction; function++) {
_rgFunctionAxis[function] = function;
}
// Default TX Mode 2 axis assignments for gamecontrollers
_rgFunctionAxis[rollFunction] = 2;
_rgFunctionAxis[pitchFunction] = 3;
_rgFunctionAxis[yawFunction] = 0;
_rgFunctionAxis[throttleFunction] = 1;

_exponential = false;
_accumulator = false;
Expand All @@ -109,13 +118,41 @@ void Joystick::_setDefaultCalibration(void) {
_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);

_transmitterMode = settings.value(_txModeSettingsKey, 2).toInt();
if(_txModeSettingsKey)
_transmitterMode = settings.value(_txModeSettingsKey, 2).toInt();

settings.beginGroup(_name);

Expand Down Expand Up @@ -195,7 +232,8 @@ void Joystick::_saveSettings(void)

// Transmitter mode is static
// Save the mode we are using
settings.setValue(_txModeSettingsKey, _transmitterMode);
if(_txModeSettingsKey)
settings.setValue(_txModeSettingsKey, _transmitterMode);

settings.beginGroup(_name);

Expand Down
8 changes: 8 additions & 0 deletions src/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class Joystick : public QThread
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

0 comments on commit bffe803

Please sign in to comment.