diff --git a/src/libs/joystick/protocols/mavlink-manual-control.ts b/src/libs/joystick/protocols/mavlink-manual-control.ts index 439edeab8..1ab49d9f6 100644 --- a/src/libs/joystick/protocols/mavlink-manual-control.ts +++ b/src/libs/joystick/protocols/mavlink-manual-control.ts @@ -295,6 +295,7 @@ export class MavlinkManualControlManager { parametersTable: { title: string; value: number }[] = [] vehicleButtonParameterTable: { title: string; value: number }[] = [] currentVehicleParameters: { [key in string]: number } = {} + vehicleTotalParametersCount: number | undefined = undefined public vehicle: ArduPilot | undefined constructor() { @@ -308,9 +309,10 @@ export class MavlinkManualControlManager { this.vehicle = vehicle // Update interval parameters when they are available - this.vehicle.onParameter.add((newParameter: Parameter) => { + this.vehicle.onParameter.add(([newParameter, parametersCount]) => { const newVehicleParameters = { ...this.currentVehicleParameters, ...{ [newParameter.name]: newParameter.value } } this.currentVehicleParameters = newVehicleParameters + this.vehicleTotalParametersCount = parametersCount }) this.vehicle.requestParametersList() @@ -423,7 +425,13 @@ export class MavlinkManualControlManager { } remapActionsToVehicleButtonParameters = (): void => { - if (!this.vehicle || !this.currentActionsMapping || !this.currentVehicleParameters || !this.vehicleButtonParameterTable) return + if (!this.vehicle || !this.currentActionsMapping || !this.currentVehicleParameters || !this.vehicleButtonParameterTable || !this.vehicleTotalParametersCount) return + // Do not proceed with remapping unless we already have all parameters downloaded + // This prevents us from thinking some function is not mapped in the vehicle when in fact we just didn't download it yet + const allParametersDownloaded = Object.entries(this.currentVehicleParameters).length >= this.vehicleTotalParametersCount + if (!allParametersDownloaded) { + return + } const buttonParametersNamedObject: { [key in number]: string } = {} this.vehicleButtonParameterTable.forEach((entry) => (buttonParametersNamedObject[entry.value] = entry.title)) diff --git a/src/libs/vehicle/ardupilot/ardupilot.ts b/src/libs/vehicle/ardupilot/ardupilot.ts index 1aeb6217a..168a98f5f 100644 --- a/src/libs/vehicle/ardupilot/ardupilot.ts +++ b/src/libs/vehicle/ardupilot/ardupilot.ts @@ -69,6 +69,7 @@ export abstract class ArduPilotVehicle extends Vehicle.AbstractVehicle extends Vehicle.AbstractVehicle extends Vehicle.AbstractVehicle { onMode = new Signal() onPosition = new Signal() onPowerSupply = new Signal() - onParameter = new Signal() + onParameter = new Signal<[Parameter, number | undefined]>() onStatusGPS = new Signal() onStatusText = new Signal() onVelocity = new Signal() @@ -114,7 +114,7 @@ export abstract class AbstractVehicle { this.onMode.register_caller(() => this.mode()) this.onPosition.register_caller(() => this.position()) this.onPowerSupply.register_caller(() => this.powerSupply()) - this.onParameter.register_caller(() => this.lastParameter()) + this.onParameter.register_caller(() => [this.lastParameter(), this.totalParametersCount()]) this.onStatusText.register_caller(() => this.statusText()) this.onStatusGPS.register_caller(() => this.statusGPS()) this.onVelocity.register_caller(() => this.velocity()) @@ -180,6 +180,7 @@ export abstract class AbstractVehicle { abstract position(): Coordinates abstract velocity(): Velocity abstract powerSupply(): PowerSupply + abstract totalParametersCount(): number | undefined abstract lastParameter(): Parameter abstract statusText(): StatusText abstract statusGPS(): StatusGPS diff --git a/src/stores/controller.ts b/src/stores/controller.ts index fc23b9811..18ffd8de3 100644 --- a/src/stores/controller.ts +++ b/src/stores/controller.ts @@ -25,7 +25,7 @@ export type controllerUpdateCallback = ( export const useControllerStore = defineStore('controller', () => { const joysticks = ref>(new Map()) const updateCallbacks = ref([]) - const protocolMapping = useStorage('cockpit-protocol-mapping-v5.2', cockpitStandardToProtocols) + const protocolMapping = useStorage('cockpit-protocol-mapping-v5.3', cockpitStandardToProtocols) const cockpitStdMappings = useStorage('cockpit-standard-mappings', availableGamepadToCockpitMaps) const availableAxesActions = allAvailableAxes const availableButtonActions = allAvailableButtons