Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert when Cockpit is minimized while vehicle is still armed #1379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/stores/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export const useAlertStore = defineStore('alert', () => {
watch(alerts, () => {
const lastAlert = alerts.slice(-1)[0]
const alertLevelEnabled = enabledAlertLevels.value.find((enabledAlert) => enabledAlert.level === lastAlert.level)
if (lastAlert.level === AlertLevel.Critical && alertLevelEnabled !== undefined && alertLevelEnabled.enabled) {
speak(lastAlert.message)
}
if (
!enableVoiceAlerts.value ||
((alertLevelEnabled === undefined || !alertLevelEnabled.enabled) && !lastAlert.message.startsWith('#'))
Expand Down
8 changes: 8 additions & 0 deletions src/stores/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '@/types/joystick'

import { useAlertStore } from './alert'
import { useMainVehicleStore } from './mainVehicle'

export type controllerUpdateCallback = (
state: JoystickState,
Expand All @@ -42,6 +43,8 @@ const cockpitStdMappingsKey = 'cockpit-standard-mappings-v2'

export const useControllerStore = defineStore('controller', () => {
const alertStore = useAlertStore()
const vehicleStore = useMainVehicleStore()

const joysticks = ref<Map<number, Joystick>>(new Map())
const updateCallbacks = ref<controllerUpdateCallback[]>([])
const protocolMappings = useBlueOsStorage(protocolMappingsKey, cockpitStandardToProtocols)
Expand Down Expand Up @@ -162,6 +165,11 @@ export const useControllerStore = defineStore('controller', () => {

if (value === 'hidden') {
console.warn('Window/tab hidden. Disabling joystick forwarding.')
if (vehicleStore.isArmed) {
const criticalMessage =
'Critical: Cockpit minimized while vehicle is armed. Joystick inputs will not work. Ensure vehicle safety.'
alertStore.pushAlert(new Alert(AlertLevel.Critical, criticalMessage))
}
enableForwarding.value = false
} else {
console.info('Window/tab visible. Enabling joystick forwarding.')
Expand Down
26 changes: 20 additions & 6 deletions src/views/ConfigurationAlertsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
class="flex flex-col justify-around align-start ml-5 max-h-[85vh] overflow-y-auto"
:class="interfaceStore.isOnSmallScreen ? 'max-w-[70vw]' : 'max-w-[40vw]'"
>
<v-switch
v-model="alertStore.enableVoiceAlerts"
label="Enable voice alerts"
color="white"
class="mt-2 -mb-2 ml-3"
/>
<div class="flex w-full justify-between pr-10">
<v-switch
v-model="alertStore.enableVoiceAlerts"
label="Enable voice alerts"
color="white"
class="mt-2 -mb-2 ml-3"
/>
<v-checkbox
v-model="alertStore.enabledAlertLevels.find((level) => level.level === AlertLevel.Critical)!.enabled"
v-tooltip="
'Critical system alerts work separately from your voice alert settings. These alerts are rare but really important, so we recommend keeping them on.'
"
label="Critical system alerts"
hide-details
color="white"
class="mt-1"
/>
</div>
Comment on lines +16 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with reusing the Critical level is that it's being also used on MAV_SEVERITY_EMERGENCY, MAV_SEVERITY_ALERT and MAV_SEVERITY_CRITICAL, from Ardupilot. Their names suggest that they are only thrown on very critical situations, but I have found it to not be true.

Right now, with the Critical level enabled (which I want to have for the joystick warning), I'm being spammed by "Ardupilot logger stuck thread" voice alerts, so I will have to disable the critical level, and in consequence I will lose the joystick alert, which I want to have.

I can think of three solutions here:

  1. Have this joystick alert on a separate level.

  2. Make each MAV_SEVERITY have it's own dedicated level.

  3. Create a dynamic alert registration system, where each new alert will create an entry for it in the alerts menu, and the user will be able to disable each alert individually.

Solution 1 is the easy one. Solution 2 is also easy and more long-term, but makes Cockpit more tied to Ardupilot (and we want to go in the opposite direction). Solution 3 seems to be the correct one, but takes a little more work (although not that much I think).

<ExpansiblePanel :is-expanded="!interfaceStore.isOnPhoneScreen">
<template #title> Enable voice on specific alert levels:</template>
<template #info
Expand All @@ -26,6 +38,7 @@
class="mx-2 min-w-[100px]"
>
<v-checkbox
v-if="enabledLevel.level !== AlertLevel.Critical"
v-model="enabledLevel.enabled"
:label="capitalize(enabledLevel.level)"
hide-details
Expand Down Expand Up @@ -55,6 +68,7 @@ import Dropdown from '@/components/Dropdown.vue'
import ExpansiblePanel from '@/components/ExpansiblePanel.vue'
import { useAlertStore } from '@/stores/alert'
import { useAppInterfaceStore } from '@/stores/appInterface'
import { AlertLevel } from '@/types/alert'

import BaseConfigurationView from './BaseConfigurationView.vue'

Expand Down
Loading