From b539026cb8030ce512b9f743aaab20123d71997a Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 26 Oct 2023 18:11:09 -0300 Subject: [PATCH] Rename protocol name from `MAVLink` to `MAVLinkManualControl` 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. --- src/assets/joystick-profiles.ts | 38 ++++++++++++------------- src/libs/joystick/protocols.ts | 11 ++++--- src/stores/mainVehicle.ts | 4 +-- src/types/joystick.ts | 2 +- src/views/ConfigurationJoystickView.vue | 20 +++++++------ 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/assets/joystick-profiles.ts b/src/assets/joystick-profiles.ts index b5f88c67c..8747fb1db 100644 --- a/src/assets/joystick-profiles.ts +++ b/src/assets/joystick-profiles.ts @@ -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 }, ], } diff --git a/src/libs/joystick/protocols.ts b/src/libs/joystick/protocols.ts index b63c7988e..896f2e2ba 100644 --- a/src/libs/joystick/protocols.ts +++ b/src/libs/joystick/protocols.ts @@ -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++) { @@ -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 @@ -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) => @@ -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 }) diff --git a/src/stores/mainVehicle.ts b/src/stores/mainVehicle.ts index ed65fcf28..325dacce6 100644 --- a/src/stores/mainVehicle.ts +++ b/src/stores/mainVehicle.ts @@ -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 diff --git a/src/types/joystick.ts b/src/types/joystick.ts index 7ab9970dc..20ce0af5d 100644 --- a/src/types/joystick.ts +++ b/src/types/joystick.ts @@ -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', } diff --git a/src/views/ConfigurationJoystickView.vue b/src/views/ConfigurationJoystickView.vue index 871f4e304..5bcf9e7cb 100644 --- a/src/views/ConfigurationJoystickView.vue +++ b/src/views/ConfigurationJoystickView.vue @@ -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, }) }) @@ -374,7 +374,7 @@ 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 }) @@ -382,13 +382,15 @@ const updateMapping = (index: number, newValue: ProtocolInput, inputType: InputT } 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()) { @@ -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,