import Heading from "@/components/ui/heading"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import DebugCameraImage from "@/components/camera/DebugCameraImage"; import { FrigateConfig } from "@/types/frigateConfig"; import useSWR from "swr"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import { useCallback, useMemo, useState } from "react"; import { Slider } from "@/components/ui/slider"; import { Label } from "@/components/ui/label"; import { useMotionContourArea, useMotionThreshold } from "@/api/ws"; export default function MotionTuner() { const { data: config } = useSWR("config"); const cameras = useMemo(() => { if (!config) { return []; } return Object.values(config.cameras) .filter((conf) => conf.ui.dashboard && conf.enabled) .sort((aConf, bConf) => aConf.ui.order - bConf.ui.order); }, [config]); const [selectedCamera, setSelectedCamera] = useState(cameras[0].name); const cameraConfig = useMemo(() => { if (config && selectedCamera) { return config.cameras[selectedCamera]; } }, [config, selectedCamera]); const motionThreshold = useMemo(() => { return cameraConfig?.motion.threshold ?? 0; }, [cameraConfig?.motion.threshold]); const motionContourArea = useMemo( () => cameraConfig?.motion.contour_area ?? 0, [cameraConfig?.motion.contour_area], ); const { send: sendMotionThreshold } = useMotionThreshold(selectedCamera); const { send: sendMotionContourArea } = useMotionContourArea(selectedCamera); const setMotionThreshold = useCallback( (threshold: number) => { if (cameraConfig && threshold != motionThreshold) { cameraConfig.motion.threshold = threshold; sendMotionThreshold(threshold); console.log("setting motion threshold", threshold); } }, [cameraConfig, motionThreshold, sendMotionThreshold], ); const setMotionContourArea = useCallback( (contour_area: number) => { if (cameraConfig && contour_area != motionContourArea) { cameraConfig.motion.contour_area = contour_area; sendMotionContourArea(contour_area); console.log("setting motion contour area", contour_area); } }, [cameraConfig, motionContourArea, sendMotionContourArea], ); if (!cameraConfig && !selectedCamera) { return ; } // console.log("selected camera", selectedCamera); // console.log("threshold", motionThreshold); // console.log("contour area", motionContourArea); // console.log(cameraConfig); return ( <> Motion Detection Tuner
setMotionThreshold(value[0])} />
setMotionContourArea(value[0])} />
); }