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