From 04fecf33f873709c415cde77cbc5732675340d84 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sun, 4 Aug 2024 13:53:53 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B4=20Adds=20webserial=20lidar=20suppo?= =?UTF-8?q?rt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/components/Lidar.svelte | 32 +++---- app/src/lib/stores/lidar.ts | 29 ++++++ app/src/routes/menu.svelte | 7 ++ app/src/routes/peripherals/lidar/+page.svelte | 7 ++ app/src/routes/peripherals/lidar/lidar.svelte | 95 +++++++++++++++++++ 5 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 app/src/lib/stores/lidar.ts create mode 100644 app/src/routes/peripherals/lidar/+page.svelte create mode 100644 app/src/routes/peripherals/lidar/lidar.svelte diff --git a/app/src/lib/components/Lidar.svelte b/app/src/lib/components/Lidar.svelte index fdeed2a..8f05a4f 100644 --- a/app/src/lib/components/Lidar.svelte +++ b/app/src/lib/components/Lidar.svelte @@ -1,5 +1,6 @@ diff --git a/app/src/lib/stores/lidar.ts b/app/src/lib/stores/lidar.ts new file mode 100644 index 0000000..424f723 --- /dev/null +++ b/app/src/lib/stores/lidar.ts @@ -0,0 +1,29 @@ +import { writable } from 'svelte/store'; + +export type LidarPoint = { + distance: number; + angle: number; + quality: number; +}; + +let lidar_data = { + points: [] +}; + +const maxLidarData = 600; + +function createLidar() { + const { subscribe, update } = writable(lidar_data); + + return { + subscribe, + addData: (lidarPoint: LidarPoint) => { + update((lidar_data) => ({ + ...lidar_data, + points: [...lidar_data.points, lidarPoint].slice(-maxLidarData) + })); + } + }; +} + +export const lidar = createLidar(); diff --git a/app/src/routes/menu.svelte b/app/src/routes/menu.svelte index 89e305c..42f041e 100644 --- a/app/src/routes/menu.svelte +++ b/app/src/routes/menu.svelte @@ -8,6 +8,7 @@ import Devices from '~icons/mdi/devices' import Camera from '~icons/mdi/camera-outline'; import Rotate3d from '~icons/mdi/rotate-3d'; + import MdiLandslideOutline from '~icons/mdi/landslide-outline'; import MotorOutline from '~icons/mdi/motor-outline'; import Health from '~icons/mdi/stethoscope'; import Folder from '~icons/mdi/folder-outline'; @@ -83,6 +84,12 @@ icon: Rotate3d, href: '/peripherals/imu', feature: $page.data.features.imu || $page.data.features.mag || $page.data.features.bmp, + }, + { + title: 'Lidar', + icon: MdiLandslideOutline, + href: '/peripherals/lidar', + feature: true//$page.data.features.lidar, } ] }, diff --git a/app/src/routes/peripherals/lidar/+page.svelte b/app/src/routes/peripherals/lidar/+page.svelte new file mode 100644 index 0000000..22c6c5c --- /dev/null +++ b/app/src/routes/peripherals/lidar/+page.svelte @@ -0,0 +1,7 @@ + + +
+ +
diff --git a/app/src/routes/peripherals/lidar/lidar.svelte b/app/src/routes/peripherals/lidar/lidar.svelte new file mode 100644 index 0000000..84ab5c2 --- /dev/null +++ b/app/src/routes/peripherals/lidar/lidar.svelte @@ -0,0 +1,95 @@ + + + + + Lidar +
+ +
+
+ +
+
+ +
+
\ No newline at end of file