Browse Source

Merge pull request #8662 from DonLakeFlyer/JoystickMultiButton

Add support for multi-press joystick buttons
QGC4.4
Don Gagne 5 years ago committed by GitHub
parent
commit
d69d17a1e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      src/Joystick/Joystick.cc
  2. 16
      src/VehicleSetup/JoystickConfigButtons.qml

24
src/Joystick/Joystick.cc

@ -515,13 +515,33 @@ void Joystick::_handleButtons() @@ -515,13 +515,33 @@ void Joystick::_handleButtons()
QString buttonAction = _buttonActionArray[buttonIndex]->action;
if(buttonAction.isEmpty() || buttonAction == _buttonActionNone)
continue;
//-- Process single button
if(!_buttonActionArray[buttonIndex]->repeat) {
//-- This button just went down
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) {
qCDebug(JoystickLog) << "Single button triggered" << buttonIndex << buttonAction;
// Check for a multi-button action
QList<int> rgButtons = { buttonIndex };
bool executeButtonAction = true;
for (int multiIndex = 0; multiIndex < _totalButtonCount; multiIndex++) {
if (multiIndex != buttonIndex) {
if (_buttonActionArray[multiIndex] && _buttonActionArray[multiIndex]->action == buttonAction) {
// We found a multi-button action
if (_rgButtonValues[multiIndex] == BUTTON_DOWN || _rgButtonValues[multiIndex] == BUTTON_REPEAT) {
// So far so good
rgButtons.append(multiIndex);
continue;
} else {
// We are missing a press we need
executeButtonAction = false;
break;
}
}
}
}
if (executeButtonAction) {
qCDebug(JoystickLog) << "Action triggered" << rgButtons << buttonAction;
_executeButtonAction(buttonAction, true);
}
}
} else {
//-- Process repeat buttons
int buttonDelay = static_cast<int>(1000.0f / _buttonFrequency);

16
src/VehicleSetup/JoystickConfigButtons.qml

@ -22,7 +22,7 @@ import QGroundControl.FactControls 1.0 @@ -22,7 +22,7 @@ import QGroundControl.FactControls 1.0
Item {
width: availableWidth
height: (activeVehicle.supportsJSButton ? buttonCol.height : buttonFlow.height) + (ScreenTools.defaultFontPixelHeight * 2)
height: (activeVehicle.supportsJSButton ? buttonCol.height : flowColumn.height) + (ScreenTools.defaultFontPixelHeight * 2)
Connections {
target: _activeJoystick
onRawButtonPressedChanged: {
@ -34,12 +34,21 @@ Item { @@ -34,12 +34,21 @@ Item {
}
}
}
ColumnLayout {
id: flowColumn
y: ScreenTools.defaultFontPixelHeight / 2
width: parent.width
spacing: ScreenTools.defaultFontPixelHeight / 2
QGCLabel {
Layout.preferredWidth: parent.width
wrapMode: Text.WordWrap
text: qsTr("Assigning the same action to multiple buttons requires the press of all those buttons for the action to be taken. This is useful to prevent accidental button presses for critical actions like Arm or Emergency Stop.")
}
Flow {
id: buttonFlow
width: parent.width
Layout.preferredWidth: parent.width
spacing: ScreenTools.defaultFontPixelWidth
visible: !activeVehicle.supportsJSButton
anchors.centerIn: parent
Repeater {
id: buttonActionRepeater
model: _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : []
@ -98,6 +107,7 @@ Item { @@ -98,6 +107,7 @@ Item {
}
}
}
}
Column {
id: buttonCol
width: parent.width

Loading…
Cancel
Save