Skip to content

Commit

Permalink
Joystick: allow custom plugin to add and handle custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
or-rhssk authored and HTRamsey committed Dec 17, 2024
1 parent f1089ac commit b10e428
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/API/QGCCorePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ class QGCCorePlugin : public QObject
/// Returns a true if xml definition file of a providen camera name exists, and loads it to file argument, to allow definition files to be loaded from resources
virtual bool getOfflineCameraDefinitionFile(const QString &cameraName, QFile &file) const { Q_UNUSED(cameraName); Q_UNUSED(file); return false; }

struct JoystickAction {
QString name;
bool canRepeat = false;
};
virtual QList<JoystickAction> joystickActions() const { return {}; }

/// Returns the list of first run prompt ids which need to be displayed according to current settings
Q_INVOKABLE QVariantList firstRunPromptsToShow() const;

Expand Down
7 changes: 7 additions & 0 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Vehicle.h"
#include "MultiVehicleManager.h"
#include "FirmwarePlugin.h"
#include "QGCCorePlugin.h"
#include "QGCLoggingCategory.h"
#include "GimbalController.h"
#include "QmlObjectListModel.h"
Expand Down Expand Up @@ -1042,6 +1043,7 @@ void Joystick::_executeButtonAction(const QString& action, bool buttonDown)
if (buttonDown) emit landingGearRetract();
} else {
if (buttonDown && _activeVehicle) {
emit unknownAction(action);
for (int i=0; i<_customActionManager.actions()->count(); i++) {
auto customAction = _customActionManager.actions()->value<CustomAction*>(i);
if (action == customAction->label()) {
Expand Down Expand Up @@ -1123,6 +1125,11 @@ void Joystick::_buildActionList(Vehicle* activeVehicle)
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearDeploy));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearRetract));

const auto customActions = QGCCorePlugin::instance()->joystickActions();
for (const auto &action : customActions) {
_assignableButtonActions.append(new AssignableButtonAction(this, action.name, action.canRepeat));
}

for (int i=0; i<_customActionManager.actions()->count(); i++) {
auto customAction = _customActionManager.actions()->value<CustomAction*>(i);
_assignableButtonActions.append(new AssignableButtonAction(this, customAction->label()));
Expand Down
1 change: 1 addition & 0 deletions src/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class Joystick : public QThread
void gripperAction (GRIPPER_ACTIONS gripperAction);
void landingGearDeploy ();
void landingGearRetract ();
void unknownAction (const QString &action);

protected:
void _setDefaultCalibration ();
Expand Down

0 comments on commit b10e428

Please sign in to comment.