From d994d1f4ca232ede42f2bff07586de03a6b71ba8 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 13 Sep 2023 15:15:31 -0300 Subject: [PATCH] Allows more than one Cockpit button to activate the same MAVLink button --- src/libs/joystick/protocols.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/joystick/protocols.ts b/src/libs/joystick/protocols.ts index c7c2d9676..ea300b38d 100644 --- a/src/libs/joystick/protocols.ts +++ b/src/libs/joystick/protocols.ts @@ -49,10 +49,13 @@ export class MavlinkControllerState extends ProtocolControllerState { let buttons_int = 0 for (let i = 0; i < MavlinkControllerState.BUTTONS_PER_BITFIELD; i++) { - const gamepadButtonPosition = mapping.buttonsCorrespondencies.findIndex((b) => isMavlinkInput(b) && b.value === i) - if (gamepadButtonPosition === -1) continue - const gamepadButtonState = joystickState.buttons[gamepadButtonPosition] - buttons_int += (gamepadButtonState ?? 0) * 2 ** i + let buttonState = 0 + mapping.buttonsCorrespondencies.forEach((b, idx) => { + if (isMavlinkInput(b) && b.value === i && joystickState.buttons[idx]) { + buttonState = 1 + } + }) + buttons_int += buttonState * 2 ** i } const xIndex = mapping.axesCorrespondencies.findIndex((v) => isMavlinkInput(v) && v.value === MAVLinkAxis.X)