Skip to content

Commit

Permalink
Add vehicle disconnection alert
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl authored and patrickelectric committed Aug 23, 2023
1 parent 1e45f63 commit 1dab3da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import type {
} from '@/libs/vehicle/types'
import * as Vehicle from '@/libs/vehicle/vehicle'
import { VehicleFactory } from '@/libs/vehicle/vehicle-factory'
import { Alert, AlertLevel } from '@/types/alert'
import { type MetadataFile } from '@/types/ardupilot-metadata'
import {
type JoystickState,
Expand All @@ -45,7 +44,6 @@ import {
} from '@/types/joystick'
import type { MissionLoadingCallback, Waypoint } from '@/types/mission'

import { useAlertStore } from './alert'
import { useControllerStore } from './controller'

/**
Expand Down Expand Up @@ -97,8 +95,6 @@ class CustomizableParameter<T> {
}

export const useMainVehicleStore = defineStore('main-vehicle', () => {
const alertStore = useAlertStore()

const cpuLoad = ref<number>()
const globalAddress = useStorage('cockpit-vehicle-address', defaultGlobalAddress)
const _mainConnectionURI = new CustomizableParameter<Connection.URI>(() => {
Expand Down Expand Up @@ -249,7 +245,6 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
modes.value = mainVehicle.value.modesAvailable()
icon.value = mainVehicle.value.icon()
configurationPages.value = mainVehicle.value.configurationPages()
alertStore.pushAlert(new Alert(AlertLevel.Success, 'Vehicle connected'))

mainVehicle.value.onAltitude.add((newAltitude: Altitude) => {
Object.assign(altitude, newAltitude)
Expand Down
9 changes: 9 additions & 0 deletions src/stores/vehicleAlerter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export const useVehicleAlerterStore = defineStore('vehicle-alerter', () => {
alertStore.pushAlert(new Alert(AlertLevel.Info, `Vehicle ${state}`))
}
)

watch(
() => vehicleStore.isVehicleOnline,
(isOnlineNow) => {
const alertLevel = isOnlineNow ? AlertLevel.Success : AlertLevel.Error
const alertMessage = isOnlineNow ? 'connected' : 'disconnected'
alertStore.pushAlert(new Alert(alertLevel, `Vehicle ${alertMessage}`))
}
)
})

0 comments on commit 1dab3da

Please sign in to comment.