Skip to content

Commit

Permalink
update to allow mode selector to show current mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjohnson97 committed Nov 19, 2023
1 parent b73b03a commit 5eee77d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
return (vehicle as ArduPilot) || undefined
}

function getStringFromValue(map: Map<string, number>, value: number): string | undefined {
for (const [key, val] of map.entries()) {
if (val === value) {
return key;
}
}
return undefined;
}

VehicleFactory.onVehicles.once((vehicles: WeakRef<Vehicle.Abstract>[]) => {
mainVehicle.value = getAutoPilot(vehicles)
modes.value = mainVehicle.value.modesAvailable()
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 5eee77d

Please sign in to comment.