diff --git a/src/modes/InnoboticsJogModeTileHelper.ts b/src/modes/InnoboticsJogModeTileHelper.ts deleted file mode 100644 index 0b3b104..0000000 --- a/src/modes/InnoboticsJogModeTileHelper.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2024. Glowbuzzer. All rights reserved - */ - -import { - DockTileDefinition, - DockTileDefinitionBuilder, - DockTileDisabled -} from "@glowbuzzer/controls" -import { useDeadman, useManualKeyswitch } from "@glowbuzzer/awlib" -import * as React from "react" -import { createElement } from "react" - -function get_message(op: boolean, keyswitch: boolean, mode: string, deadman: boolean) { - if (!op) { - return "Operation Not Enabled" - } - if (!keyswitch) { - return "Manual Keyswitch Not Engaged" - } - if (mode !== "jog") { - return "Jog Mode Not Selected" - } - if (!deadman) { - return "Deadman Not Engaged" - } -} - -export function InnoboticsJogModeTileHelper(tileDefinition: DockTileDefinition) { - return DockTileDefinitionBuilder(tileDefinition) - .wrapper((tile, connected, op, mode): React.ReactElement => { - const keyswitch = useManualKeyswitch() - const deadman = useDeadman() - - if (!connected) { - return createElement(DockTileDisabled, { - children: tile - }) - } - - const message = get_message(op, keyswitch, mode, deadman) - if (message) { - return createElement(DockTileDisabled, { - children: tile, - content: message - }) - } - return createElement(React.Fragment, { children: tile }) - }) - .build() -} diff --git a/src/modes/InnoboticsJogTileWrapper.tsx b/src/modes/InnoboticsJogTileWrapper.tsx new file mode 100644 index 0000000..6bcc5d6 --- /dev/null +++ b/src/modes/InnoboticsJogTileWrapper.tsx @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024. Glowbuzzer. All rights reserved + */ + +import * as React from "react" +import { useDeadman, useManualKeyswitch } from "@glowbuzzer/awlib" +import { useConnection } from "@glowbuzzer/store" +import { DockTileDisabled, useGlowbuzzerMode, useOperationEnabled } from "@glowbuzzer/controls" + +function get_message(op: boolean, keyswitch: boolean, mode: string, deadman: boolean) { + if (!op) { + return "Operation Not Enabled" + } + if (!keyswitch) { + return "Manual Keyswitch Not Engaged" + } + if (mode !== "jog") { + return "Jog Mode Not Selected" + } + if (!deadman) { + return "Deadman Not Engaged" + } +} + +export const InnoboticsJogTileWrapper = ({ children }) => { + const [{ actValue: keyswitch }] = useManualKeyswitch() + const [{ actValue: deadman }] = useDeadman() + const { connected } = useConnection() + const op = useOperationEnabled() + const { mode } = useGlowbuzzerMode() + + if (!connected) { + return + } + + const message = get_message(op, keyswitch, mode, deadman) + if (message) { + return + } + + return <>{children} +}