From 98f3fc674b1d5b8d5e963e5ec53dc949fa29a54e Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 11 Jul 2025 18:59:07 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Makes=20socket=20messages=20event?= =?UTF-8?q?=20typed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/types/models.ts | 17 ++ app/src/routes/+layout.svelte | 108 ++++---- app/src/routes/controller/+page.svelte | 46 ++-- app/src/routes/peripherals/i2c/i2c.svelte | 8 +- .../routes/peripherals/i2c/i2cSetting.svelte | 10 +- app/src/routes/peripherals/imu/imu.svelte | 176 ++++++------ .../routes/peripherals/servo/servos.svelte | 7 +- .../routes/system/status/SystemStatus.svelte | 112 ++++---- app/src/routes/wifi/sta/Wifi.svelte | 257 +++++++++--------- 9 files changed, 382 insertions(+), 359 deletions(-) diff --git a/app/src/lib/types/models.ts b/app/src/lib/types/models.ts index ac53ff3..e0bdc0c 100644 --- a/app/src/lib/types/models.ts +++ b/app/src/lib/types/models.ts @@ -1,3 +1,20 @@ +export enum Topics { + imu = 'imu', + mode = 'mode', + input = 'input', + analytics = 'analytics', + position = 'position', + angles = 'angles', + i2cScan = 'i2cScan', + peripheralSettings = 'peripheralSettings', + otastatus = 'otastatus', + servoState = 'servoState', + servoPWM = 'servoPWM', + WiFiSettings = 'WiFiSettings', + sonar = 'sonar', + rssi = 'rssi' +} + export type vector = { x: number; y: number } export interface ControllerInput { diff --git a/app/src/routes/+layout.svelte b/app/src/routes/+layout.svelte index 8640690..7a3c2a5 100644 --- a/app/src/routes/+layout.svelte +++ b/app/src/routes/+layout.svelte @@ -1,13 +1,13 @@ diff --git a/app/src/routes/controller/+page.svelte b/app/src/routes/controller/+page.svelte index bd5c629..c81a23d 100644 --- a/app/src/routes/controller/+page.svelte +++ b/app/src/routes/controller/+page.svelte @@ -1,31 +1,31 @@
- -
- -
+ +
+ +
diff --git a/app/src/routes/peripherals/i2c/i2c.svelte b/app/src/routes/peripherals/i2c/i2c.svelte index ec42e28..0410feb 100644 --- a/app/src/routes/peripherals/i2c/i2c.svelte +++ b/app/src/routes/peripherals/i2c/i2c.svelte @@ -2,7 +2,7 @@ import SettingsCard from '$lib/components/SettingsCard.svelte' import { onMount } from 'svelte' import { socket } from '$lib/stores' - import type { I2CDevice } from '$lib/types/models' + import { Topics, type I2CDevice } from '$lib/types/models' import { Connection } from '$lib/components/icons' import I2CSetting from './i2cSetting.svelte' @@ -24,9 +24,9 @@ let isLoading = $state(false) onMount(() => { - socket.on('i2cScan', handleScan) + socket.on(Topics.i2cScan, handleScan) triggerScan() - return () => socket.off('i2cScan', handleScan) + return () => socket.off(Topics.i2cScan, handleScan) }) const handleScan = (data: any) => { @@ -43,7 +43,7 @@ const triggerScan = () => { isLoading = true - socket.sendEvent('i2cScan', '') + socket.sendEvent(Topics.i2cScan, '') } diff --git a/app/src/routes/peripherals/i2c/i2cSetting.svelte b/app/src/routes/peripherals/i2c/i2cSetting.svelte index 059facc..1500117 100644 --- a/app/src/routes/peripherals/i2c/i2cSetting.svelte +++ b/app/src/routes/peripherals/i2c/i2cSetting.svelte @@ -1,7 +1,7 @@ diff --git a/app/src/routes/peripherals/servo/servos.svelte b/app/src/routes/peripherals/servo/servos.svelte index 021b736..0afdf98 100644 --- a/app/src/routes/peripherals/servo/servos.svelte +++ b/app/src/routes/peripherals/servo/servos.svelte @@ -1,5 +1,6 @@ diff --git a/app/src/routes/wifi/sta/Wifi.svelte b/app/src/routes/wifi/sta/Wifi.svelte index c25f320..5a35357 100644 --- a/app/src/routes/wifi/sta/Wifi.svelte +++ b/app/src/routes/wifi/sta/Wifi.svelte @@ -1,19 +1,24 @@ @@ -312,7 +317,7 @@ @@ -368,8 +373,8 @@ class="btn btn-primary text-primary-content btn-md absolute -top-14 right-0" onclick={() => { if (checkNetworkList()) { - scanForNetworks(); - showNetworkEditor = true; + scanForNetworks() + showNetworkEditor = true } }}> @@ -389,13 +394,13 @@