Skip to content

Commit

Permalink
Rename protocol name from MAVLink to MAVLinkManualControl
Browse files Browse the repository at this point in the history
Being more specific makes it clear that we are talking about `MANUAL_CONTROL` messages on MAVLink, so we don't confuse this with a MAVLink `COMMAND` message, for example, which is used on boats and other vehicles.
  • Loading branch information
rafaellehmkuhl committed Nov 8, 2023
1 parent 22ea103 commit b539026
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
38 changes: 19 additions & 19 deletions src/assets/joystick-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import { type GamepadToCockpitStdMapping, type ProtocolControllerMapping, Joysti
export const cockpitStandardToProtocols: ProtocolControllerMapping = {
name: 'Cockpit Standard Gamepad to Protocols',
axesCorrespondencies: [
{ protocol: JoystickProtocol.MAVLink, value: MAVLinkAxis.Y },
{ protocol: JoystickProtocol.MAVLink, value: MAVLinkAxis.X },
{ protocol: JoystickProtocol.MAVLink, value: MAVLinkAxis.R },
{ protocol: JoystickProtocol.MAVLink, value: MAVLinkAxis.Z },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.Y },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.X },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.R },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.Z },
],
axesMins: [-1000, 1000, -1000, 1000],
axesMaxs: [1000, -1000, 1000, 0],
buttonsCorrespondencies: [
{ protocol: JoystickProtocol.MAVLink, value: 0 },
{ protocol: JoystickProtocol.MAVLink, value: 1 },
{ protocol: JoystickProtocol.MAVLink, value: 2 },
{ protocol: JoystickProtocol.MAVLink, value: 3 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 0 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 1 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 2 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 3 },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.GO_TO_PREVIOUS_VIEW },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.GO_TO_NEXT_VIEW },
{ protocol: JoystickProtocol.MAVLink, value: 9 },
{ protocol: JoystickProtocol.MAVLink, value: 10 },
{ protocol: JoystickProtocol.MAVLink, value: 4 },
{ protocol: JoystickProtocol.MAVLink, value: 6 },
{ protocol: JoystickProtocol.MAVLink, value: 7 },
{ protocol: JoystickProtocol.MAVLink, value: 8 },
{ protocol: JoystickProtocol.MAVLink, value: 11 },
{ protocol: JoystickProtocol.MAVLink, value: 12 },
{ protocol: JoystickProtocol.MAVLink, value: 13 },
{ protocol: JoystickProtocol.MAVLink, value: 14 },
{ protocol: JoystickProtocol.MAVLink, value: 5 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 9 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 10 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 4 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 6 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 7 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 8 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 11 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 12 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 13 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 14 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 5 },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.TOGGLE_FULL_SCREEN },
],
}
Expand Down
11 changes: 7 additions & 4 deletions src/libs/joystick/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MavlinkControllerState extends ProtocolControllerState {
constructor(joystickState: JoystickState, mapping: ProtocolControllerMapping, target = 1) {
super()

const isMavlinkInput = (input: ProtocolInput): boolean => input.protocol === JoystickProtocol.MAVLink
const isMavlinkInput = (input: ProtocolInput): boolean => input.protocol === JoystickProtocol.MAVLinkManualControl

let buttons_int = 0
for (let i = 0; i < MavlinkControllerState.BUTTONS_PER_BITFIELD; i++) {
Expand Down Expand Up @@ -157,7 +157,7 @@ export const mavlinkAvailableButtons = sequentialArray(16)
const mavlinkAxesLimits = [-1000, 1000]
export const protocolAxesLimits = (protocol: JoystickProtocol): number[] => {
switch (protocol) {
case JoystickProtocol.MAVLink:
case JoystickProtocol.MAVLinkManualControl:
return mavlinkAxesLimits
default:
// Mavlink is the current main protocol and will be used by default
Expand All @@ -167,7 +167,7 @@ export const protocolAxesLimits = (protocol: JoystickProtocol): number[] => {

export const allAvailableAxes: InputWithPrettyName[] = []
mavlinkAvailableAxes.forEach((axis) =>
allAvailableAxes.push({ input: { protocol: JoystickProtocol.MAVLink, value: axis }, prettyName: axis })
allAvailableAxes.push({ input: { protocol: JoystickProtocol.MAVLinkManualControl, value: axis }, prettyName: axis })
)

Object.values(OtherProtocol).forEach((fn) =>
Expand All @@ -176,7 +176,10 @@ Object.values(OtherProtocol).forEach((fn) =>

export const allAvailableButtons: InputWithPrettyName[] = []
mavlinkAvailableButtons.forEach((btn) =>
allAvailableButtons.push({ input: { protocol: JoystickProtocol.MAVLink, value: btn }, prettyName: btn.toString() })
allAvailableButtons.push({
input: { protocol: JoystickProtocol.MAVLinkManualControl, value: btn },
prettyName: btn.toString(),
})
)
Object.values(CockpitAction).forEach((action) =>
allAvailableButtons.push({ input: { protocol: JoystickProtocol.CockpitAction, value: action }, prettyName: action })
Expand Down
4 changes: 2 additions & 2 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
const functionName = buttonParameterTable.find((p) => p.value === param[1])?.title
if (functionName === undefined) return
newMavlinkButtonsNames.push({
input: { protocol: JoystickProtocol.MAVLink, value: buttonId },
input: { protocol: JoystickProtocol.MAVLinkManualControl, value: buttonId },
prettyName: functionName,
})
})
}
if (newMavlinkButtonsNames.isEmpty()) return
let newProtocolButtonsFunctions = controllerStore.availableProtocolButtonFunctions.filter((btn) => {
return btn.input.protocol !== JoystickProtocol.MAVLink
return btn.input.protocol !== JoystickProtocol.MAVLinkManualControl
})
newProtocolButtonsFunctions = newProtocolButtonsFunctions.concat(newMavlinkButtonsNames)
controllerStore.availableProtocolButtonFunctions = newProtocolButtonsFunctions
Expand Down
2 changes: 1 addition & 1 deletion src/types/joystick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JoystickModel } from '@/libs/joystick/manager'
* Each protocol is expected to have it's own way of doing thing, including mapping, limiting, communicating, etc.
*/
export enum JoystickProtocol {
MAVLink = 'mavlink',
MAVLinkManualControl = 'mavlink-manual-control',
CockpitAction = 'cockpit-action',
Other = 'other',
}
Expand Down
20 changes: 11 additions & 9 deletions src/views/ConfigurationJoystickView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,15 @@ watch(inputClickedDialog, () => (justRemappedInput.value = undefined))
const availableProtocolButtonFunctions = computed(() => {
// eslint-disable-next-line jsdoc/require-jsdoc
const organizedButtons: { [key in JoystickProtocol]: InputWithPrettyName[] } = {
[JoystickProtocol.MAVLink]: [],
[JoystickProtocol.MAVLinkManualControl]: [],
[JoystickProtocol.CockpitAction]: [],
[JoystickProtocol.Other]: [],
}
controllerStore.availableProtocolButtonFunctions.forEach((btn) => organizedButtons[btn.input.protocol].push(btn))
vehicleStore.buttonParameterTable.forEach((btn) => {
if (organizedButtons[JoystickProtocol.MAVLink].map((b) => b.prettyName).includes(btn.title)) return
organizedButtons[JoystickProtocol.MAVLink].push({
input: { protocol: JoystickProtocol.MAVLink, value: btn.title },
if (organizedButtons[JoystickProtocol.MAVLinkManualControl].map((b) => b.prettyName).includes(btn.title)) return
organizedButtons[JoystickProtocol.MAVLinkManualControl].push({
input: { protocol: JoystickProtocol.MAVLinkManualControl, value: btn.title },
prettyName: btn.title,
})
})
Expand Down Expand Up @@ -374,21 +374,23 @@ const updateMapping = (index: number, newValue: ProtocolInput, inputType: InputT
let newInput = newValue
// When we use an unmapped MAVLink function, we use the same mapping but we have te new function to that button
if (newValue.protocol === JoystickProtocol.MAVLink && typeof newValue.value !== 'number') {
if (newValue.protocol === JoystickProtocol.MAVLinkManualControl && typeof newValue.value !== 'number') {
const buttonParameterValue = vehicleStore.buttonParameterTable.find((btn) => btn.title === newValue.value)?.value
if (buttonParameterValue === undefined) {
Swal.fire({ text: `Could not find MAVLink parameter ${newValue.value}.`, icon: 'error', timer: 5000 })
return
}
let mavlinkButton: undefined | number = undefined
const usedMavButtons = oldInputMapping.filter((i) => i.protocol === JoystickProtocol.MAVLink).map((i) => i.value)
const usedMavButtons = oldInputMapping
.filter((i) => i.protocol === JoystickProtocol.MAVLinkManualControl)
.map((i) => i.value)
const availableMavButtons = mavlinkAvailableButtons.filter((b) => !usedMavButtons.includes(b))
const oldButtonInput = oldInputMapping[index]
if (oldButtonInput.protocol !== JoystickProtocol.MAVLink && !availableMavButtons.isEmpty()) {
if (oldButtonInput.protocol !== JoystickProtocol.MAVLinkManualControl && !availableMavButtons.isEmpty()) {
mavlinkButton = availableMavButtons[0]
} else if (oldButtonInput.protocol === JoystickProtocol.MAVLink) {
} else if (oldButtonInput.protocol === JoystickProtocol.MAVLinkManualControl) {
// Check if there's more than one Cockpit button assigned to this same MAVLink button
const doubleMapped = usedMavButtons.filter((b) => b === oldButtonInput.value).length > 1
if (doubleMapped && !availableMavButtons.isEmpty()) {
Expand All @@ -408,7 +410,7 @@ const updateMapping = (index: number, newValue: ProtocolInput, inputType: InputT
Swal.fire({ text: errorMessage, icon: 'error', timer: 5000 })
return
}
newInput = { protocol: JoystickProtocol.MAVLink, value: mavlinkButton }
newInput = { protocol: JoystickProtocol.MAVLinkManualControl, value: mavlinkButton }
const configurationSettings: ArduPilotParameterSetData = {
id: `BTN${mavlinkButton}_FUNCTION`,
value: buttonParameterValue,
Expand Down

0 comments on commit b539026

Please sign in to comment.