keyboard camerea tilt slider

This commit is contained in:
legop3
2025-12-22 18:55:19 -05:00
parent b4a5633bd4
commit 020ddfea07
7 changed files with 146 additions and 50 deletions
+1 -24
View File
@@ -168,7 +168,6 @@ function InlineCameraTilt({ keymap }) {
: (min + max) / 2;
const [pendingAngle, setPendingAngle] = useState(value);
const throttleRef = useRef(null);
const draggingRef = useRef(false);
useEffect(() => {
@@ -177,38 +176,16 @@ function InlineCameraTilt({ keymap }) {
}
}, [value]);
useEffect(
() => () => {
if (throttleRef.current) {
clearTimeout(throttleRef.current);
}
},
[],
);
const scheduleSend = (next) => {
if (throttleRef.current) {
clearTimeout(throttleRef.current);
}
throttleRef.current = setTimeout(() => {
setServoAngle(next);
}, 150);
};
const handleSlider = (event) => {
const next = Number.parseFloat(event.target.value);
if (Number.isNaN(next)) return;
draggingRef.current = true;
setPendingAngle(next);
scheduleSend(next);
setServoAngle(next);
};
const commitSlider = () => {
draggingRef.current = false;
if (throttleRef.current) {
clearTimeout(throttleRef.current);
}
setServoAngle(pendingAngle);
};
if (!enabled) return null;