Emit imu, mag and bmp data

This commit is contained in:
Rune Harlyk
2025-11-27 17:38:37 +01:00
parent 7d2f384898
commit 6c61227623
5 changed files with 38 additions and 10 deletions
+18 -5
View File
@@ -1,5 +1,5 @@
import { writable } from 'svelte/store'
import type { IMU } from '$lib/types/models'
import type { IMUMsg } from '$lib/types/models'
const maxIMUData = 100
@@ -14,11 +14,24 @@ export const imu = (() => {
bmp_temp: [] as number[]
})
const addData = (content: IMU) => {
const addData = (content: IMUMsg) => {
update(data => {
;(Object.keys(content) as (keyof IMU)[]).forEach(key => {
data[key] = [...data[key], content[key]].slice(-maxIMUData)
})
if (content.imu && content.imu[3]) {
data.x = [...data.x, content.imu[0]].slice(-maxIMUData)
data.y = [...data.y, content.imu[1]].slice(-maxIMUData)
data.z = [...data.z, content.imu[2]].slice(-maxIMUData)
}
if (content.mag && content.mag[4]) {
data.heading = [...data.heading, content.mag[3]].slice(-maxIMUData)
}
if (content.bmp && content.bmp[3]) {
data.pressure = [...data.pressure, content.bmp[0]].slice(-maxIMUData)
data.altitude = [...data.altitude, content.bmp[1]].slice(-maxIMUData)
data.bmp_temp = [...data.bmp_temp, content.bmp[2]].slice(-maxIMUData)
}
return data
})
}
+6
View File
@@ -154,6 +154,12 @@ export type IMU = {
pressure: number
}
export type IMUMsg = {
imu: [number, number, number, boolean]
mag: [number, number, number, number, boolean]
bmp: [number, number, number, boolean]
}
export interface I2CDevice {
address: number
part_number: string