Skip to content

Commit

Permalink
Allow empty line in grblHAL per request #364
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-github committed Aug 16, 2023
1 parent 7620056 commit d723801
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 70 deletions.
Binary file modified dist/CNC/GRBL/index.html.gz
Binary file not shown.
Binary file modified dist/CNC/GRBLHal/index.html.gz
Binary file not shown.
Binary file modified dist/Plotter/HP-GL/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Marlin-embedded/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Marlin/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Repetier/index.html.gz
Binary file not shown.
Binary file modified dist/Printer3D/Smoothieware/index.html.gz
Binary file not shown.
Binary file modified dist/SandTable/GRBL/index.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/App/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
import { h } from 'preact'
import { webUIbuild } from '../../targets'
export const webUIversion = '3.0.0-a38'
export const webUIversion = '3.0.0-a39'
export const Esp3dVersion = () => (
<span>
{webUIversion}.{webUIbuild}
Expand Down
99 changes: 55 additions & 44 deletions src/components/Panels/Terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

import { h } from "preact"
import { useEffect, useRef, useState } from "preact/hooks"
import { T } from "../Translations"
import { h } from 'preact'
import { useEffect, useRef, useState } from 'preact/hooks'
import { T } from '../Translations'
import {
Terminal,
Send,
CheckCircle,
Circle,
PauseCircle,
} from "preact-feather"
import { useUiContext, useDatasContext, useUiContextFn } from "../../contexts"
import { useTargetContext, variablesList } from "../../targets"
import { useHttpQueue } from "../../hooks"
import { espHttpURL, replaceVariables } from "../Helpers"
import { ButtonImg } from "../Controls"
import { Menu as PanelMenu } from "./"
} from 'preact-feather'
import { useUiContext, useDatasContext, useUiContextFn } from '../../contexts'
import { useTargetContext, variablesList } from '../../targets'
import { useHttpQueue } from '../../hooks'
import { espHttpURL, replaceVariables } from '../Helpers'
import { ButtonImg } from '../Controls'
import { Menu as PanelMenu } from './'

/*
* Local const
Expand All @@ -43,9 +43,9 @@ const TerminalPanel = () => {
const { processData } = useTargetContext()
const { createNewRequest } = useHttpQueue()
if (terminal.isVerbose.current == undefined)
terminal.isVerbose.current = uisettings.getValue("verbose")
terminal.isVerbose.current = uisettings.getValue('verbose')
if (terminal.isAutoScroll.current == undefined)
terminal.isAutoScroll.current = uisettings.getValue("autoscroll")
terminal.isAutoScroll.current = uisettings.getValue('autoscroll')
const [isVerbose, setIsVerbose] = useState(terminal.isVerbose.current)
const [isAutoScroll, setIsAutoScroll] = useState(
terminal.isAutoScroll.current
Expand All @@ -55,7 +55,7 @@ const TerminalPanel = () => {
const inputRef = useRef()
const messagesEndRef = useRef(null)
const terminalOutput = useRef(null)
const id = "terminalPanel"
const id = 'terminalPanel'
let inputHistoryIndex = terminal.inputHistory.length - 1
const scrollToBottom = () => {
if (
Expand Down Expand Up @@ -92,7 +92,7 @@ const TerminalPanel = () => {
terminal.inputHistory[inputHistoryIndex]
terminal.input.current = inputRef.current.value
} else {
inputRef.current.value = ""
inputRef.current.value = ''
terminal.input.current = inputRef.current.value
}
break
Expand All @@ -103,48 +103,52 @@ const TerminalPanel = () => {
const onSend = (e) => {
useUiContextFn.haptic()
inputRef.current.focus()
if (!terminal.input.current && variablesList.allowEmptyLine)
terminal.input.current = ''
if (
terminal.input.current &&
terminal.input.current.trim().length > 0
(terminal.input.current &&
terminal.input.current.trim().length > 0) ||
variablesList.allowEmptyLine
) {
const cmd = terminal.input.current.trim()
if (
cmd.length > 0 &&
terminal.inputHistory[terminal.inputHistory.length - 1] != cmd
) {
terminal.addInputHistory(cmd)
}

inputHistoryIndex = terminal.inputHistory.length - 1
processData(
"echo",
'echo',
replaceVariables(variablesList.commands, cmd, true)
)
createNewRequest(
espHttpURL("command", {
espHttpURL('command', {
cmd: replaceVariables(variablesList.commands, cmd),
}),
{ method: "GET" },
{ method: 'GET' },
{
onSuccess: (result) => {
processData("response", result)
processData('response', result)
},
onFail: (error) => {
console.log(error)
processData("error", error)
processData('error', error)
},
}
)
}
terminal.input.current = ""
inputRef.current.value = ""
terminal.input.current = ''
inputRef.current.value = ''
}
const onInput = (e) => {
terminal.input.current = e.target.value
}
useEffect(() => {
scrollToBottom()
}, [terminal.content])
console.log("Terminal panel")
console.log('Terminal panel')

const toggleVerboseMode = () => {
useUiContextFn.haptic()
Expand All @@ -165,7 +169,7 @@ const TerminalPanel = () => {

const menu = [
{
label: T("S76"),
label: T('S76'),
displayToggle: () => (
<span class="feather-icon-container">
{isVerbose ? (
Expand All @@ -178,7 +182,7 @@ const TerminalPanel = () => {
onClick: toggleVerboseMode,
},
{
label: T("S77"),
label: T('S77'),
displayToggle: () => (
<span class="feather-icon-container">
{isAutoScroll ? (
Expand All @@ -196,7 +200,7 @@ const TerminalPanel = () => {
},
{ divider: true },
{
label: T("S79"),
label: T('S79'),
onClick: (e) => {
useUiContextFn.haptic()
terminal.clear()
Expand All @@ -210,7 +214,7 @@ const TerminalPanel = () => {
<div class="navbar">
<span class="navbar-section feather-icon-container">
<Terminal />
<strong class="text-ellipsis">{T("Terminal")}</strong>
<strong class="text-ellipsis">{T('Terminal')}</strong>
</span>
<span class="navbar-section">
<span style="height: 100%;">
Expand All @@ -234,13 +238,13 @@ const TerminalPanel = () => {
onkeyup={onKeyUp}
ref={inputRef}
value={terminal.input.current}
placeholder={T("S80")}
placeholder={T('S80')}
/>
<ButtonImg
group
ltooltip
data-tooltip={T("S82")}
label={T("S81")}
data-tooltip={T('S82')}
label={T('S81')}
icon={<Send />}
onClick={onSend}
/>
Expand Down Expand Up @@ -272,20 +276,27 @@ const TerminalPanel = () => {
>
{terminal.content &&
terminal.content.map((line) => {
let className = ""
let className = ''
switch (line.type) {
case "echo":
className = "echo"
case 'echo':
className = 'echo'
break
case "error":
className = "error"
case 'error':
className = 'error'
break
default:
//do nothing
}
if (line.isAction) {
return <pre class="action" title={line.actionType}>{line.content}</pre>
} else if (isVerbose || isVerbose === line.isverboseOnly) {
return (
<pre class="action" title={line.actionType}>
{line.content}
</pre>
)
} else if (
isVerbose ||
isVerbose === line.isverboseOnly
) {
return <pre class={className}>{line.content}</pre>
}
})}
Expand All @@ -296,13 +307,13 @@ const TerminalPanel = () => {
}

const TerminalPanelElement = {
id: "terminalPanel",
id: 'terminalPanel',
content: <TerminalPanel />,
name: "S75",
icon: "Terminal",
show: "showterminalpanel",
onstart: "openterminalonstart",
settingid: "terminal",
name: 'S75',
icon: 'Terminal',
show: 'showterminalpanel',
onstart: 'openterminalonstart',
settingid: 'terminal',
}

export { TerminalPanel, TerminalPanelElement }
51 changes: 26 additions & 25 deletions src/targets/CNC/grblHAL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,63 @@
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 { h } from "preact"
import { iconsTarget } from "./icons"
import { files } from "./files"
import { processor } from "./processor"
import { gcode_parser_modes } from "./gcode_parser_modes"
import { defaultPanelsList } from "./panels"
import { MachineSettings } from "./MachineSettings"
import { h } from 'preact'
import { iconsTarget } from './icons'
import { files } from './files'
import { processor } from './processor'
import { gcode_parser_modes } from './gcode_parser_modes'
import { defaultPanelsList } from './panels'
import { MachineSettings } from './MachineSettings'
import {
InformationsControls,
QuickButtonsBar,
BackgroundContainer,
} from "./Controls"
} from './Controls'
import {
TargetContextProvider,
useTargetContext,
useTargetContextFn,
} from "./TargetContext"
import realCommandsTable from "./realCommandsTable"
import variablesTable from "./variablesTable"
import { AppLogo as WebUILogo } from "../../../components/Images/logo"
import { AppLogo } from "./logo"
import { addObjectItem, removeObjectItem } from "../../../components/Helpers"
} from './TargetContext'
import realCommandsTable from './realCommandsTable'
import variablesTable from './variablesTable'
import { AppLogo as WebUILogo } from '../../../components/Images/logo'
import { AppLogo } from './logo'
import { addObjectItem, removeObjectItem } from '../../../components/Helpers'

const Target = "grblHAL"
const webUIbuild = "GH2"
const Name = "grblHAL"
const Target = 'grblHAL'
const webUIbuild = 'GH2'
const Name = 'grblHAL'
const fwUrl = [
"https://github.com/grblHAL",
"https://github.com/luc-github/ESP3D-TFT",
'https://github.com/grblHAL',
'https://github.com/luc-github/ESP3D-TFT',
]

const restartdelay = 30
const variablesList = {
commands: [...realCommandsTable, ...variablesTable],
addCommand: (variable) =>
addObjectItem(variablesList.commands, "name", variable),
addObjectItem(variablesList.commands, 'name', variable),
removeCommand: (name) =>
removeObjectItem(variablesList.commands, "name", name),
removeObjectItem(variablesList.commands, 'name', name),
modes: [...gcode_parser_modes],
hideFeatures: false,
allowEmptyLine: true,
}
const eventsList = {
evts: [],
on: (event, fn) => {
if (typeof eventsList.evts[event] === "undefined") {
if (typeof eventsList.evts[event] === 'undefined') {
eventsList.evts[event] = []
}
addObjectItem(eventsList.evts[event], "fn", { fn: fn })
addObjectItem(eventsList.evts[event], 'fn', { fn: fn })
},
off: (event, fn) => {
removeObjectItem(variablesList.evts[event], "fn", fn)
removeObjectItem(variablesList.evts[event], 'fn', fn)
},
emit: (event, data) => {
if (eventsList.evts[event])
eventsList.evts[event].forEach((element) => {
if (typeof element.fn === "function") element.fn(data)
if (typeof element.fn === 'function') element.fn(data)
})
},
}
Expand Down

0 comments on commit d723801

Please sign in to comment.