feat: Meldung für Events darstellen (Kalibrierung, TDR ud Schleifenmessung)

This commit is contained in:
ISA
2025-08-13 12:13:16 +02:00
parent 48d634295a
commit 0fb6d184bd
13 changed files with 188 additions and 8 deletions

View File

@@ -0,0 +1,55 @@
"use client";
import React from "react";
import { useAppDispatch } from "@/redux/store";
import { setEvents } from "@/redux/slices/deviceEventsSlice";
declare global {
interface Window {
loopMeasurementEvent?: number[];
tdrMeasurementEvent?: number[];
alignmentEvent?: number[];
}
}
const POLL_MS = 2000; // poll every 2 seconds
export default function DeviceEventsBridge() {
const dispatch = useAppDispatch();
React.useEffect(() => {
let lastSig = "";
const readAndDispatch = () => {
const ksx = Array.isArray(window.loopMeasurementEvent)
? window.loopMeasurementEvent
: undefined;
const ksy = Array.isArray(window.tdrMeasurementEvent)
? window.tdrMeasurementEvent
: undefined;
const ksz = Array.isArray(window.alignmentEvent)
? window.alignmentEvent
: undefined;
// Build a stable signature of first 32 values per array
const to32 = (a?: number[]) => {
const out: number[] = [];
if (Array.isArray(a)) {
for (let i = 0; i < 32; i++) out.push(a[i] ? 1 : 0);
} else {
for (let i = 0; i < 32; i++) out.push(0);
}
return out;
};
const sig = `${to32(ksx).join("")}|${to32(ksy).join("")}|${to32(ksz).join(
""
)}`;
if (sig !== lastSig) {
lastSig = sig;
dispatch(setEvents({ ksx, ksy, ksz }));
}
};
readAndDispatch();
const id = setInterval(readAndDispatch, POLL_MS);
return () => clearInterval(id);
}, [dispatch]);
return null;
}

View File

@@ -0,0 +1,26 @@
"use client";
import React from "react";
import { useAppSelector } from "@/redux/store";
export default function GlobalActivityOverlay() {
const anyLoop = useAppSelector((s) => s.deviceEvents.anyLoopActive);
const anyTdr = useAppSelector((s) => s.deviceEvents.anyTdrActive);
const anyAlign = useAppSelector((s) => s.deviceEvents.anyAlignmentActive);
const active = anyLoop || anyTdr || anyAlign;
if (!active) return null;
const messages: string[] = [];
if (anyLoop) messages.push("Schleifenmessung läuft…");
if (anyTdr) messages.push("TDR-Messung läuft…");
if (anyAlign) messages.push("Abgleich läuft…");
return (
<div className="fixed inset-0 z-[2000] flex items-center justify-center bg-white/70 backdrop-blur-sm">
<div className="p-4 rounded-md shadow bg-white border border-gray-200">
<div className="font-semibold mb-2">Bitte warten</div>
<div className="text-sm text-gray-700">{messages.join(" · ")}</div>
</div>
</div>
);
}