IR controls

This commit is contained in:
legop3
2026-07-11 03:59:34 -04:00
parent 10121650de
commit f2d3567978
6 changed files with 51 additions and 13 deletions
+22 -2
View File
@@ -77,6 +77,25 @@ function isSpotlightOn(light = {}) {
return Boolean(Number(raw));
}
function normalizeIrMode(mode) {
const normalized = String(mode || '').trim().toLowerCase();
if (normalized === 'on') return 'On';
if (normalized === 'off') return 'Off';
return 'Auto';
}
function nextIrMode(currentMode) {
/*
The rover laser button becomes the PTZ camera's IR mode control while the
PTZ camera is active. Cycle all three modes exposed by this Reolink camera
instead of reducing the control to a two-state toggle.
*/
const current = normalizeIrMode(currentMode);
if (current === 'Auto') return 'On';
if (current === 'On') return 'Off';
return 'Auto';
}
export function usePtzControlAdapter() {
const socket = useSocket();
const ptz = useSessionSelector((state) => state.session?.ptzCamera || null);
@@ -176,8 +195,9 @@ export function usePtzControlAdapter() {
const setIr = useCallback(
(nextOn) => {
if (!isActive) return false;
const currentOff = String(ptz?.ir?.state || '').toLowerCase() === 'off';
const desiredState = typeof nextOn === 'boolean' ? (nextOn ? 'Auto' : 'Off') : currentOff ? 'Auto' : 'Off';
const desiredState = typeof nextOn === 'boolean'
? (nextOn ? 'On' : 'Off')
: nextIrMode(ptz?.ir?.state);
emitPtz('ptzCamera:ir', { state: desiredState });
return true;
},