changes done to manage pw state

This commit is contained in:
bsaravanan783
2025-06-03 21:56:52 +05:30
parent 6e02a73eb6
commit 686328a688
2 changed files with 19 additions and 6 deletions

View File

@@ -12,7 +12,8 @@
probingComplete,
probingFailed,
probingStarted,
systemReady
systemReady,
homeMachineComplete
} from "$lib/ControllerState";
import { numberWithUnit } from "$lib/RegexHelpers";
import TextFieldWithOptions from "$components/TextFieldWithOptions.svelte";
@@ -131,11 +132,18 @@
async function begin() {
try {
if (!get(systemReady)) {
// Wait for both system ready and home machine completion
if (!get(systemReady) || !get(homeMachineComplete)) {
await new Promise(resolve => {
const unsubscribe = systemReady.subscribe(ready => {
if (ready) {
unsubscribe();
const unsubscribeSystem = systemReady.subscribe(ready => {
if (ready && get(homeMachineComplete)) {
unsubscribeSystem();
resolve(true);
}
});
const unsubscribeHome = homeMachineComplete.subscribe(homeComplete => {
if (homeComplete && get(systemReady)) {
unsubscribeHome();
resolve(true);
}
});

View File

@@ -9,13 +9,18 @@ export const probingFailed = writable(false);
export const probingStarted = writable(false);
export const probingComplete = writable(false);
export const systemReady = writable(false);
export const homeMachineComplete = writable(false);
export function handleControllerStateUpdate(state: Record<string, any>) {
if (!get(systemReady)) {
systemReady.set(true);
}
if (get(probingActive) && get(systemReady)) {
if (state.xx === "READY" && !get(homeMachineComplete)) {
homeMachineComplete.set(true);
}
if (get(probingActive) && get(systemReady) && get(homeMachineComplete)) {
if (state.pw === 0) {
probeContacted.set(true);
}