Compare commits
18 Commits
bugfix/das
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a6235a6844 | |||
| 9520aa5dac | |||
| 00ca9441b9 | |||
| 1243ce2098 | |||
| 845d603ae3 | |||
| 1653d9f0d4 | |||
| eb5eb69c28 | |||
| 61c85fdc3f | |||
| 7877173f56 | |||
| eb3f441a24 | |||
| bf77d6001a | |||
| 0bdc8b25a8 | |||
| dfc14575a8 | |||
| b328d25bc7 | |||
| b79da7048e | |||
| dab49fd99c | |||
| 775fce7900 | |||
| cc8b3a5691 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "bayiq-ui",
|
||||
"private": true,
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
12
src/app/config/cameraConfig.ts
Normal file
12
src/app/config/cameraConfig.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// Camera configuration - add more cameras here as needed
|
||||
export const CAMERA_IDS = ["A", "B", "C"] as const;
|
||||
|
||||
export type CameraID = (typeof CAMERA_IDS)[number];
|
||||
|
||||
export const DEFAULT_REGIONS = [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
];
|
||||
@@ -17,9 +17,7 @@ type CameraSocketState = {
|
||||
|
||||
export type WebSocketConextValue = {
|
||||
info: InfoSocketState;
|
||||
cameraFeedA: CameraSocketState;
|
||||
cameraFeedB: CameraSocketState;
|
||||
cameraFeedC: CameraSocketState;
|
||||
cameraFeed: CameraSocketState;
|
||||
};
|
||||
|
||||
export const WebsocketContext = createContext<WebSocketConextValue | null>(null);
|
||||
@@ -31,6 +29,4 @@ const useWebSocketContext = () => {
|
||||
};
|
||||
|
||||
export const useInfoSocket = () => useWebSocketContext().info;
|
||||
export const useCameraFeedASocket = () => useWebSocketContext().cameraFeedA;
|
||||
export const useCameraFeedBSocket = () => useWebSocketContext().cameraFeedB;
|
||||
export const useCameraFeedCSocket = () => useWebSocketContext().cameraFeedC;
|
||||
export const useCameraFeedSocket = () => useWebSocketContext().cameraFeed;
|
||||
|
||||
@@ -3,13 +3,12 @@ import { CameraFeedContext } from "../context/CameraFeedContext";
|
||||
import { initialState, reducer } from "../reducers/cameraFeedReducer";
|
||||
import { useBlackBoard } from "../../hooks/useBlackBoard";
|
||||
import type { CameraFeedState } from "../../types/types";
|
||||
import { useCameraZoom } from "../../features/cameras/hooks/useCameraZoom";
|
||||
|
||||
import { CAMERA_IDS } from "../config/cameraConfig";
|
||||
import CameraZoomFetcher from "./CameraZoomFetcher";
|
||||
|
||||
export const CameraFeedProvider = ({ children }: { children: ReactNode }) => {
|
||||
const { blackboardMutation } = useBlackBoard();
|
||||
const { cameraZoomQuery: cameraZoomQueryA } = useCameraZoom("A");
|
||||
const { cameraZoomQuery: cameraZoomQueryB } = useCameraZoom("B");
|
||||
const { cameraZoomQuery: cameraZoomQueryC } = useCameraZoom("C");
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
@@ -23,52 +22,25 @@ export const CameraFeedProvider = ({ children }: { children: ReactNode }) => {
|
||||
const cameraFeedData: CameraFeedState = result.result;
|
||||
const recontructedState = {
|
||||
...cameraFeedData,
|
||||
paintedCells: {
|
||||
A: new Map(cameraFeedData.paintedCells.A),
|
||||
B: new Map(cameraFeedData.paintedCells.B),
|
||||
C: new Map(cameraFeedData.paintedCells.C),
|
||||
},
|
||||
paintedCells: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = new Map(cameraFeedData.paintedCells[id]);
|
||||
return acc;
|
||||
},
|
||||
{} as typeof cameraFeedData.paintedCells,
|
||||
),
|
||||
};
|
||||
dispatch({ type: "SET_CAMERA_FEED_DATA", cameraState: recontructedState });
|
||||
};
|
||||
fetchBlackBoardData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchZoomLevels = async () => {
|
||||
const [resultA, resultB, resultC] = await Promise.all([
|
||||
cameraZoomQueryA.refetch(),
|
||||
cameraZoomQueryB.refetch(),
|
||||
cameraZoomQueryC.refetch(),
|
||||
]);
|
||||
|
||||
const zoomLevelAnumber = parseFloat(resultA.data?.propPhysCurrent?.value);
|
||||
const zoomLevelBnumber = parseFloat(resultB.data?.propPhysCurrent?.value);
|
||||
const zoomLevelCnumber = parseFloat(resultC.data?.propPhysCurrent?.value);
|
||||
|
||||
if (resultA.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "A", zoomLevel: zoomLevelAnumber },
|
||||
});
|
||||
}
|
||||
|
||||
if (resultB.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "B", zoomLevel: zoomLevelBnumber },
|
||||
});
|
||||
}
|
||||
|
||||
if (resultC.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "C", zoomLevel: zoomLevelCnumber },
|
||||
});
|
||||
}
|
||||
};
|
||||
fetchZoomLevels();
|
||||
}, []);
|
||||
|
||||
return <CameraFeedContext.Provider value={{ state, dispatch }}>{children}</CameraFeedContext.Provider>;
|
||||
return (
|
||||
<CameraFeedContext.Provider value={{ state, dispatch }}>
|
||||
{CAMERA_IDS.map((cameraId) => (
|
||||
<CameraZoomFetcher key={cameraId} cameraId={cameraId} dispatch={dispatch} />
|
||||
))}
|
||||
{children}
|
||||
</CameraFeedContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
38
src/app/providers/CameraZoomFetcher.tsx
Normal file
38
src/app/providers/CameraZoomFetcher.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useEffect } from "react";
|
||||
import { useCameraZoom } from "../../features/cameras/hooks/useCameraZoom";
|
||||
import type { CameraFeedAction } from "../../types/types";
|
||||
import type { CameraID } from "../config/cameraConfig";
|
||||
|
||||
type CameraZoomFetcherProps = {
|
||||
cameraId: CameraID;
|
||||
dispatch: (action: CameraFeedAction) => void;
|
||||
};
|
||||
|
||||
const CameraZoomFetcher = ({ cameraId, dispatch }: CameraZoomFetcherProps) => {
|
||||
const { cameraZoomQuery } = useCameraZoom(cameraId);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchZoomLevel = async () => {
|
||||
const result = await cameraZoomQuery.refetch();
|
||||
|
||||
if (result?.data) {
|
||||
const currentZoomLevel = result?.data["propPhysCurrent"].value;
|
||||
const minLevel = result?.data["propPhysMin"].value;
|
||||
const maxLevel = result?.data["propPhysMax"].value;
|
||||
|
||||
const normalizedZoomLevel = ((currentZoomLevel - minLevel) / (maxLevel - minLevel)).toFixed(2);
|
||||
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: cameraId, zoomLevel: parseFloat(normalizedZoomLevel) },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
fetchZoomLevel();
|
||||
}, [cameraId]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default CameraZoomFetcher;
|
||||
@@ -3,18 +3,28 @@ import { WebsocketContext, type WebSocketConextValue } from "../context/WebSocke
|
||||
import useWebSocket from "react-use-websocket";
|
||||
import { wsConfig } from "../config/wsconfig";
|
||||
import type { CameraZoomData, InfoBarData } from "../../types/types";
|
||||
import { CAMERA_IDS } from "../config/cameraConfig";
|
||||
import { CAMBASE_WS } from "../../utils/config";
|
||||
import { useCameraFeedContext } from "../context/CameraFeedContext";
|
||||
|
||||
type WebSocketProviderProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
const { state } = useCameraFeedContext();
|
||||
const [systemData, setSystemData] = useState<InfoBarData | null>(null);
|
||||
const [socketData, setSocketData] = useState<CameraZoomData | null>(null);
|
||||
const infoSocket = useWebSocket(wsConfig.infoBar, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedASocket = useWebSocket(wsConfig.cameraFeedA, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedBSocket = useWebSocket(wsConfig.cameraFeedB, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedCSocket = useWebSocket(wsConfig.cameraFeedC, { share: true, shouldReconnect: () => true });
|
||||
const sockets = CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = `${CAMBASE_WS}/websocket-Camera${id}-live-video`;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
const cameraFeedID = state.cameraFeedID;
|
||||
const cameraFeed = useWebSocket(sockets[cameraFeedID], { share: true, shouldReconnect: () => true });
|
||||
|
||||
useEffect(() => {
|
||||
async function parseData() {
|
||||
@@ -23,20 +33,15 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
const data = JSON.parse(text);
|
||||
setSystemData(data);
|
||||
}
|
||||
if (cameraFeedASocket.lastMessage || cameraFeedBSocket.lastMessage || cameraFeedCSocket.lastMessage) {
|
||||
const message = cameraFeedASocket.lastMessage || cameraFeedBSocket.lastMessage || cameraFeedCSocket.lastMessage;
|
||||
if (cameraFeed.lastMessage) {
|
||||
const message = cameraFeed.lastMessage;
|
||||
const data = await message?.data.text();
|
||||
const parsedData: CameraZoomData = JSON.parse(data || "");
|
||||
setSocketData(parsedData);
|
||||
}
|
||||
}
|
||||
parseData();
|
||||
}, [
|
||||
cameraFeedASocket.lastMessage,
|
||||
cameraFeedBSocket.lastMessage,
|
||||
cameraFeedCSocket.lastMessage,
|
||||
infoSocket.lastMessage,
|
||||
]);
|
||||
}, [cameraFeed.lastMessage, infoSocket.lastMessage]);
|
||||
|
||||
const value = useMemo<WebSocketConextValue>(
|
||||
() => ({
|
||||
@@ -45,32 +50,16 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
readyState: infoSocket.readyState,
|
||||
sendJson: infoSocket.sendJsonMessage,
|
||||
},
|
||||
cameraFeedA: {
|
||||
cameraFeed: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedASocket.readyState,
|
||||
readyState: cameraFeed.readyState,
|
||||
|
||||
send: cameraFeedASocket.sendMessage,
|
||||
},
|
||||
cameraFeedB: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedBSocket.readyState,
|
||||
|
||||
send: cameraFeedBSocket.sendMessage,
|
||||
},
|
||||
cameraFeedC: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedCSocket.readyState,
|
||||
|
||||
send: cameraFeedCSocket.sendMessage,
|
||||
send: cameraFeed.sendMessage,
|
||||
},
|
||||
}),
|
||||
[
|
||||
cameraFeedASocket.readyState,
|
||||
cameraFeedASocket.sendMessage,
|
||||
cameraFeedBSocket.readyState,
|
||||
cameraFeedBSocket.sendMessage,
|
||||
cameraFeedCSocket.readyState,
|
||||
cameraFeedCSocket.sendMessage,
|
||||
cameraFeed.readyState,
|
||||
cameraFeed.sendMessage,
|
||||
infoSocket.readyState,
|
||||
infoSocket.sendJsonMessage,
|
||||
socketData,
|
||||
|
||||
@@ -1,47 +1,39 @@
|
||||
import type { CameraFeedAction, CameraFeedState, PaintedCell } from "../../types/types";
|
||||
import { CAMERA_IDS, DEFAULT_REGIONS, type CameraID } from "../config/cameraConfig";
|
||||
|
||||
export const initialState: CameraFeedState = {
|
||||
cameraFeedID: "A",
|
||||
paintedCells: {
|
||||
A: new Map<string, PaintedCell>(),
|
||||
B: new Map<string, PaintedCell>(),
|
||||
C: new Map<string, PaintedCell>(),
|
||||
},
|
||||
regionsByCamera: {
|
||||
A: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
B: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
C: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
},
|
||||
cameraFeedID: CAMERA_IDS[0],
|
||||
brushSize: 1,
|
||||
paintedCells: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = new Map<string, PaintedCell>();
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Map<string, PaintedCell>>,
|
||||
),
|
||||
regionsByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = DEFAULT_REGIONS;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, { name: string; brushColour: string }[]>,
|
||||
),
|
||||
|
||||
selectedRegionIndex: 0,
|
||||
modeByCamera: {
|
||||
A: "painter",
|
||||
B: "painter",
|
||||
C: "painter",
|
||||
},
|
||||
zoomLevel: {
|
||||
A: 1,
|
||||
B: 1,
|
||||
C: 1,
|
||||
},
|
||||
modeByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = "painter";
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, string>,
|
||||
),
|
||||
zoomLevel: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = 0;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, number>,
|
||||
),
|
||||
};
|
||||
|
||||
export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
@@ -119,6 +111,12 @@ export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
[action.payload.cameraFeedID]: action.payload.zoomLevel,
|
||||
},
|
||||
};
|
||||
|
||||
case "SET_BRUSH_SIZE":
|
||||
return {
|
||||
...state,
|
||||
brushSize: action.payload.brushSize,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Tabs, Tab, TabList, TabPanel } from "react-tabs";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||
import RegionSelector from "./RegionSelector";
|
||||
import CameraControls from "./cameraControls/CameraControls";
|
||||
@@ -13,6 +13,7 @@ type CameraPanelProps = {
|
||||
|
||||
const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetModalOpen }: CameraPanelProps) => {
|
||||
const { state, dispatch } = useCameraFeedContext();
|
||||
const [subTabIndex, setSubTabIndex] = useState(0);
|
||||
const cameraFeedID = state.cameraFeedID;
|
||||
const regions = state.regionsByCamera[cameraFeedID];
|
||||
|
||||
@@ -28,6 +29,7 @@ const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetMod
|
||||
return "B";
|
||||
case 2:
|
||||
return "C";
|
||||
//Add more cases if more cameras are added
|
||||
default:
|
||||
return "A";
|
||||
}
|
||||
@@ -38,7 +40,7 @@ const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetMod
|
||||
}, [dispatch, tabIndex]);
|
||||
|
||||
return (
|
||||
<Tabs>
|
||||
<Tabs onSelect={(index) => setSubTabIndex(index)}>
|
||||
<TabList>
|
||||
<Tab>Target Detection</Tab>
|
||||
<Tab>Camera Controls</Tab>
|
||||
@@ -52,10 +54,11 @@ const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetMod
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
subTabIndex={subTabIndex}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<CameraControls cameraFeedID={cameraFeedID} />
|
||||
<CameraControls cameraFeedID={cameraFeedID} subTabIndex={subTabIndex} />
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import Card from "../../../../ui/Card";
|
||||
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
|
||||
import "react-tabs/style/react-tabs.css";
|
||||
import CameraPanel from "./CameraPanel";
|
||||
import { CAMERA_IDS } from "../../../../app/config/cameraConfig";
|
||||
|
||||
type CameraSettingsProps = {
|
||||
setTabIndex: (tabIndex: number) => void;
|
||||
@@ -12,7 +13,6 @@ type CameraSettingsProps = {
|
||||
};
|
||||
|
||||
const CameraSettings = ({
|
||||
tabIndex,
|
||||
setTabIndex,
|
||||
isResetAllModalOpen,
|
||||
handleClose,
|
||||
@@ -26,34 +26,20 @@ const CameraSettings = ({
|
||||
onSelect={(index) => setTabIndex(index)}
|
||||
>
|
||||
<TabList>
|
||||
<Tab>Camera A</Tab>
|
||||
<Tab>Camera B</Tab>
|
||||
<Tab>Camera C</Tab>
|
||||
{CAMERA_IDS.map((id) => (
|
||||
<Tab key={id}>Camera {id}</Tab>
|
||||
))}
|
||||
</TabList>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
{CAMERA_IDS.map((id, index) => (
|
||||
<TabPanel key={id}>
|
||||
<CameraPanel
|
||||
tabIndex={index}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
))}
|
||||
</Tabs>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -4,20 +4,20 @@ import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext"
|
||||
import { useColourDectection } from "../../hooks/useColourDetection";
|
||||
import { useBlackBoard } from "../../../../hooks/useBlackBoard";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
useCameraFeedASocket,
|
||||
useCameraFeedBSocket,
|
||||
useCameraFeedCSocket,
|
||||
} from "../../../../app/context/WebSocketContext";
|
||||
import { useCameraFeedSocket } from "../../../../app/context/WebSocketContext";
|
||||
import type { CameraID } from "../../../../app/config/cameraConfig";
|
||||
import { useEffect } from "react";
|
||||
import SliderComponent from "../../../../ui/SliderComponent";
|
||||
|
||||
type RegionSelectorProps = {
|
||||
regions: Region[];
|
||||
selectedRegionIndex: number;
|
||||
mode: string;
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
isResetAllModalOpen: boolean;
|
||||
handleClose: () => void;
|
||||
setIsResetModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
subTabIndex?: number;
|
||||
};
|
||||
|
||||
const RegionSelector = ({
|
||||
@@ -26,34 +26,37 @@ const RegionSelector = ({
|
||||
mode,
|
||||
cameraFeedID,
|
||||
isResetAllModalOpen,
|
||||
|
||||
subTabIndex,
|
||||
setIsResetModalOpen,
|
||||
}: RegionSelectorProps) => {
|
||||
const { colourMutation } = useColourDectection();
|
||||
const { state, dispatch } = useCameraFeedContext();
|
||||
const { blackboardMutation } = useBlackBoard();
|
||||
const paintedCells = state.paintedCells[cameraFeedID];
|
||||
const cameraASocket = useCameraFeedASocket();
|
||||
const cameraBSocket = useCameraFeedBSocket();
|
||||
const cameraCSocket = useCameraFeedCSocket();
|
||||
const brushSize = state.brushSize;
|
||||
const cameraSocket = useCameraFeedSocket();
|
||||
useEffect(() => {
|
||||
if (subTabIndex === 0) {
|
||||
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID, mode: "painter" } });
|
||||
}
|
||||
}, [cameraFeedID, dispatch, subTabIndex]);
|
||||
|
||||
const getCurrentSocket = () => {
|
||||
switch (cameraFeedID) {
|
||||
case "A":
|
||||
return cameraASocket;
|
||||
return cameraSocket;
|
||||
case "B":
|
||||
return cameraBSocket;
|
||||
return cameraSocket;
|
||||
case "C":
|
||||
return cameraCSocket;
|
||||
return cameraSocket;
|
||||
}
|
||||
};
|
||||
|
||||
const socket = getCurrentSocket();
|
||||
|
||||
const getMagnificationLevel = () => {
|
||||
const test = socket.data;
|
||||
if (!socket.data) return null;
|
||||
console.log(test);
|
||||
const test = socket?.data;
|
||||
if (!socket?.data) return null;
|
||||
if (!test || !test.magnificationLevel) return "1x";
|
||||
return test?.magnificationLevel;
|
||||
};
|
||||
@@ -170,7 +173,7 @@ const RegionSelector = ({
|
||||
<div className="flex flex-col md:flex-row gap-3">
|
||||
<div className="p-2 border border-gray-600 rounded-lg flex flex-col h-[10%] w-full">
|
||||
<h2 className="text-2xl mb-2">Tools</h2>
|
||||
<div className="flex flex-col">
|
||||
<div className="flex flex-col gap-2">
|
||||
<label
|
||||
htmlFor="paintMode"
|
||||
className={`p-4 border rounded-lg mb-2
|
||||
@@ -203,6 +206,19 @@ const RegionSelector = ({
|
||||
/>
|
||||
<span className="text-xl">Erase mode</span>
|
||||
</label>
|
||||
<div className="flex flex-col border border-gray-600 rounded-lg p-4">
|
||||
<span className="text-lg mb-2">
|
||||
{mode === "painter" ? "Brush" : "Eraser"} Size: {brushSize}
|
||||
</span>
|
||||
<SliderComponent
|
||||
id="brushSize"
|
||||
onChange={(value) => dispatch({ type: "SET_BRUSH_SIZE", payload: { brushSize: value as number } })}
|
||||
value={brushSize}
|
||||
min={1}
|
||||
max={5}
|
||||
step={1}
|
||||
/>
|
||||
</div>
|
||||
<label
|
||||
htmlFor="magnifyMode"
|
||||
className={`p-4 border rounded-lg mb-2
|
||||
|
||||
@@ -1,17 +1,31 @@
|
||||
import { useEffect } from "react";
|
||||
import type { CameraID } from "../../../../../app/config/cameraConfig";
|
||||
import { useCameraFeedContext } from "../../../../../app/context/CameraFeedContext";
|
||||
import SliderComponent from "../../../../../ui/SliderComponent";
|
||||
import { useCameraZoom } from "../../../hooks/useCameraZoom";
|
||||
import { useDebouncedCallback } from "use-debounce";
|
||||
|
||||
type CameraControlsProps = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
subTabIndex?: number;
|
||||
};
|
||||
|
||||
const CameraControls = ({ cameraFeedID }: CameraControlsProps) => {
|
||||
const CameraControls = ({ cameraFeedID, subTabIndex }: CameraControlsProps) => {
|
||||
const { state, dispatch } = useCameraFeedContext();
|
||||
const { cameraZoomMutation } = useCameraZoom(cameraFeedID);
|
||||
const { cameraZoomMutation, cameraZoomQuery } = useCameraZoom(cameraFeedID);
|
||||
|
||||
const zoomLevel = state.zoomLevel ? state.zoomLevel[cameraFeedID] : 0;
|
||||
const currentZoomLevel = cameraZoomQuery.data ? cameraZoomQuery.data["propPhysCurrent"].value : 0;
|
||||
const minLevel = cameraZoomQuery.data ? cameraZoomQuery.data["propPhysMin"].value : 0;
|
||||
const maxLevel = cameraZoomQuery.data ? cameraZoomQuery.data["propPhysMax"].value : 0;
|
||||
|
||||
const normalizedZoomLevel = ((currentZoomLevel - minLevel) / (maxLevel - minLevel)).toFixed(2);
|
||||
useEffect(() => {
|
||||
if (subTabIndex === 1) {
|
||||
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID, mode: "controller" } });
|
||||
}
|
||||
}, [cameraFeedID, dispatch, subTabIndex]);
|
||||
|
||||
const zoomLevel = state.zoomLevel ? state.zoomLevel[cameraFeedID] : 1;
|
||||
const debouncedMutation = useDebouncedCallback(async (value) => {
|
||||
await cameraZoomMutation.mutateAsync({
|
||||
cameraFeedID,
|
||||
@@ -23,17 +37,34 @@ const CameraControls = ({ cameraFeedID }: CameraControlsProps) => {
|
||||
const newZoom = value as number;
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: cameraFeedID, zoomLevel: value as number },
|
||||
payload: { cameraFeedID: cameraFeedID, zoomLevel: newZoom },
|
||||
});
|
||||
debouncedMutation(newZoom);
|
||||
};
|
||||
|
||||
const handleOneShotClick = () => {
|
||||
debouncedMutation(normalizedZoomLevel);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full mt-[5%]">
|
||||
<h2 className="text-2xl mb-4">Camera {cameraFeedID}</h2>
|
||||
<div className="w-[70%] ">
|
||||
<label htmlFor="zoom">Zoom {zoomLevel} </label>
|
||||
<SliderComponent id="zoom" onChange={handleChange} value={zoomLevel} min={1} max={3} step={0.1} />
|
||||
<div>
|
||||
<div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full mt-[5%]">
|
||||
<h2 className="text-2xl mb-4">Camera {cameraFeedID}</h2>
|
||||
<div className="w-[70%] ">
|
||||
<label htmlFor="zoom">Zoom {zoomLevel}</label>
|
||||
<SliderComponent id="zoom" onChange={handleChange} value={zoomLevel} min={0} max={1} step={0.1} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full mt-[5%]">
|
||||
<h2>One Shot</h2>
|
||||
<button
|
||||
type="button"
|
||||
className="p-2 bg-gray-500 rounded-xl w-[40%] mt-2 hover:bg-gray-700 cursor-pointer"
|
||||
onClick={handleOneShotClick}
|
||||
>
|
||||
One Shot
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -3,13 +3,10 @@ import { Stage, Layer, Image, Shape } from "react-konva";
|
||||
import type { KonvaEventObject } from "konva/lib/Node";
|
||||
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
|
||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||
import {
|
||||
useCameraFeedASocket,
|
||||
useCameraFeedBSocket,
|
||||
useCameraFeedCSocket,
|
||||
} from "../../../../app/context/WebSocketContext";
|
||||
import { useCameraFeedSocket } from "../../../../app/context/WebSocketContext";
|
||||
import { ReadyState } from "react-use-websocket";
|
||||
import { toast } from "sonner";
|
||||
import type { CameraID } from "../../../../app/config/cameraConfig";
|
||||
|
||||
const BACKEND_WIDTH = 640;
|
||||
const BACKEND_HEIGHT = 360;
|
||||
@@ -26,6 +23,8 @@ const VideoFeedGridPainter = () => {
|
||||
const regions = state.regionsByCamera[cameraFeedID];
|
||||
const selectedRegionIndex = state.selectedRegionIndex;
|
||||
const mode = state.modeByCamera[cameraFeedID];
|
||||
const brushSize = state.brushSize;
|
||||
|
||||
const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
|
||||
const [stageSize, setStageSize] = useState({ width: BACKEND_WIDTH, height: BACKEND_HEIGHT });
|
||||
const isDrawingRef = useRef(false);
|
||||
@@ -41,22 +40,20 @@ const VideoFeedGridPainter = () => {
|
||||
const currentScale = stageSize.width / BACKEND_WIDTH;
|
||||
const size = BACKEND_CELL_SIZE * currentScale;
|
||||
|
||||
const cameraASocket = useCameraFeedASocket();
|
||||
const cameraBSocket = useCameraFeedBSocket();
|
||||
const cameraCSocket = useCameraFeedCSocket();
|
||||
const cameraSocket = useCameraFeedSocket();
|
||||
|
||||
const getCurrentSocket = () => {
|
||||
switch (cameraFeedID) {
|
||||
case "A":
|
||||
return cameraASocket;
|
||||
return cameraSocket;
|
||||
case "B":
|
||||
return cameraBSocket;
|
||||
return cameraSocket;
|
||||
case "C":
|
||||
return cameraCSocket;
|
||||
return cameraSocket;
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomClick = (e: KonvaEventObject<MouseEvent>, cameraFeedID: "A" | "B" | "C") => {
|
||||
const handleZoomClick = (e: KonvaEventObject<MouseEvent>, cameraFeedID: CameraID) => {
|
||||
if (mode !== "zoom") return;
|
||||
const socket = getCurrentSocket();
|
||||
const stage = e.target.getStage();
|
||||
@@ -90,34 +87,37 @@ const VideoFeedGridPainter = () => {
|
||||
|
||||
const image = draw(latestBitmapRef);
|
||||
|
||||
const paintCell = (x: number, y: number) => {
|
||||
const paintCell = (x: number, y: number, brushSize: number) => {
|
||||
if (mode === "controller" || mode === "zoom" || mode === "magnify") return;
|
||||
const col = Math.floor(x / (size + gap));
|
||||
const row = Math.floor(y / (size + gap));
|
||||
const radius = Math.floor(brushSize / 2);
|
||||
|
||||
if (row < 0 || row >= rows || col < 0 || col >= cols) return;
|
||||
|
||||
const activeRegion = regions[selectedRegionIndex];
|
||||
if (!activeRegion) return;
|
||||
|
||||
const key = `${row}-${col}`;
|
||||
const currentColour = regions[selectedRegionIndex].brushColour;
|
||||
|
||||
const map = paintedCells;
|
||||
const existing = map.get(key);
|
||||
|
||||
if (mode === "eraser") {
|
||||
if (map.has(key)) {
|
||||
map.delete(key);
|
||||
paintLayerRef.current?.batchDraw();
|
||||
for (let r = row - radius; r <= row + radius; r++) {
|
||||
for (let c = col - radius; c <= col + radius; c++) {
|
||||
if (r < 0 || r >= rows || c < 0 || c >= cols) continue;
|
||||
const key = `${r}-${c}`;
|
||||
const map = paintedCells;
|
||||
const existing = map.get(key);
|
||||
if (mode === "eraser") {
|
||||
if (map.has(key)) {
|
||||
map.delete(key);
|
||||
paintLayerRef.current?.batchDraw();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (existing && existing.colour === currentColour) continue;
|
||||
map.set(key, { colour: currentColour, region: activeRegion });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (existing && existing.colour === currentColour) return;
|
||||
|
||||
map.set(key, { colour: currentColour, region: activeRegion });
|
||||
|
||||
paintLayerRef.current?.batchDraw();
|
||||
};
|
||||
|
||||
@@ -125,14 +125,14 @@ const VideoFeedGridPainter = () => {
|
||||
if (!regions[selectedRegionIndex] || mode === "magnify" || mode === "zoom") return;
|
||||
isDrawingRef.current = true;
|
||||
const pos = e.target.getStage()?.getPointerPosition();
|
||||
if (pos) paintCell(pos.x, pos.y);
|
||||
if (pos) paintCell(pos.x, pos.y, brushSize);
|
||||
};
|
||||
|
||||
const handleStageMouseMove = (e: KonvaEventObject<MouseEvent>) => {
|
||||
if (!isDrawingRef.current || mode === "magnify") return;
|
||||
if (!regions[selectedRegionIndex]) return;
|
||||
const pos = e.target.getStage()?.getPointerPosition();
|
||||
if (pos) paintCell(pos.x, pos.y);
|
||||
if (pos) paintCell(pos.x, pos.y, brushSize);
|
||||
};
|
||||
|
||||
const handleStageMouseUp = () => {
|
||||
@@ -223,6 +223,7 @@ const VideoFeedGridPainter = () => {
|
||||
height={stageSize.height}
|
||||
classname={"rounded-lg"}
|
||||
onClick={(e) => handleZoomClick(e, cameraFeedID)}
|
||||
cornerRadius={10}
|
||||
/>
|
||||
</Layer>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAMBASE } from "../../../utils/config";
|
||||
import type { CameraZoomConfig } from "../../../types/types";
|
||||
import type { CameraID } from "../../../app/config/cameraConfig";
|
||||
|
||||
const fetchZoomLevel = async (cameraFeedID: string) => {
|
||||
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Camera${cameraFeedID}-onvif-controller`);
|
||||
@@ -22,11 +23,13 @@ const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
|
||||
id: `Camera${zoomConfig.cameraFeedID}-onvif-controller`,
|
||||
fields,
|
||||
};
|
||||
console.log(zoomPayload);
|
||||
const response = await fetch(`${CAMBASE}/api/update-config`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(zoomPayload),
|
||||
});
|
||||
const response = await fetch(
|
||||
`${CAMBASE}/Camera${zoomConfig.cameraFeedID}-camera-control?command=setAbsoluteZoom&zoomLevel=${zoomConfig.zoomLevel}`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(zoomPayload),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
@@ -34,7 +37,7 @@ const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useCameraZoom = (cameraFeedID: "A" | "B" | "C") => {
|
||||
export const useCameraZoom = (cameraFeedID: CameraID) => {
|
||||
const cameraZoomQuery = useQuery({
|
||||
queryKey: ["cameraZoom", cameraFeedID],
|
||||
queryFn: () => fetchZoomLevel(cameraFeedID),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { CAMBASE } from "../../../utils/config";
|
||||
import type { CameraID } from "../../../app/config/cameraConfig";
|
||||
|
||||
const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
const targetDectionFeed = async (cameraFeedID: CameraID | null) => {
|
||||
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
|
||||
signal: AbortSignal.timeout(300000),
|
||||
cache: "no-store",
|
||||
@@ -12,7 +13,7 @@ const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
return response.blob();
|
||||
};
|
||||
|
||||
const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
const getVideoFeed = async (cameraFeedID: CameraID | null) => {
|
||||
const response = await fetch(`${CAMBASE}/Camera${cameraFeedID}-preview`, {
|
||||
signal: AbortSignal.timeout(300000),
|
||||
cache: "no-store",
|
||||
@@ -23,7 +24,7 @@ const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
return response.blob();
|
||||
};
|
||||
|
||||
export const useGetVideoFeed = (cameraFeedID: "A" | "B" | "C" | null, mode: string) => {
|
||||
export const useGetVideoFeed = (cameraFeedID: CameraID | null, mode: string) => {
|
||||
const targetDetectionQuery = useQuery({
|
||||
queryKey: ["getfeed", cameraFeedID],
|
||||
queryFn: () => targetDectionFeed(cameraFeedID),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useGetSystemHealth } from "../hooks/useGetSystemHealth";
|
||||
import CameraStatus from "./cameraStatus/CameraStatus";
|
||||
import SystemHealthCard from "./systemHealth/SystemHealthCard";
|
||||
import SystemStatusCard from "./systemStatus/SystemStatusCard";
|
||||
import { CAMERA_IDS } from "../../../app/config/cameraConfig";
|
||||
|
||||
const DashboardGrid = () => {
|
||||
const { query } = useGetSystemHealth();
|
||||
@@ -26,30 +27,35 @@ const DashboardGrid = () => {
|
||||
channelA: [],
|
||||
channelB: [],
|
||||
channelC: [],
|
||||
// todo: check if more cameras will be added later
|
||||
default: [],
|
||||
},
|
||||
);
|
||||
|
||||
const categoryA = statusCategories?.channelA ?? [];
|
||||
const categoryB = statusCategories?.channelB ?? [];
|
||||
const categoryC = statusCategories?.channelC ?? [];
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2 gap-4">
|
||||
<SystemStatusCard />
|
||||
<SystemHealthCard
|
||||
startTime={startTime}
|
||||
uptime={uptime}
|
||||
statuses={statuses}
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
dateUpdatedAt={dateUpdatedAt}
|
||||
refetch={refetch}
|
||||
/>
|
||||
<div className="grid grid-cols-1 md:col-span-2 md:grid-cols-3 gap-x-4">
|
||||
<CameraStatus title="Camera A" category={categoryA} isError={isError} />
|
||||
<CameraStatus title="Camera B" category={categoryB} isError={isError} />
|
||||
<CameraStatus title="Camera C" category={categoryC} isError={isError} />
|
||||
<div className="grid grid-cols-1 md:grid-rows-0 md:grid-cols-2 gap-4 md:col-span-2">
|
||||
<SystemStatusCard />
|
||||
<SystemHealthCard
|
||||
startTime={startTime}
|
||||
uptime={uptime}
|
||||
statuses={statuses}
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
dateUpdatedAt={dateUpdatedAt}
|
||||
refetch={refetch}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:col-span-2 md:grid-cols-[repeat(3,1fr)] gap-x-4">
|
||||
{CAMERA_IDS.map((cameraID) => (
|
||||
<CameraStatus
|
||||
key={cameraID}
|
||||
title={`Camera ${cameraID}`}
|
||||
category={statusCategories?.[`channel${cameraID}`] ?? []}
|
||||
isError={isError}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import type { SystemHealthStatus } from "../../../../types/types";
|
||||
import { capitalize } from "../../../../utils/utils";
|
||||
|
||||
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
||||
import Badge from "../../../../ui/Badge";
|
||||
|
||||
type CameraStatusGridItemProps = {
|
||||
title: string;
|
||||
@@ -15,6 +16,10 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
||||
return status.tags.every((tag) => allowedTags.includes(tag));
|
||||
});
|
||||
|
||||
const downItems = statusCategory?.filter((status) => {
|
||||
return status.tags.some((tag) => tag !== "RUNNING" && tag !== "VIDEO-PLAYING");
|
||||
});
|
||||
|
||||
const handleClick = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
@@ -24,8 +29,21 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
||||
className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241] hover:cursor-pointer m-2 h-70"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<h3 className="text-lg flex flex-row items-center">{capitalize(title)}</h3>
|
||||
<p className="text-sm text-slate-300">{isAllGood ? "Click to view module status" : "Some systems down"}</p>
|
||||
<p className="text-sm text-slate-300">
|
||||
{isAllGood ? (
|
||||
"Click to view module status"
|
||||
) : (
|
||||
<>
|
||||
<ul>
|
||||
{downItems.map((item) => (
|
||||
<li key={item.id} className="flex justify-between mb-2">
|
||||
<span>{item.id}</span> <Badge text={item.tags[0]} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<SystemHealthModal
|
||||
isSystemHealthModalOpen={isOpen}
|
||||
|
||||
@@ -39,7 +39,7 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd
|
||||
}
|
||||
return (
|
||||
<div className="relative h-100 md:h-75 overflow-y-auto flex flex-col gap-4">
|
||||
<div className="p-2 border-b border-gray-600 grid grid-cols-1 md:grid-cols-2 gap-2 justify-between">
|
||||
<div className="p-2 border-gray-600 grid grid-cols-1 md:grid-cols-2 gap-2 justify-between">
|
||||
<div className="flex flex-col border border-gray-600 p-4 rounded-lg hover:bg-[#233241]">
|
||||
<h3 className="text-lg">Start Time</h3> <span className="text-slate-300">{startTime}</span>
|
||||
</div>
|
||||
|
||||
@@ -25,7 +25,7 @@ const SystemHealthCard = ({
|
||||
refetch,
|
||||
}: SystemOverviewProps) => {
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<Card className="p-4 ">
|
||||
<CardHeader title="System Health" refetch={refetch} icon={faArrowsRotate} />
|
||||
<SystemHealth
|
||||
startTime={startTime}
|
||||
|
||||
@@ -29,7 +29,7 @@ const SystemStatusCard = () => {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<Card className="p-4 ">
|
||||
<CardHeader title="System Status" />
|
||||
{stats ? (
|
||||
<div className="grid grid-cols-2 grid-rows-2 gap-4 col-span-2">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Field, useFormikContext } from "formik";
|
||||
import { useOSDConfig } from "../hooks/useOSDConfig";
|
||||
import { useOSDConfig } from "../../hooks/useOSDConfig";
|
||||
import OSDFieldToggle from "./OSDFieldToggle";
|
||||
import type { OSDConfigFields } from "../../../types/types";
|
||||
import type { OSDConfigFields } from "../../../../types/types";
|
||||
import { toast } from "sonner";
|
||||
|
||||
type OSDFieldsProps = {
|
||||
@@ -12,7 +12,16 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
|
||||
const { osdMutation } = useOSDConfig();
|
||||
const { values } = useFormikContext<OSDConfigFields>();
|
||||
|
||||
const includeKeys = Object.keys(values as OSDConfigFields).filter((value) => value.includes("include"));
|
||||
const validOSDKeys: Array<keyof OSDConfigFields> = [
|
||||
"includeVRM",
|
||||
"includeMotion",
|
||||
"includeTimeStamp",
|
||||
"includeCameraName",
|
||||
"overlayPosition",
|
||||
"OSDTimestampFormat",
|
||||
];
|
||||
|
||||
const includeKeys = validOSDKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
|
||||
|
||||
const handleSubmit = async (values: OSDConfigFields) => {
|
||||
const result = await osdMutation.mutateAsync(values);
|
||||
@@ -1,5 +1,6 @@
|
||||
import Card from "../../../ui/Card";
|
||||
import CardHeader from "../../../ui/CardHeader";
|
||||
import Card from "../../../../ui/Card";
|
||||
import CardHeader from "../../../../ui/CardHeader";
|
||||
import PayloadOptions from "../PayloadOptions/PayloadOptions";
|
||||
import OSDFields from "./OSDFields";
|
||||
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
|
||||
import "react-tabs/style/react-tabs.css";
|
||||
@@ -15,13 +16,13 @@ const OSDOptionsCard = ({ isOSDLoading }: OSDOptionsCardProps) => {
|
||||
<Tabs>
|
||||
<TabList>
|
||||
<Tab>OSD Settings</Tab>
|
||||
<Tab>payload Settings</Tab>
|
||||
<Tab>Payload Settings</Tab>
|
||||
</TabList>
|
||||
<TabPanel>
|
||||
<OSDFields isOSDLoading={isOSDLoading} />
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<div>payload settings</div>
|
||||
<PayloadOptions />
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
</Card>
|
||||
@@ -6,7 +6,7 @@ import { usePostBearerConfig } from "../hooks/useBearer";
|
||||
import { useDispatcherConfig } from "../hooks/useDispatcherConfig";
|
||||
import { useOptionalConstants } from "../hooks/useOptionalConstants";
|
||||
import { useCustomFields } from "../hooks/useCustomFields";
|
||||
import OSDOptionsCard from "./OSDOptionsCard";
|
||||
import OSDOptionsCard from "./OSD/OSDOptionsCard";
|
||||
import { useOSDConfig } from "../hooks/useOSDConfig";
|
||||
|
||||
const OutputForms = () => {
|
||||
@@ -89,6 +89,39 @@ const OutputForms = () => {
|
||||
includeCameraName: includeCameraName ?? false,
|
||||
overlayPosition: overlayPosition ?? "Top",
|
||||
OSDTimestampFormat: OSDTimestampFormat ?? "UTC",
|
||||
|
||||
// payload ooptions
|
||||
includeMac: false,
|
||||
includeSaFID: false,
|
||||
includeCharHeight: false,
|
||||
includeConfidence: false,
|
||||
includeCorrectSpacing: false,
|
||||
includeDecodeID: false,
|
||||
includeDirection: false,
|
||||
includeFrameHeight: false,
|
||||
includeFrameID: false,
|
||||
includeFrameTimeRef: false,
|
||||
includeFrameWidth: false,
|
||||
includeHorizSlew: false,
|
||||
inclduePlate: false,
|
||||
includeNightModeAction: false,
|
||||
includeOverview: false,
|
||||
includePlateSecondary: false,
|
||||
includePlateTrack: false,
|
||||
includePlateTrackSecondary: false,
|
||||
includePreferredCountry: false,
|
||||
includeRawReads: false,
|
||||
includeRawREADSSecondary: false,
|
||||
includeRef: false,
|
||||
includeSeenCount: false,
|
||||
includeRepeatedPlate: false,
|
||||
includeSerialCount: false,
|
||||
includeTraceCount: false,
|
||||
includeTrack: false,
|
||||
includeTrackSecondary: false,
|
||||
includeVertSlew: false,
|
||||
includeVRMSecondary: false,
|
||||
includeHotListMatches: false,
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: FormTypes) => {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useFormikContext } from "formik";
|
||||
import type { PayloadConfigFields } from "../../../../types/types";
|
||||
import PayloadOptionsToggle from "./PayloadOptionsToggle";
|
||||
|
||||
const PayloadOptions = () => {
|
||||
const { values } = useFormikContext<PayloadConfigFields>();
|
||||
|
||||
const validPayloadKeys: Array<keyof PayloadConfigFields> = [
|
||||
"includeMac",
|
||||
"includeSaFID",
|
||||
"includeCharHeight",
|
||||
"includeConfidence",
|
||||
"includeCorrectSpacing",
|
||||
"includeDecodeID",
|
||||
"includeDirection",
|
||||
"includeFrameHeight",
|
||||
"includeFrameID",
|
||||
"includeFrameTimeRef",
|
||||
"includeFrameWidth",
|
||||
"includeHorizSlew",
|
||||
"inclduePlate",
|
||||
"includeNightModeAction",
|
||||
"includeOverview",
|
||||
"includePlateSecondary",
|
||||
"includePlateTrack",
|
||||
];
|
||||
|
||||
const includeKeys = validPayloadKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
|
||||
|
||||
const handleSubmit = async (values: PayloadConfigFields) => {
|
||||
console.log("Payload Config Submitted:", values);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<div className="flex flex-col space-y-4">
|
||||
<div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4">
|
||||
<div className="flex flex-col space-y-4 h-100 overflow-y-auto p-3">
|
||||
{includeKeys.map((key, index) => (
|
||||
<PayloadOptionsToggle key={index} label={key} value={key} />
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleSubmit(values)}
|
||||
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
|
||||
>
|
||||
Save Settings
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PayloadOptions;
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Field } from "formik";
|
||||
|
||||
type PayloadOptionsToggleProps = {
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
const PayloadOptionsToggle = ({ label, value }: PayloadOptionsToggleProps) => {
|
||||
return (
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none w-full justify-between">
|
||||
<span className="text-lg">{label}</span>
|
||||
<Field id={value} type="checkbox" name={value} className="sr-only peer" />
|
||||
<div
|
||||
className="relative w-10 h-5 rounded-full bg-gray-300 transition peer-checked:bg-blue-500 after:content-['']
|
||||
after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:shadow after:transition
|
||||
after:duration-300 peer-checked:after:translate-x-5"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
};
|
||||
|
||||
export default PayloadOptionsToggle;
|
||||
16
src/features/output/hooks/usePayloadConfig.ts
Normal file
16
src/features/output/hooks/usePayloadConfig.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
const fetchPayloadConfig = async () => {
|
||||
const response = await fetch("/api/payload-config");
|
||||
if (!response.ok) throw new Error("Failed to fetch payload config");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const usePayloadCongfig = () => {
|
||||
const payloadConfigQuery = useQuery({
|
||||
queryKey: ["payloadConfig"],
|
||||
queryFn: fetchPayloadConfig,
|
||||
});
|
||||
|
||||
return { payloadConfigQuery };
|
||||
};
|
||||
@@ -11,7 +11,7 @@
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as SettingsRouteImport } from './routes/settings'
|
||||
import { Route as OutputRouteImport } from './routes/output'
|
||||
import { Route as BaywatchRouteImport } from './routes/baywatch'
|
||||
import { Route as CamerasRouteImport } from './routes/cameras'
|
||||
import { Route as AboutRouteImport } from './routes/about'
|
||||
import { Route as IndexRouteImport } from './routes/index'
|
||||
|
||||
@@ -25,9 +25,9 @@ const OutputRoute = OutputRouteImport.update({
|
||||
path: '/output',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const BaywatchRoute = BaywatchRouteImport.update({
|
||||
id: '/baywatch',
|
||||
path: '/baywatch',
|
||||
const CamerasRoute = CamerasRouteImport.update({
|
||||
id: '/cameras',
|
||||
path: '/cameras',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const AboutRoute = AboutRouteImport.update({
|
||||
@@ -44,14 +44,14 @@ const IndexRoute = IndexRouteImport.update({
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
@@ -59,22 +59,22 @@ export interface FileRoutesById {
|
||||
__root__: typeof rootRouteImport
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths: '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
fullPaths: '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to: '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
id: '__root__' | '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
to: '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
id: '__root__' | '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
fileRoutesById: FileRoutesById
|
||||
}
|
||||
export interface RootRouteChildren {
|
||||
IndexRoute: typeof IndexRoute
|
||||
AboutRoute: typeof AboutRoute
|
||||
BaywatchRoute: typeof BaywatchRoute
|
||||
CamerasRoute: typeof CamerasRoute
|
||||
OutputRoute: typeof OutputRoute
|
||||
SettingsRoute: typeof SettingsRoute
|
||||
}
|
||||
@@ -95,11 +95,11 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof OutputRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/baywatch': {
|
||||
id: '/baywatch'
|
||||
path: '/baywatch'
|
||||
fullPath: '/baywatch'
|
||||
preLoaderRoute: typeof BaywatchRouteImport
|
||||
'/cameras': {
|
||||
id: '/cameras'
|
||||
path: '/cameras'
|
||||
fullPath: '/cameras'
|
||||
preLoaderRoute: typeof CamerasRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/about': {
|
||||
@@ -122,7 +122,7 @@ declare module '@tanstack/react-router' {
|
||||
const rootRouteChildren: RootRouteChildren = {
|
||||
IndexRoute: IndexRoute,
|
||||
AboutRoute: AboutRoute,
|
||||
BaywatchRoute: BaywatchRoute,
|
||||
CamerasRoute: CamerasRoute,
|
||||
OutputRoute: OutputRoute,
|
||||
SettingsRoute: SettingsRoute,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import CameraGrid from "../features/cameras/components/CameraGrid";
|
||||
|
||||
export const Route = createFileRoute("/baywatch")({
|
||||
export const Route = createFileRoute("/cameras")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<CameraGrid />
|
||||
</div>
|
||||
);
|
||||
return <CameraGrid />;
|
||||
}
|
||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/output")({
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<OutputForms />
|
||||
</div>
|
||||
);
|
||||
return <OutputForms />;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/settings")({
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<Settings />
|
||||
</div>
|
||||
);
|
||||
return <Settings />;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { CameraID } from "../app/config/cameraConfig";
|
||||
|
||||
export type WebSocketContextValue = {
|
||||
connected: boolean;
|
||||
send?: (msg: unknown) => void;
|
||||
@@ -86,7 +88,51 @@ export type OSDConfigFields = {
|
||||
OSDTimestampFormat: "UTC" | "LOCAL";
|
||||
};
|
||||
|
||||
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs & CustomFields & OSDConfigFields;
|
||||
export type PayloadConfigFields = {
|
||||
includeMac: boolean;
|
||||
includeSaFID: boolean;
|
||||
includeCameraName: boolean;
|
||||
includeCharHeight: boolean;
|
||||
includeConfidence: boolean;
|
||||
includeCorrectSpacing: boolean;
|
||||
includeDecodeID: boolean;
|
||||
includeDirection: boolean;
|
||||
includeFrameHeight: boolean;
|
||||
includeFrameID: boolean;
|
||||
includeFrameTimeRef: boolean;
|
||||
includeFrameWidth: boolean;
|
||||
includeHorizSlew: boolean;
|
||||
includeMotion: boolean;
|
||||
inclduePlate: boolean;
|
||||
includeNightModeAction: boolean;
|
||||
includeOverview: boolean;
|
||||
includePlateSecondary: boolean;
|
||||
includePlateTrack: boolean;
|
||||
includePlateTrackSecondary: boolean;
|
||||
includePreferredCountry: boolean;
|
||||
includeRawReads: boolean;
|
||||
includeRawREADSSecondary: boolean;
|
||||
includeRef: boolean;
|
||||
includeSeenCount: boolean;
|
||||
includeRepeatedPlate: boolean;
|
||||
includeSerialCount: boolean;
|
||||
includeTimeStamp: boolean;
|
||||
includeTraceCount: boolean;
|
||||
includeTrack: boolean;
|
||||
includeTrackSecondary: boolean;
|
||||
includeVertSlew: boolean;
|
||||
includeVRM: boolean;
|
||||
includeVRMSecondary: boolean;
|
||||
includeHotListMatches: boolean;
|
||||
};
|
||||
|
||||
export type FormTypes = BearerTypeFields &
|
||||
OptionalConstants &
|
||||
OptionalLaneIDs &
|
||||
CustomFields &
|
||||
OSDConfigFields &
|
||||
PayloadConfigFields;
|
||||
|
||||
type FieldProperty = {
|
||||
datatype: string;
|
||||
value: string;
|
||||
@@ -128,57 +174,43 @@ export type OptionalBOF2LaneIDs = {
|
||||
};
|
||||
|
||||
export type CameraFeedState = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
paintedCells: {
|
||||
A: Map<string, PaintedCell>;
|
||||
B: Map<string, PaintedCell>;
|
||||
C: Map<string, PaintedCell>;
|
||||
};
|
||||
regionsByCamera: {
|
||||
A: Region[];
|
||||
B: Region[];
|
||||
C: Region[];
|
||||
};
|
||||
cameraFeedID: CameraID;
|
||||
brushSize: number;
|
||||
paintedCells: Record<CameraID, Map<string, PaintedCell>>;
|
||||
|
||||
regionsByCamera: Record<CameraID, Region[]>;
|
||||
selectedRegionIndex: number;
|
||||
modeByCamera: {
|
||||
A: string;
|
||||
B: string;
|
||||
C: string;
|
||||
};
|
||||
modeByCamera: Record<CameraID, string>;
|
||||
|
||||
tabIndex?: number;
|
||||
zoomLevel: {
|
||||
A: number;
|
||||
B: number;
|
||||
C: number;
|
||||
};
|
||||
zoomLevel: Record<CameraID, number>;
|
||||
};
|
||||
|
||||
export type CameraFeedAction =
|
||||
| {
|
||||
type: "SET_CAMERA_FEED";
|
||||
payload: "A" | "B" | "C";
|
||||
payload: CameraID;
|
||||
}
|
||||
| {
|
||||
type: "CHANGE_MODE";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; mode: string };
|
||||
payload: { cameraFeedID: CameraID; mode: string };
|
||||
}
|
||||
| { type: "SET_SELECTED_REGION_INDEX"; payload: number }
|
||||
| {
|
||||
type: "SET_SELECTED_REGION_COLOUR";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; newColour: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string; newColour: string };
|
||||
}
|
||||
| {
|
||||
type: "ADD_NEW_REGION";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; brushColour: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string; brushColour: string };
|
||||
}
|
||||
| {
|
||||
type: "REMOVE_REGION";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string };
|
||||
}
|
||||
| {
|
||||
type: "RESET_PAINTED_CELLS";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map<string, PaintedCell> };
|
||||
payload: { cameraFeedID: CameraID; paintedCells: Map<string, PaintedCell> };
|
||||
}
|
||||
| {
|
||||
type: "SET_CAMERA_FEED_DATA";
|
||||
@@ -189,7 +221,11 @@ export type CameraFeedAction =
|
||||
}
|
||||
| {
|
||||
type: "SET_ZOOM_LEVEL";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; zoomLevel: number };
|
||||
payload: { cameraFeedID: CameraID; zoomLevel: number };
|
||||
}
|
||||
| {
|
||||
type: "SET_BRUSH_SIZE";
|
||||
payload: { brushSize: number };
|
||||
};
|
||||
|
||||
export type DecodeReading = {
|
||||
@@ -211,7 +247,7 @@ export type ColourData = {
|
||||
};
|
||||
|
||||
export type ColourDetectionPayload = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
regions: ColourData[];
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ const Header = () => {
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/baywatch"
|
||||
to="/cameras"
|
||||
className="[&.active]:font-bold [&.active]:bg-gray-700 p-2 rounded-lg flex items-center gap-2 hover:bg-gray-700"
|
||||
>
|
||||
Cameras
|
||||
@@ -58,7 +58,7 @@ const Header = () => {
|
||||
{/* <FontAwesomeIcon icon={faGaugeHigh} /> */}
|
||||
Dashboard
|
||||
</Link>
|
||||
<Link to="/baywatch" className="" onClick={toggleMenu}>
|
||||
<Link to="/cameras" className="" onClick={toggleMenu}>
|
||||
{/* <FontAwesomeIcon icon={faGaugeHigh} /> */}
|
||||
Cameras
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user