📜 Makes data sync more seamless

This commit is contained in:
Rune Harlyk
2024-02-23 13:43:23 +01:00
parent 04c3603254
commit 99a185ac82
9 changed files with 228 additions and 134 deletions
+5
View File
@@ -2,6 +2,7 @@ import { isConnected, socketData } from '$lib/stores';
import { Result, Ok } from '$lib/utilities';
import { resultService } from '$lib/services';
import { type WebSocketJsonMsg } from '$lib/models';
import type { Writable } from 'svelte/store';
type WebsocketOutData = string | ArrayBufferLike | Blob | ArrayBufferView;
@@ -37,6 +38,10 @@ class SocketService {
return Result.err('The connection is not open');
}
public addPublisher(store: Writable<WebsocketOutData>, type?: string) {
store.subscribe((data) => this.send(type ? JSON.stringify({ type, data }) : data));
}
private handleConnected(): void {
isConnected.set(true);
}
+1 -1
View File
@@ -10,7 +10,7 @@ export const input = writable({
speed: 0
});
export const outControllerData = writable(new Uint8Array([0, 128, 128, 128, 128, 70, 0]));
export const outControllerData = writable(new Int8Array([0, 0, 0, 0, 0, 70, 0]));
export const jointNames = persistentStore('joint_names', []);
+6
View File
@@ -3,3 +3,9 @@ export const toUint8 = (number: number, min: number, max: number) => {
let scaled = ((number - min) / (max - min)) * 255;
return Math.round(scaled) & 0xff;
};
export const toInt8 = (number: number, min: number, max: number) => {
number = Math.max(min, Math.min(max, number));
let scaled = ((number - min) / (max - min)) * 255 - 128;
return Math.max(-128, Math.min(127, Math.round(scaled))) | 0;
};