🪇 Implements major structure and service refactors

This commit is contained in:
Rune Harlyk
2024-08-19 20:13:57 +02:00
committed by Rune Harlyk
parent 9978918bf9
commit 3da1717341
23 changed files with 139 additions and 121 deletions
+20 -29
View File
@@ -1,36 +1,27 @@
import { type IMU } from '$lib/types/models';
import { writable } from 'svelte/store';
let imu_data = {
x: <number[]>[],
y: <number[]>[],
z: <number[]>[],
imu_temp: <number[]>[],
altitude: <number[]>[],
pressure: <number[]>[],
bmp_temp: <number[]>[]
};
import type { IMU } from '$lib/types/models';
const maxIMUData = 100;
function createIMU() {
const { subscribe, update } = writable(imu_data);
export const imu = (() => {
const { subscribe, update } = writable({
x: [] as number[],
y: [] as number[],
z: [] as number[],
imu_temp: [] as number[],
altitude: [] as number[],
pressure: [] as number[],
bmp_temp: [] as number[]
});
return {
subscribe,
addData: (content: IMU) => {
update((imu_data) => ({
...imu_data,
x: [...imu_data.x, content.x].slice(-maxIMUData),
y: [...imu_data.y, content.y].slice(-maxIMUData),
z: [...imu_data.z, content.z].slice(-maxIMUData),
imu_temp: [...imu_data.imu_temp, content.imu_temp].slice(-maxIMUData),
altitude: [...imu_data.altitude, content.altitude].slice(-maxIMUData),
pressure: [...imu_data.pressure, content.pressure].slice(-maxIMUData),
bmp_temp: [...imu_data.bmp_temp, content.bmp_temp].slice(-maxIMUData)
}));
}
const addData = (content: IMU) => {
update((data) => {
(Object.keys(content) as (keyof IMU)[]).forEach((key) => {
data[key] = [...data[key], content[key]].slice(-maxIMUData);
});
return data;
});
};
}
export const imu = createIMU();
return { subscribe, addData };
})();