Skip to content

Commit

Permalink
Allows more than one Cockpit button to activate the same MAVLink button
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Sep 13, 2023
1 parent a7b1926 commit d994d1f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libs/joystick/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d994d1f

Please sign in to comment.