Skip to content

Commit 4a98c8b

Browse files
committed
core: frontend: add notification for uncalibrated sensors
1 parent 015b99c commit 4a98c8b

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

core/frontend/src/components/health/HealthTrayMenu.vue

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
<v-icon
9191
v-if="heartbeat_age() < time_limit_heartbeat"
9292
class="px-1"
93-
:color="`rgba(255,255,255,${0.4 + (1000 - heartbeat_age()) / 1000}`"
94-
title="MAVLink heartbeats arriving as expected"
93+
:color="heartbeat_color()"
94+
:title="heartbeat_message()"
9595
>
9696
mdi-heart-pulse
9797
</v-icon>
@@ -125,6 +125,22 @@
125125
<td>Current:</td>
126126
<td> {{ battery_current }} A</td>
127127
</tr>
128+
<tr v-for="(calibrated, sensor_name,) in ardupilot_sensors.sensors" :key="sensor_name">
129+
<td class="sensor-type">
130+
{{ sensor_name }}:
131+
</td>
132+
<td v-if="!calibrated">
133+
<v-btn
134+
x-small
135+
:to="{ name: 'Vehicle Setup', params: { tab: 'configure', subtab: sensor_name } }"
136+
>
137+
Calibrate
138+
</v-btn>
139+
</td>
140+
<td v-else>
141+
Calibrated
142+
</td>
143+
</tr>
128144
</table>
129145
</div>
130146
</v-container>
@@ -136,11 +152,14 @@
136152
<script lang="ts">
137153
import Vue from 'vue'
138154
155+
import { convertHexToRgbd } from '@/cosmos'
139156
import mavlink2rest from '@/libs/MAVLink2Rest'
140157
import { MavModeFlag, MavType } from '@/libs/MAVLink2Rest/mavlink2rest-ts/messages/mavlink2rest-enum'
158+
import ardupilot_sensors from '@/store/ardupilot_sensors'
141159
import autopilot_data from '@/store/autopilot'
142160
import mavlink from '@/store/mavlink'
143161
import system_information from '@/store/system-information'
162+
import * as DEFAULT_COLORS from '@/style/colors/default'
144163
import { RaspberryEventType } from '@/types/system-information/platform'
145164
import { Disk } from '@/types/system-information/system'
146165
import mavlink_store_get from '@/utils/mavlink'
@@ -206,6 +225,9 @@ export default Vue.extend({
206225
disk_usage_high(): boolean {
207226
return this.disk_usage_percent > 85
208227
},
228+
ardupilot_sensors() {
229+
return ardupilot_sensors
230+
},
209231
},
210232
mounted() {
211233
mavlink2rest.startListening('HEARTBEAT').setCallback((message) => {
@@ -244,6 +266,20 @@ export default Vue.extend({
244266
'MAV_TYPE_VTOL_TAILSITTER',
245267
].includes(type)
246268
},
269+
heartbeat_color() : string {
270+
const selected_color = ardupilot_sensors.all_sensors_calibrated
271+
? DEFAULT_COLORS.SHEET_LIGHT_BG : DEFAULT_COLORS.WARNING
272+
const [r, g, b] = convertHexToRgbd(selected_color)
273+
const opacity = Math.max(0.4, 1.4 - this.heartbeat_age() / 1000)
274+
275+
return `rgba(${r}, ${g}, ${b}, ${opacity})`
276+
},
277+
heartbeat_message() : string {
278+
if (ardupilot_sensors.all_sensors_calibrated) {
279+
return 'MAVLink heartbeats arriving as expected'
280+
}
281+
return 'One or more sensors are not calibrated'
282+
},
247283
},
248284
})
249285
</script>
@@ -261,4 +297,8 @@ export default Vue.extend({
261297
.white-shadow {
262298
text-shadow: 0 0 3px #FFF;
263299
}
300+
301+
.sensor-type {
302+
text-transform: capitalize;
303+
}
264304
</style>

core/frontend/src/cosmos.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { vec3 } from "gl-matrix";
2+
13
export {}
24

35
declare global {
@@ -56,6 +58,19 @@ String.prototype.toTitle = function (this: string): string {
5658
return this[0].toUpperCase() + this.substring(1)
5759
}
5860

61+
/**
62+
* Converts a hexadecimal color code to RGB values
63+
* @param color - The hexadecimal color code (with or without '#' prefix)
64+
* @returns A vec3 array containing the RGB values as integers [r, g, b] where each value is 0-255
65+
*/
66+
export const convertHexToRgbd = (color: string): vec3 => {
67+
color = color.replace('#', '')
68+
const r = parseInt(color.substring(0, 2), 16)
69+
const g = parseInt(color.substring(2, 4), 16)
70+
const b = parseInt(color.substring(4, 6), 16)
71+
return [r, g, b]
72+
}
73+
5974

6075
/**
6176
* Utility functions for clipboard operations

0 commit comments

Comments
 (0)