/* StatusCNC.js - ESP3D WebUI component file Copyright (c) 2021 Luc LEBOSSE. All rights reserved. This code is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with This code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import { Fragment, TargetedMouseEvent } from "preact" import type { FunctionalComponent, VNode } from "preact" import { T } from "../Translations" import { useUiContextFn } from "../../contexts" import { useTargetContext, variablesList } from "../../targets" import { ButtonImg, Button, FullScreenButton, CloseButton, ContainerHelper } from "../Controls" import { useTargetCommands } from "../../hooks" import { Layers, Unlock, RefreshCcw, Moon, Play, Pause, } from "preact-feather" /* * Local const * */ type StreamStatus = { status?: string name?: string type?: string processed?: number total?: number code?: number } const StatusControls: FunctionalComponent = () => { const { status, message, alarmCode, errorCode, streamStatus } = useTargetContext() as unknown as { status: { state?: string; code?: number } message?: string alarmCode: number errorCode: number streamStatus: StreamStatus } if (!useUiContextFn.getValue("showstatuspanel")) return null return ( {status.state && (
{T(status.state)}
{streamStatus.status && (
{T(streamStatus.status)} {streamStatus.name ? ` (${streamStatus.type}) ${ streamStatus.name } ${ streamStatus.total ? ( (Number(streamStatus.processed) / Number(streamStatus.total)) * 100 ).toFixed(0) : streamStatus.processed }%` : ""}
)} {streamStatus.code && (
{T("S22")} {`: ${ streamStatus.code}`}
)} {status.code && (
{T(`${status.state }:${ status.code}`)}
)} {message && (
{T(message)}
)} {(alarmCode != 0 || errorCode != 0) && (
{T( alarmCode != 0 ? `ALARM:${ alarmCode}` : `error:${ errorCode}` )}
)}
)}
) } type ModeDescriptor = { id: string; label: string; pre?: string } type PinsStates = Record type StatesMap = Record | unknown> const StatusPanel: FunctionalComponent = () => { const { status, states, pinsStates, streamStatus } = useTargetContext() as unknown as { status: { state?: string } states: StatesMap pinsStates: PinsStates streamStatus: StreamStatus } const { targetCommands } = useTargetCommands() const id = "statusPanel" const buttonsList: Array<{ name: string depend?: string[] | (() => boolean) buttons: Array<{ cmd: string icon: VNode desc: string depend?: string[] | (() => boolean) }> }> = [ { name: "CN40", buttons: [ { cmd: "$X", icon: , desc: T("CN42"), }, { cmd: "#SOFTRESET#", icon: , desc: T("CN41"), }, { cmd: "$SLP", icon: , desc: T("CN43"), }, { cmd: "#FEEDHOLD#", icon: , desc: T("Hold"), depend: [ "Door", "Sleep", "Alarm", "Error", "Check", "Run", "Idle", "Home", "Jog", "Tool", "?", ], }, { cmd: "#CYCLESTART#", icon: , desc: T("CN61"), depend: ["Hold", "Tool"], }, ], }, ] return (
{pinsStates && Object.keys(pinsStates).length > 0 && (
{Object.keys(pinsStates).map((pin) => { return (
{pin}
) })}
)} {states && Object.keys(states).length > 0 && states["motion_mode"] && variablesList.modes && (
{(variablesList.modes as ModeDescriptor[]).map((element) => { if ((states as StatesMap)[element.id]) { const stateEntry = (states as StatesMap)[element.id] if (Array.isArray(stateEntry)) { return (stateEntry as Array<{ value: string; pre?: string }>).map((item) => { return( ) }) } else return ( ) } })}
)} {buttonsList.map((list) => { if (list.depend) { if (list.depend) { if (typeof list.depend === "function") { if (!list.depend()) { return } } else if (!list.depend.includes(status.state || "")) return } } return (
{list.buttons.map((button) => { if (button.depend) { if ( typeof button.depend === "function" ) { if (!button.depend()) { return } } else if ( !button.depend.includes( status.state || "" ) ) return } return ( ) => { useUiContextFn.haptic() e.currentTarget.blur() targetCommands(button.cmd) }} /> ) })}
) })}
) } const StatusPanelElement = { id: "statusPanel", content: , name: "CN34", icon: "Layers", show: "showstatuspanel", onstart: "openstatusonstart", settingid: "status", } export { StatusPanel, StatusPanelElement, StatusControls }