From 2664e9a5a690537985fc448ce8e8de9de97bf4a3 Mon Sep 17 00:00:00 2001 From: Rustom Jehangir Date: Mon, 1 Aug 2016 10:03:20 -0700 Subject: [PATCH] Make supportsJSButton a plugin option --- .../APM/ArduSubFirmwarePlugin.cc | 5 +++++ src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h | 2 ++ src/FirmwarePlugin/FirmwarePlugin.cc | 5 +++++ src/FirmwarePlugin/FirmwarePlugin.h | 4 ++++ src/Vehicle/Vehicle.cc | 5 +++++ src/Vehicle/Vehicle.h | 2 ++ src/VehicleSetup/JoystickConfig.qml | 18 +++++++++--------- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc index 1818b5cf2..e6dd01b74 100644 --- a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc +++ b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc @@ -67,3 +67,8 @@ bool ArduSubFirmwarePlugin::supportsRadio(void) { return false; } + +bool ArduSubFirmwarePlugin::supportsJSButton(void) +{ + return true; +} diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h index 1f862ce4e..5d6386951 100644 --- a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h @@ -74,6 +74,8 @@ public: bool supportsManualControl(void); bool supportsRadio(void); + + bool supportsJSButton(void); }; #endif diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 5e835f5fd..9707264e9 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -99,6 +99,11 @@ bool FirmwarePlugin::supportsRadio(void) return true; } +bool FirmwarePlugin::supportsJSButton(void) +{ + return false; +} + bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) { Q_UNUSED(vehicle); diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index ecd6179e9..a4f580308 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -141,6 +141,10 @@ public: /// setup page. Returns true by default. virtual bool supportsRadio(void); + /// Returns true if the firmware supports the AP_JSButton library, which allows joystick buttons + /// to be assigned via parameters in firmware. Default is false. + virtual bool supportsJSButton(void); + /// Called before any mavlink message is processed by Vehicle such that the firmwre plugin /// can adjust any message characteristics. This is handy to adjust or differences in mavlink /// spec implementations such that the base code can remain mavlink generic. diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 40982010e..f21c8710a 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -1530,6 +1530,11 @@ bool Vehicle::supportsRadio(void) const return _firmwarePlugin->supportsRadio(); } +bool Vehicle::supportsJSButton(void) const +{ + return _firmwarePlugin->supportsJSButton(); +} + void Vehicle::_setCoordinateValid(bool coordinateValid) { if (coordinateValid != _coordinateValid) { diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 90df74f65..e70c2981b 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -277,6 +277,7 @@ public: Q_PROPERTY(bool rover READ rover CONSTANT) Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT) Q_PROPERTY(bool supportsThrottleModeCenterZero READ supportsThrottleModeCenterZero CONSTANT) + Q_PROPERTY(bool supportsJSButton READ supportsJSButton CONSTANT) Q_PROPERTY(bool sub READ sub CONSTANT) Q_PROPERTY(bool autoDisconnect MEMBER _autoDisconnect NOTIFY autoDisconnectChanged) Q_PROPERTY(QString prearmError READ prearmError WRITE setPrearmError NOTIFY prearmErrorChanged) @@ -476,6 +477,7 @@ public: bool supportsManualControl(void) const; bool supportsThrottleModeCenterZero(void) const; bool supportsRadio(void) const; + bool supportsJSButton(void) const; void setFlying(bool flying); void setGuidedMode(bool guidedMode); diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index c53a74273..91b689362 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -381,7 +381,7 @@ QGCView { Column { spacing: ScreenTools.defaultFontPixelHeight / 3 - visible: !_activeVehicle.sub + visible: _activeVehicle.supportsThrottleModeCenterZero ExclusiveGroup { id: throttleModeExclusiveGroup } @@ -449,8 +449,8 @@ QGCView { if (buttonActionRepeater.itemAt(index)) { buttonActionRepeater.itemAt(index).pressed = pressed } - if (subButtonActionRepeater.itemAt(index)) { - subButtonActionRepeater.itemAt(index).pressed = pressed + if (jsButtonActionRepeater.itemAt(index)) { + jsButtonActionRepeater.itemAt(index).pressed = pressed } } } @@ -474,7 +474,7 @@ QGCView { Row { spacing: ScreenTools.defaultFontPixelWidth - visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.sub + visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton property bool pressed @@ -516,7 +516,7 @@ QGCView { Row { spacing: ScreenTools.defaultFontPixelWidth - visible: _activeVehicle.sub + visible: _activeVehicle.supportsJSButton QGCLabel { horizontalAlignment: Text.AlignHCenter @@ -536,12 +536,12 @@ QGCView { } // Row Repeater { - id: subButtonActionRepeater + id: jsButtonActionRepeater model: _activeJoystick.totalButtonCount Row { spacing: ScreenTools.defaultFontPixelWidth - visible: _activeVehicle.sub + visible: _activeVehicle.supportsJSButton property bool pressed @@ -564,14 +564,14 @@ QGCView { } FactComboBox { - id: mainSubButtonActionCombo + id: mainJSButtonActionCombo width: ScreenTools.defaultFontPixelWidth * 15 fact: controller.parameterExists(-1, "BTN"+index+"_FUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_FUNCTION") : null; indexModel: false } FactComboBox { - id: shiftSubButtonActionCombo + id: shiftJSButtonActionCombo width: ScreenTools.defaultFontPixelWidth * 15 fact: controller.parameterExists(-1, "BTN"+index+"_SFUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_SFUNCTION") : null; indexModel: false -- 2.22.0