/* function clickBtn(id: string) { const el = document.getElementById(id) as HTMLInputElement | null if (el) el.click() } /* function clickBtn(id: string) { const el = document.getElementById(id) as HTMLInputElement | null if (el) el.click() } /* const clickBtn = (id: string) => { const el = document.getElementById(id) as HTMLInputElement | null if (el) el.click() } /* JogPlotter.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 } from "preact" import { Edit2, Home, Move, ChevronDown, Edit3, StopCircle, } from "preact-feather" import { useTargetCommands } from "../../hooks" import { useUiContextFn, useModalsContext, useToastsContext } from "../../contexts" import { T } from "../Translations" import { Button, ButtonImg, FullScreenButton, CloseButton, ContainerHelper } from "../Controls" import { useEffect } from "preact/hooks" import { showModal } from "../Modal" import { useTargetContext, variablesList } from "../../targets" import { Field } from "../Controls" let currentVelocity = 0 let currentJogDistance = 100 let currentSteps = 0 /* * Local const * */ //A separate control to avoid the full panel to be updated when the positions are updated const PositionsControls: FunctionalComponent = () => { const { positions } = useTargetContext() const steps = useUiContextFn.getValue("steps") return (
{useUiContextFn.getValue("showx") && (
{typeof positions.x != "undefined" && (
X
{positions.x == "?" ? "?" : positions.x / steps}
)}
)} {useUiContextFn.getValue("showy") && (
{typeof positions.y != "undefined" && (
Y
{positions.y == "?" ? "?" : positions.y / steps}
)}
)} {useUiContextFn.getValue("showpen") && (
{typeof positions.pen != "undefined" && (
{T("HP17")}
{positions.pen == "?" ? ( "?" ) : positions.pen == "1" ? ( ) : ( _ )}
)}
)}
) } const JogPanel: FunctionalComponent = () => { const { modals } = useModalsContext() const { targetCommands } = useTargetCommands() const { positions } = useTargetContext() const id = "jogPanel" console.log(id) function clickBtn(id: string) { const el = document.getElementById(id) as HTMLInputElement | null if (el) el.click() } //we could use an array of object {distance, prev, next} //but for the 5 entries this works too const selectorBtn = (type: string) => { if (type == "+") { if (currentJogDistance == 100) clickBtn("move_0_1") else if (currentJogDistance == 0.1) clickBtn("move_1") else if (currentJogDistance == 1) clickBtn("move_10") else if (currentJogDistance == 10) clickBtn("move_50") else if (currentJogDistance == 50) clickBtn("move_100") } else if (type == "-") { if (currentJogDistance == 100) clickBtn("move_50") else if (currentJogDistance == 0.1) clickBtn("move_100") else if (currentJogDistance == 1) clickBtn("move_0_1") else if (currentJogDistance == 10) clickBtn("move_1") else if (currentJogDistance == 50) clickBtn("move_10") } } //Send Home command const sendParkCommand = () => { const command = useUiContextFn.getValue("jogparkcmd") const cmds = command.split(";") cmds.forEach((cmd: any) => { if (cmd.trim().length > 0) { targetCommands(variablesList.formatCommand(cmd)) } }) } const buttonsInfos: any = {} const initButtons = () => { const btnYplus = { label: "Y+", tooltip: "HP6", cmd: "Y+" } const btnXplus = { label: "X+", tooltip: "HP6", cmd: "X+" } const btnYminus = { label: "Y-", tooltip: "HP7", cmd: "Y-", } const btnXminus = { label: "X-", tooltip: "HP7", cmd: "X-", } const showxy = useUiContextFn.getValue("showx") && useUiContextFn.getValue("showy") const invertx = useUiContextFn.getValue("invertx") const inverty = useUiContextFn.getValue("inverty") const swapxy = showxy ? useUiContextFn.getValue("swapxy") : false if (swapxy) { if (inverty) { buttonsInfos.R = btnYplus buttonsInfos.L = btnYminus } else { buttonsInfos.L = btnYplus buttonsInfos.R = btnYminus } if (invertx) { buttonsInfos.B = btnXplus buttonsInfos.T = btnXminus } else { buttonsInfos.T = btnXplus buttonsInfos.B = btnXminus } } else { if (inverty) { buttonsInfos.B = btnYplus buttonsInfos.T = btnYminus } else { buttonsInfos.T = btnYplus buttonsInfos.B = btnYminus } if (invertx) { buttonsInfos.R = btnXplus buttonsInfos.L = btnXminus } else { buttonsInfos.L = btnXplus buttonsInfos.R = btnXminus } } } initButtons() //Send jog command const sendJogCommand = (axis: string) => { let velocitycmd = "" let jogcmd = "PR" if (currentVelocity != 0) velocitycmd = `VS${ currentVelocity };` switch (axis) { case "X+": jogcmd += `${currentJogDistance * currentSteps },0;` break case "X-": jogcmd += `-${ currentJogDistance * currentSteps },0;` break case "Y-": jogcmd += `0,-${ currentJogDistance * currentSteps };` break case "Y+": jogcmd += `0,${ currentJogDistance * currentSteps };` break default: console.log(`Unknow axis: ${ axis}`) return } if (velocitycmd.length != 0) { targetCommands(velocitycmd) } targetCommands(jogcmd) } //click distance button const onCheck = (e: TargetedMouseEvent, distance: number) => { e.currentTarget.blur() currentJogDistance = distance } //Set the current velocity const setVelocity = () => { let value: any = currentVelocity showModal({ modals, title: T("HP1"), button2: { text: T("S28") }, button1: { cb: () => { if (String(value).length >= 0) currentVelocity = Number(value) }, text: T("S43"), id: "applyVelocityBtn", }, icon: , id: "inputVelocity", content: (
{T("HP1")}
{ value = e.currentTarget.value.trim() console.log(value) if (Number(value) < 0 || String(value).length == 0) { const btn = document.getElementById("applyVelocityBtn") as HTMLButtonElement | null if (btn) btn.disabled = true } else { const btn = document.getElementById("applyVelocityBtn") as HTMLButtonElement | null if (btn) btn.disabled = false } }} />
), }) } //Set the current velocity const setSteps = () => { let value: any = currentSteps showModal({ modals, title: T("HP2"), button2: { text: T("S28") }, button1: { cb: () => { if (String(value).length >= 0) currentSteps = Number(value) }, text: T("S43"), id: "applyStepsBtn", }, icon: , id: "inputSteps", content: (
{T("HP2")}
{ value = e.currentTarget.value.trim() if (Number(value) < 1 || String(value).length == 0) { const btn = document.getElementById("applyStepsBtn") as HTMLButtonElement | null if (btn) btn.disabled = true } else { const btn = document.getElementById("applyStepsBtn") as HTMLButtonElement | null if (btn) btn.disabled = false } }} />
), }) } useEffect(() => { currentVelocity = useUiContextFn.getValue("velocity") currentSteps = useUiContextFn.getValue("steps") }, []) return (
{((useUiContextFn.getValue("showx") && buttonsInfos.T.cmd.startsWith("X")) || (useUiContextFn.getValue("showy") && buttonsInfos.T.cmd.startsWith( "Y" ))) && ( )}
{((useUiContextFn.getValue("showx") && buttonsInfos.L.cmd.startsWith("X")) || (useUiContextFn.getValue("showy") && buttonsInfos.L.cmd.startsWith( "Y" ))) && ( ) => { useUiContextFn.haptic() e.currentTarget.blur() sendJogCommand(buttonsInfos.L.cmd) }} /> )} } data-tooltip={T("HP19")} id={"btnpark"} onClick={(e: TargetedMouseEvent) => { useUiContextFn.haptic() e.currentTarget.blur() sendParkCommand() }} /> {((useUiContextFn.getValue("showx") && buttonsInfos.L.cmd.startsWith("X")) || (useUiContextFn.getValue("showy") && buttonsInfos.L.cmd.startsWith( "Y" ))) && ( ) => { useUiContextFn.haptic() e.currentTarget.blur() sendJogCommand(buttonsInfos.R.cmd) }} /> )}
{((useUiContextFn.getValue("showx") && buttonsInfos.B.cmd.startsWith("X")) || (useUiContextFn.getValue("showy") && buttonsInfos.B.cmd.startsWith( "Y" ))) && ( ) => { useUiContextFn.haptic() e.currentTarget.blur() sendJogCommand(buttonsInfos.B.cmd) }} /> )}
mm
{ selectorBtn("+") }} />
{ selectorBtn("-") }} />
) => { useUiContextFn.haptic() onCheck(e, 100) }} />
) => { useUiContextFn.haptic() onCheck(e, 50) }} />
) => { useUiContextFn.haptic() onCheck(e, 10) }} />
) => { useUiContextFn.haptic() onCheck(e, 1) }} />
) => { useUiContextFn.haptic() onCheck(e, 0.1) }} />
{useUiContextFn.getValue("showpen") && ( { if (!update) { if (val) { targetCommands("PD;") positions.pen = true } else { targetCommands("PU;") positions.pen = false } } }} label={T("HP20")} /> )} } data-tooltip={T("HP11")} onClick={(e: TargetedMouseEvent) => { useUiContextFn.haptic() e.currentTarget.blur() const cmds = useUiContextFn .getValue("jogstopcmd") .split(";") cmds.forEach((cmd: any) => { if (cmd.trim().length > 0) { targetCommands( variablesList.formatCommand(cmd) ) } }) }} />
) } const JogPanelElement = { id: "jogPanel", content: , name: "S66", icon: "Move", show: "showjogpanel", onstart: "openjogonstart", settingid: "jog", } export { JogPanel, JogPanelElement, PositionsControls }