Skip to content

Commit

Permalink
refactor: update interface of DD
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakrok09 committed Aug 25, 2024
1 parent 7049bae commit 924e2a0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/control/CommandButton.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/tauri";
import util from "$lib/util.js";
import { util } from "$lib";
import { getContext } from "svelte";
import type { FinalizedConfig } from "$lib/appShell/SerpentaConfig";
Expand Down
16 changes: 2 additions & 14 deletions src/lib/components/control/TauriCommandButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,8 @@
import type { FinalizedConfig } from "$lib/appShell/SerpentaConfig";
export let className: string = "";
export let cmd:
| "connect_to_pod"
| "start_levi"
| "quit_levi"
| "disconnect"
| "procedures"
| "save_logs"
| "test_route"
| "speeds_to_u64"
| "speeds_from_u64"
| "positions_to_u64"
| "positions_from_u64"
| "demonstration_a"
| "demonstration_b";
export let cmd: string;
export let successCallback: (r: any) => void = () => {};
export let errorCallback: (error: string) => void = () => {};
export let textOverride: string = "";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/data/Store.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const STALE_DATA_TICKS = 10_000;
export let datatype: string;
const store = gdd.stores.getWritable(datatype);
const store = gdd.getWritable(datatype);
$: store;
</script>
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/graphic/FSM.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
let moving_ls_st: SVGGElement;
let all_states: SVGGElement[];
const storeManager = gdd.stores;
const fsmState = storeManager.getWritable<number>("FSMState");
const fsmState = gdd.getWritable<number>("FSMState");
function turn_on(state: SVGGElement) {
if (!state || !state.style) return;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/page/BottomBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const config: FinalizedConfig = getContext<FinalizedConfig>("serpenta-config");
const gdd: DataDistributor = config.grand_data_distributor;
const bigErrorStatus: Writable<ErrorStatus> = config.big_error;
const fsmStateName: string = config.stores.fsm;
const podName: string = config.pod_name;
Expand All @@ -33,7 +32,7 @@
};
});
const fsmState = gdd.stores.getWritable(fsmStateName);
const fsmState = gdd.getWritable(fsmStateName);
</script>

<footer
Expand Down
34 changes: 10 additions & 24 deletions src/lib/middleware/DataDistributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,25 @@ export interface DataDistributor {
kill(): void;

/**
* Get the store manager
* @note considered refactoring.
*/
get stores(): StoreManager;
}

/**
* The StoreManager class is responsible for managing the data stores
*/
interface StoreManager {
/**
* Register a store
* Register a store.
* @param name - the name of the store
* @param initial
* @param initialUnits
* @param initial - initial value of the store
* @param processFunction - the function to process the data
* @param initialUnits - units of the store
* @see dataConvFun
*/
registerStore<T>(name: string, initial: T, processFunction?: dataConvFun<T>, initialUnits?: string): void;

/**
* Update a store
* @param name - the name of the store
* @param timestamp
* @param style
* @param units
* @param data - the data to update the store with
* @param name the name of the store
* @param style the style of the store as to what colour it shall become
* @param units the units of this store.
* These do not get changed often but are sent from the config, so they are kept.
* @param data the data to update the store with
*/
updateStore(name: string, timestamp: number, style: string, units: string, data: number): void;
updateStore(name: string, style: string, units: string, data: number): void;

getValue<T>(name: string): T;

getWritable<T>(name: string): Writable<Store<T>>;
}
Expand All @@ -77,10 +66,7 @@ interface Store<T> {
readonly processFunction: dataConvFun<T>;

get value(): T;

get style(): string;

get units(): string;

get timestamp(): number;
}

0 comments on commit 924e2a0

Please sign in to comment.