diff --git a/control-station/src/components/KeyboardStopHandler.tsx b/control-station/src/components/KeyboardStopHandler.tsx new file mode 100644 index 0000000..fbb04c1 --- /dev/null +++ b/control-station/src/components/KeyboardStopHandler.tsx @@ -0,0 +1,26 @@ +import { useEffect } from "react"; +import PodSocketClient from "services/PodSocketClient"; + +interface KeyboardStopHandlerProps { + podSocketClient: PodSocketClient; +} + +function KeyboardStopHandler({ podSocketClient }: KeyboardStopHandlerProps) { + useEffect(() => { + const downHandler = (event: KeyboardEvent) => { + if (event.code === "Space") { + console.log("emit stop"); + podSocketClient.sendStop(); + } + }; + window.addEventListener("keydown", downHandler); + + return () => { + window.removeEventListener("keydown", downHandler); + }; + }, [podSocketClient]); + + return <>; +} + +export default KeyboardStopHandler; diff --git a/control-station/src/views/Dashboard/Dashboard.tsx b/control-station/src/views/Dashboard/Dashboard.tsx index 127cef3..1961b28 100644 --- a/control-station/src/views/Dashboard/Dashboard.tsx +++ b/control-station/src/views/Dashboard/Dashboard.tsx @@ -1,3 +1,4 @@ +import KeyboardStopHandler from "components/KeyboardStopHandler"; import usePodData from "./usePodData"; function Dashboard() { @@ -12,6 +13,7 @@ function Dashboard() {

wheel counter - {podData.wheelCounter}

wheel speed - {podData.wheelSpeed.toFixed(2)}

+