Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Implement KeyboardStopHandler for manual stop
Browse files Browse the repository at this point in the history
- Emit stop event when spacebar is pressed in the dashboard
  • Loading branch information
taesungh committed Jun 3, 2023
1 parent b8d774b commit 06b46c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions control-station/src/components/KeyboardStopHandler.tsx
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions control-station/src/views/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import KeyboardStopHandler from "components/KeyboardStopHandler";
import usePodData from "./usePodData";

function Dashboard() {
Expand All @@ -12,6 +13,7 @@ function Dashboard() {
<p>wheel counter - {podData.wheelCounter}</p>
<p>wheel speed - {podData.wheelSpeed.toFixed(2)}</p>
</div>
<KeyboardStopHandler podSocketClient={podSocketClient} />
<button onClick={() => podSocketClient.sendService()}>service</button>
<button onClick={() => podSocketClient.sendStart()}>start</button>
<button onClick={() => podSocketClient.sendStop()}>stop</button>
Expand Down

0 comments on commit 06b46c3

Please sign in to comment.