mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 10:00:46 -04:00
puh
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-Bgtbi1T2.js"></script>
|
<script type="module" crossorigin src="/assets/index-ChuD7eTF.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-CCqAmxiE.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ function clampServoAngle(config, value) {
|
|||||||
export function ControlSystemProvider({ children }) {
|
export function ControlSystemProvider({ children }) {
|
||||||
const pipeline = useCommandPipeline();
|
const pipeline = useCommandPipeline();
|
||||||
const [state, dispatch] = useReducer(controlReducer, initialControlState);
|
const [state, dispatch] = useReducer(controlReducer, initialControlState);
|
||||||
const prevModeRef = useRef(initialControlState.mode);
|
const prevModeRef = useRef(null);
|
||||||
|
const pendingLightsRef = useRef(false);
|
||||||
const servoAngleRef = useRef(initialControlState.camera.angle);
|
const servoAngleRef = useRef(initialControlState.camera.angle);
|
||||||
const {
|
const {
|
||||||
value: controlSettings,
|
value: controlSettings,
|
||||||
@@ -38,10 +39,16 @@ export function ControlSystemProvider({ children }) {
|
|||||||
const targets = entities.filter(
|
const targets = entities.filter(
|
||||||
(ent) => ent.type === 'light' && ent.available !== false && ent.state !== 'on',
|
(ent) => ent.type === 'light' && ent.available !== false && ent.state !== 'on',
|
||||||
);
|
);
|
||||||
if (targets.length === 0) return;
|
if (targets.length === 0) {
|
||||||
|
pendingLightsRef.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pendingLightsRef.current = true;
|
||||||
targets.forEach((ent) => {
|
targets.forEach((ent) => {
|
||||||
homeAssistantSetState(ent.id, 'on').catch(() => {});
|
homeAssistantSetState(ent.id, 'on').catch(() => {});
|
||||||
});
|
});
|
||||||
|
// Give the loop a chance; clear pending after issuing commands.
|
||||||
|
pendingLightsRef.current = false;
|
||||||
}, [session?.homeAssistant?.entities, homeAssistantSetState]);
|
}, [session?.homeAssistant?.entities, homeAssistantSetState]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -53,9 +60,17 @@ export function ControlSystemProvider({ children }) {
|
|||||||
prevModeRef.current = state.mode;
|
prevModeRef.current = state.mode;
|
||||||
if (prevMode !== 'drive' && state.mode === 'drive' && session?.homeAssistant?.entities) {
|
if (prevMode !== 'drive' && state.mode === 'drive' && session?.homeAssistant?.entities) {
|
||||||
turnOnAllLights();
|
turnOnAllLights();
|
||||||
|
} else if (prevMode !== 'drive' && state.mode === 'drive') {
|
||||||
|
pendingLightsRef.current = true;
|
||||||
}
|
}
|
||||||
}, [state.mode, session?.homeAssistant?.entities, turnOnAllLights]);
|
}, [state.mode, session?.homeAssistant?.entities, turnOnAllLights]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (pendingLightsRef.current && session?.homeAssistant?.entities) {
|
||||||
|
turnOnAllLights();
|
||||||
|
}
|
||||||
|
}, [session?.homeAssistant?.entities, turnOnAllLights]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const mergedKeymap = { ...DEFAULT_KEYMAP, ...(controlSettings?.keymap || {}) };
|
const mergedKeymap = { ...DEFAULT_KEYMAP, ...(controlSettings?.keymap || {}) };
|
||||||
dispatch({ type: 'control/set-keymap', payload: mergedKeymap });
|
dispatch({ type: 'control/set-keymap', payload: mergedKeymap });
|
||||||
@@ -196,10 +211,13 @@ export function ControlSystemProvider({ children }) {
|
|||||||
if (!macro) return;
|
if (!macro) return;
|
||||||
if (macroId === 'drive-sequence') {
|
if (macroId === 'drive-sequence') {
|
||||||
turnOnAllLights();
|
turnOnAllLights();
|
||||||
|
if (!session?.homeAssistant?.entities) {
|
||||||
|
pendingLightsRef.current = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await pipeline.runMacroSteps(macro);
|
await pipeline.runMacroSteps(macro);
|
||||||
},
|
},
|
||||||
[pipeline, state.macros, turnOnAllLights],
|
[pipeline, state.macros, session?.homeAssistant?.entities, turnOnAllLights],
|
||||||
);
|
);
|
||||||
|
|
||||||
const stopAllMotion = useCallback(() => {
|
const stopAllMotion = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user