Commit eb23e67e authored by DoinLakeFlyer's avatar DoinLakeFlyer

parent 1c4e2252
...@@ -515,12 +515,32 @@ void Joystick::_handleButtons() ...@@ -515,12 +515,32 @@ void Joystick::_handleButtons()
QString buttonAction = _buttonActionArray[buttonIndex]->action; QString buttonAction = _buttonActionArray[buttonIndex]->action;
if(buttonAction.isEmpty() || buttonAction == _buttonActionNone) if(buttonAction.isEmpty() || buttonAction == _buttonActionNone)
continue; continue;
//-- Process single button
if(!_buttonActionArray[buttonIndex]->repeat) { if(!_buttonActionArray[buttonIndex]->repeat) {
//-- This button just went down //-- This button just went down
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) { if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) {
qCDebug(JoystickLog) << "Single button triggered" << buttonIndex << buttonAction; // Check for a multi-button action
_executeButtonAction(buttonAction, true); 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 { } else {
//-- Process repeat buttons //-- Process repeat buttons
......
...@@ -22,7 +22,7 @@ import QGroundControl.FactControls 1.0 ...@@ -22,7 +22,7 @@ import QGroundControl.FactControls 1.0
Item { Item {
width: availableWidth width: availableWidth
height: (activeVehicle.supportsJSButton ? buttonCol.height : buttonFlow.height) + (ScreenTools.defaultFontPixelHeight * 2) height: (activeVehicle.supportsJSButton ? buttonCol.height : flowColumn.height) + (ScreenTools.defaultFontPixelHeight * 2)
Connections { Connections {
target: _activeJoystick target: _activeJoystick
onRawButtonPressedChanged: { onRawButtonPressedChanged: {
...@@ -34,66 +34,76 @@ Item { ...@@ -34,66 +34,76 @@ Item {
} }
} }
} }
Flow { ColumnLayout {
id: buttonFlow id: flowColumn
width: parent.width y: ScreenTools.defaultFontPixelHeight / 2
spacing: ScreenTools.defaultFontPixelWidth width: parent.width
visible: !activeVehicle.supportsJSButton spacing: ScreenTools.defaultFontPixelHeight / 2
anchors.centerIn: parent QGCLabel {
Repeater { Layout.preferredWidth: parent.width
id: buttonActionRepeater wrapMode: Text.WordWrap
model: _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : [] 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.")
Row { }
spacing: ScreenTools.defaultFontPixelWidth Flow {
property bool pressed id: buttonFlow
property var currentAssignableAction: _activeJoystick ? _activeJoystick.assignableActions.get(buttonActionCombo.currentIndex) : null Layout.preferredWidth: parent.width
Rectangle { spacing: ScreenTools.defaultFontPixelWidth
anchors.verticalCenter: parent.verticalCenter visible: !activeVehicle.supportsJSButton
width: ScreenTools.defaultFontPixelHeight * 1.5 Repeater {
height: width id: buttonActionRepeater
border.width: 1 model: _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : []
border.color: qgcPal.text Row {
color: pressed ? qgcPal.buttonHighlight : qgcPal.button spacing: ScreenTools.defaultFontPixelWidth
QGCLabel { property bool pressed
anchors.fill: parent property var currentAssignableAction: _activeJoystick ? _activeJoystick.assignableActions.get(buttonActionCombo.currentIndex) : null
color: pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText Rectangle {
horizontalAlignment: Text.AlignHCenter anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter width: ScreenTools.defaultFontPixelHeight * 1.5
text: modelData height: width
} border.width: 1
} border.color: qgcPal.text
QGCComboBox { color: pressed ? qgcPal.buttonHighlight : qgcPal.button
id: buttonActionCombo QGCLabel {
width: ScreenTools.defaultFontPixelWidth * 26 anchors.fill: parent
model: _activeJoystick ? _activeJoystick.assignableActionTitles : [] color: pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
onActivated: { horizontalAlignment: Text.AlignHCenter
_activeJoystick.setButtonAction(modelData, textAt(index)) verticalAlignment: Text.AlignVCenter
} text: modelData
Component.onCompleted: {
if(_activeJoystick) {
var i = find(_activeJoystick.buttonActions[modelData])
if(i < 0) i = 0
currentIndex = i
} }
} }
} QGCComboBox {
QGCCheckBox { id: buttonActionCombo
id: repeatCheck width: ScreenTools.defaultFontPixelWidth * 26
text: qsTr("Repeat") model: _activeJoystick ? _activeJoystick.assignableActionTitles : []
enabled: currentAssignableAction && _activeJoystick.calibrated && currentAssignableAction.canRepeat onActivated: {
onClicked: { _activeJoystick.setButtonAction(modelData, textAt(index))
_activeJoystick.setButtonRepeat(modelData, checked) }
Component.onCompleted: {
if(_activeJoystick) {
var i = find(_activeJoystick.buttonActions[modelData])
if(i < 0) i = 0
currentIndex = i
}
}
} }
Component.onCompleted: { QGCCheckBox {
if(_activeJoystick) { id: repeatCheck
checked = _activeJoystick.getButtonRepeat(modelData) text: qsTr("Repeat")
enabled: currentAssignableAction && _activeJoystick.calibrated && currentAssignableAction.canRepeat
onClicked: {
_activeJoystick.setButtonRepeat(modelData, checked)
}
Component.onCompleted: {
if(_activeJoystick) {
checked = _activeJoystick.getButtonRepeat(modelData)
}
} }
anchors.verticalCenter: parent.verticalCenter
}
Item {
width: ScreenTools.defaultFontPixelWidth * 2
height: 1
} }
anchors.verticalCenter: parent.verticalCenter
}
Item {
width: ScreenTools.defaultFontPixelWidth * 2
height: 1
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment