Skip to content

Commit

Permalink
Add vehicle disconnection alert
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Aug 22, 2023
1 parent 8ecfaa7 commit f75bb9c
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 @@ -34,7 +34,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 @@ -44,7 +43,6 @@ import {
} from '@/types/joystick'
import type { MissionLoadingCallback, Waypoint } from '@/types/mission'

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

/**
Expand Down Expand Up @@ -96,8 +94,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 @@ -247,7 +243,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 f75bb9c

Please sign in to comment.