diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 19700e9fa9b16a9003e842906e73b99b77bf4b0d..2b217ae486d80f6d356dc48dab0061d56a70152e 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -79,6 +79,36 @@ 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; + + for(int function = 0; function < maxFunction; function++) { + _rgFunctionAxis[function] = function; + } + + _exponential = false; + _accumulator = false; + _deadband = false; + _throttleMode = ThrottleModeCenterZero; + _calibrated = true; + + _saveSettings(); +} + void Joystick::_loadSettings(void) { QSettings settings; @@ -102,7 +132,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"); diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index bef89146f7c8a5ff8c32a324e58a939bc99d692a..521f8866aff6828ad95d77638476dd9ff80841f0 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -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); @@ -144,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; diff --git a/src/Joystick/JoystickSDL.cc b/src/Joystick/JoystickSDL.cc index 303c3005c00c6ff659cecff0852e897b72141e4b..59798e2681573bf049d0c8dd5f1dedc3fb76d6a8 100644 --- a/src/Joystick/JoystickSDL.cc +++ b/src/Joystick/JoystickSDL.cc @@ -10,6 +10,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in , _isGameController(isGameController) , _index(index) { + if(_isGameController) _setDefaultCalibration(); } QMap JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) { diff --git a/src/Joystick/JoystickSDL.h b/src/Joystick/JoystickSDL.h index 2c4a9ca6aeb93fae1880f4f8b3e266604c181eb3..36d966e2842eec1c2fb2205f69109e93a42f71e1 100644 --- a/src/Joystick/JoystickSDL.h +++ b/src/Joystick/JoystickSDL.h @@ -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 discover(MultiVehicleManager* _multiVehicleManager); + static QMap 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(); diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index ce68595db94d98acabd5c2724a52b63400ad57d4..a204c16c14d864f1df36e13ca6f3189dc97807d6 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -302,6 +302,7 @@ SetupPage { // Command Buttons Row { spacing: 10 + visible: _activeJoystick.requiresCalibration QGCButton { id: skipButton