From 5eee77d76e3db99fb827dbbee837535dec1e0f74 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 19 Nov 2023 11:51:45 -0800 Subject: [PATCH] update to allow mode selector to show current mode --- src/stores/mainVehicle.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/stores/mainVehicle.ts b/src/stores/mainVehicle.ts index 77061f8b7..d1db7a457 100644 --- a/src/stores/mainVehicle.ts +++ b/src/stores/mainVehicle.ts @@ -254,6 +254,15 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { return (vehicle as ArduPilot) || undefined } + function getStringFromValue(map: Map, value: number): string | undefined { + for (const [key, val] of map.entries()) { + if (val === value) { + return key; + } + } + return undefined; + } + VehicleFactory.onVehicles.once((vehicles: WeakRef[]) => { mainVehicle.value = getAutoPilot(vehicles) modes.value = mainVehicle.value.modesAvailable() @@ -303,6 +312,9 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { firmwareType.value = heartbeat.autopilot.type vehicleType.value = heartbeat.mavtype.type lastHeartbeat.value = new Date() + if (modes.value !== undefined) { + mode.value = getStringFromValue(modes.value, heartbeat.custom_mode); + } }) // eslint-disable-next-line @typescript-eslint/no-explicit-any getAutoPilot(vehicles).onMode.add((vehicleMode: any) => {