import React from "react"; import styled from "styled-components"; import { Card, CardList, Section, Elevation, Switch } from "@blueprintjs/core"; import { DualsenseHIDState } from "dualsense-ts"; import { ControllerContext } from "../Controller"; const StyledDebugger = styled.div` grid-column: 1; grid-row: 1/-1; justify-content: right; align-items: top; display: flex; opacity: 0.7; padding: 1vw; width: 20vw; `; const ScrollablePre = styled.pre` overflow: scroll; word-break: normal !important; word-wrap: normal !important; white-space: pre !important; width: 15vw; max-height: 30vw; `; export const Debugger = () => { const controller = React.useContext(ControllerContext); const [controllerState, setDebugState] = React.useState( controller.hid.state ); const [showReport, setShowReport] = React.useState(false); const [showState, setShowState] = React.useState(false); React.useEffect(() => { controller.on("change", (controller) => { setDebugState(controller.hid.state); }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); let reportBuffer: string = ""; let reportLength: string = ""; if (controller.hid.provider.buffer) { const report = controller.hid.provider.buffer as DataView; reportBuffer = `const report = Buffer.from([${new Uint8Array( report.buffer ).join(", ")}])`; reportLength = `${report.byteLength} bytes`; } else { reportBuffer = "Waiting for report..."; reportLength = "unknown"; } return (
Connected: {controller.hid.provider.connected ? "yes" : "no"} Method:{" "} {controller.hid.provider.wireless === undefined ? "none" : controller.hid.provider.wireless ? "bluetooth" : "usb"} Limited:{" "} {controller.hid.provider.limited === undefined ? "unknown" : controller.hid.provider.limited ? "yes" : "no"}
setShowState(!showState)} /> setShowReport(!showReport)} />
{showReport ? [
Buffer Sample
{reportBuffer}
, ] : []} {showState ? [
{Object.entries(controllerState) .map( ([key, val], index) => `${key}: ${JSON.stringify(val)}` ) .join("\n")}
, ] : []}
); };