Skip to content

Commit

Permalink
Support custom builds with joysticks which are buttons only
Browse files Browse the repository at this point in the history
For example a Herelink controller custom build will use this.
  • Loading branch information
DonLakeFlyer committed Aug 8, 2023
1 parent 9b6b359 commit 48d1441
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "VideoManager.h"
#include "QGCCameraManager.h"
#include "QGCCameraControl.h"
#include "QGCCorePlugin.h"
#include "QGCOptions.h"

#include <QSettings>

Expand Down Expand Up @@ -108,6 +110,8 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
, _totalButtonCount(_buttonCount+_hatButtonCount)
, _multiVehicleManager(multiVehicleManager)
{
_useButtonsOnly = qgcApp()->toolbox()->corePlugin()->options()->joystickUseButtonsOnly();

qRegisterMetaType<GRIPPER_ACTIONS>();

_rgAxisValues = new int[static_cast<size_t>(_axisCount)];
Expand Down Expand Up @@ -713,10 +717,9 @@ void Joystick::startPolling(Vehicle* vehicle)
}
// Update qml in case of joystick transition
emit calibratedChanged(_calibrated);
// Build action list
_buildActionList(vehicle);
// Only connect the new vehicle if it wants joystick data
if (vehicle->joystickEnabled()) {

if (vehicle->joystickEnabled() || _useButtonsOnly) {
_pollingStartedForCalibration = false;
connect(this, &Joystick::setArmed, _activeVehicle, &Vehicle::setArmedShowError);
connect(this, &Joystick::setVtolInFwdFlight, _activeVehicle, &Vehicle::setVtolInFwdFlight);
Expand All @@ -738,7 +741,7 @@ void Joystick::startPolling(Vehicle* vehicle)
void Joystick::stopPolling(void)
{
if (isRunning()) {
if (_activeVehicle && _activeVehicle->joystickEnabled()) {
if (_activeVehicle && (_activeVehicle->joystickEnabled() || _useButtonsOnly)) {
disconnect(this, &Joystick::setArmed, _activeVehicle, &Vehicle::setArmedShowError);
disconnect(this, &Joystick::setVtolInFwdFlight, _activeVehicle, &Vehicle::setVtolInFwdFlight);
disconnect(this, &Joystick::setFlightMode, _activeVehicle, &Vehicle::setFlightMode);
Expand Down Expand Up @@ -985,9 +988,10 @@ void Joystick::setCalibrationMode(bool calibrating)

void Joystick::_executeButtonAction(const QString& action, bool buttonDown)
{
if (!_activeVehicle || !_activeVehicle->joystickEnabled() || action == _buttonActionNone) {
if (!_activeVehicle || (!_activeVehicle->joystickEnabled() && !_useButtonsOnly) || action == _buttonActionNone) {
return;
}

if (action == _buttonActionArm) {
if (buttonDown) emit setArmed(true);
} else if (action == _buttonActionDisarm) {
Expand Down
5 changes: 5 additions & 0 deletions src/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class Joystick : public QThread
Q_PROPERTY(int axisCount READ axisCount CONSTANT)
Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT)

// This property is used to indicate a joystick setup where the stick axes are ignored and only the
// buttons are supported. This type of setup is used by a Herelink controller for example.
Q_PROPERTY(bool useButtonsOnly MEMBER _useButtonsOnly CONSTANT)

//-- Actions assigned to buttons
Q_PROPERTY(QStringList buttonActions READ buttonActions NOTIFY buttonActionsChanged)

Expand Down Expand Up @@ -275,6 +279,7 @@ class Joystick : public QThread

std::atomic<bool> _exitThread{false}; ///< true: signal thread to exit
bool _calibrationMode = false;
bool _useButtonsOnly = false;
int* _rgAxisValues = nullptr;
Calibration_t* _rgCalibration = nullptr;
ThrottleMode_t _throttleMode = ThrottleModeDownZero;
Expand Down
12 changes: 11 additions & 1 deletion src/VehicleSetup/JoystickConfig.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,30 @@ SetupPage {
id: bar
width: parent.width
Component.onCompleted: {
currentIndex = _activeJoystick && _activeJoystick.calibrated ? 0 : 2
currentIndex = 0
if (_activeJoystick) {
if (_activeJoystick.useButtonsOnly) {
currentIndex = 1
} else if (_activeJoystick.calibrated) {
currentIndex = 2
}
}
}
anchors.top: parent.top
QGCTabButton {
text: qsTr("General")
visible: !_activeJoystick.useButtonsOnly
}
QGCTabButton {
text: qsTr("Button Assigment")
}
QGCTabButton {
text: qsTr("Calibration")
visible: !_activeJoystick.useButtonsOnly
}
QGCTabButton {
text: qsTr("Advanced")
visible: !_activeJoystick.useButtonsOnly
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/VehicleSetup/SetupView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Rectangle {
id: joystickButton
imageResource: "/qmlimages/Joystick.png"
setupIndicator: true
setupComplete: joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
setupComplete: joystickManager.activeJoystick ? (joystickManager.activeJoystick.calibrated || joystickManager.activeJoystick.useButtonsOnly) : false
exclusiveGroup: setupButtonGroup
visible: _fullParameterVehicleAvailable && joystickManager.joysticks.length !== 0
text: qsTr("Joystick")
Expand Down
4 changes: 4 additions & 0 deletions src/api/QGCOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class QGCOptions : public QObject

virtual QGCFlyViewOptions* flyViewOptions ();

// This is used to indicate a joystick setup where the stick axes are ignored and only the
// buttons are supported. This type of setup is used by a Herelink controller for example.
virtual bool joystickUseButtonsOnly() const { return false; }

signals:
void showSensorCalibrationCompassChanged (bool show);
void showSensorCalibrationGyroChanged (bool show);
Expand Down

0 comments on commit 48d1441

Please sign in to comment.