From 1794682a6ddc71c7fdfcf85655cfde56b65b662e Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:18:54 +0800 Subject: [PATCH] Fix some glitches and typos Comment several console.log to clean console output --- src/components/Helpers/filters.js | 4 +- src/components/Modal/logginModal.js | 4 +- src/components/Panels/Status.js | 16 ++--- src/contexts/DatasContext.js | 14 ++-- src/targets/CNC/Controls/QuickStopButton.js | 2 +- .../CNC/GRBL/Controls/BackgroundContainer.js | 2 +- src/targets/FLASH-source.js | 2 +- src/targets/Printer3D/Marlin/FLASH-source.js | 2 +- src/targets/Printer3D/Marlin/SD-source.js | 2 +- src/targets/Printer3D/Marlin/TargetContext.js | 3 +- src/targets/Printer3D/Marlin/filters.js | 69 ++++++++++++------- .../Printer3D/Smoothieware/MachineSettings.js | 4 +- .../Printer3D/Smoothieware/SD-source.js | 2 +- .../Printer3D/Smoothieware/SDEXT-source.js | 2 +- .../Printer3D/Smoothieware/TargetContext.js | 4 +- src/targets/Printer3D/translations/en.json | 2 +- 16 files changed, 73 insertions(+), 61 deletions(-) diff --git a/src/components/Helpers/filters.js b/src/components/Helpers/filters.js index bb6c35a30..7dcc9e9f9 100644 --- a/src/components/Helpers/filters.js +++ b/src/components/Helpers/filters.js @@ -22,13 +22,13 @@ import { compareStrings } from './strings' //sort files alphabeticaly then folders alphabeticaly const sortedFilesList = (filesList, alphabeticaly) => { - console.log('Sorting files list', alphabeticaly) + //console.log('Sorting files list', alphabeticaly) if (typeof filesList == 'undefined') return [] if (typeof alphabeticaly == 'undefined') { alphabeticaly = true } if (alphabeticaly) { - console.log('Sorting alphabetically') + //console.log('Sorting alphabetically') filesList.sort(function (a, b) { return compareStrings(a.name, b.name) }) diff --git a/src/components/Modal/logginModal.js b/src/components/Modal/logginModal.js index 6d31cc187..f26b3978b 100644 --- a/src/components/Modal/logginModal.js +++ b/src/components/Modal/logginModal.js @@ -44,12 +44,12 @@ const showLogin = () => { if (val) passwordValue.current = val.trim() } const clickLogin = () => { - console.log( + /* console.log( "login :", loginValue.current, " password:", passwordValue.current - ) + )*/ useUiContextFn.haptic() const formData = new FormData() formData.append("SUBMIT", "YES") diff --git a/src/components/Panels/Status.js b/src/components/Panels/Status.js index 5dbff3a94..9ef6ba021 100644 --- a/src/components/Panels/Status.js +++ b/src/components/Panels/Status.js @@ -31,6 +31,7 @@ const TimeControl = ({ label, time }) => { time.hour = time.hour ? time.hour.toString() : '0' time.min = time.min ? time.min.toString() : '0' time.sec = time.sec ? time.sec.toString() : '0' + if (time.day == 'Infinity') return null return (
{T(label)}:
@@ -70,6 +71,10 @@ const TimeControl = ({ label, time }) => { const StatusControls = () => { const { streamStatus, status } = useTargetContext() if (!useUiContextFn.getValue('showstatuspanel')) return null + console.log("streamStatus") + console.log(streamStatus) + console.log( "status") + console.log( status) return ( {streamStatus && @@ -154,17 +159,6 @@ const StatusControls = () => {
)} - {status.state && status.state.length > 0 && ( -
-
-
{T('P67')}
-
{status.state}
-
-
- )} ) } diff --git a/src/contexts/DatasContext.js b/src/contexts/DatasContext.js index a13f0511f..26f6df3c9 100644 --- a/src/contexts/DatasContext.js +++ b/src/contexts/DatasContext.js @@ -44,13 +44,13 @@ const DatasContextProvider = ({ children }) => { } const addTerminalContent = (element) => { - console.log(element) - console.log( - 'isVerbose', - terminalBuffer.current.length, - 'Quiet', - terminalBufferQuiet.current.length - ) + //console.log(element) + //console.log( + // 'isVerbose', + // terminalBuffer.current.length, + // 'Quiet', + // terminalBufferQuiet.current.length + //) const newData = {} newData.verbose = limitArr( [...terminalBuffer.current, element], diff --git a/src/targets/CNC/Controls/QuickStopButton.js b/src/targets/CNC/Controls/QuickStopButton.js index f54e30dfe..7b5090074 100644 --- a/src/targets/CNC/Controls/QuickStopButton.js +++ b/src/targets/CNC/Controls/QuickStopButton.js @@ -63,7 +63,7 @@ const QuickStopButton = () => { const cmds = useUiContextFn.getValue("emergencystop").split(";") cmds.forEach((cmd) => { SendCommand(cmd) - console.log(cmd) + // console.log(cmd) }) }} /> diff --git a/src/targets/CNC/GRBL/Controls/BackgroundContainer.js b/src/targets/CNC/GRBL/Controls/BackgroundContainer.js index 519fd8a1c..0b077d853 100644 --- a/src/targets/CNC/GRBL/Controls/BackgroundContainer.js +++ b/src/targets/CNC/GRBL/Controls/BackgroundContainer.js @@ -27,7 +27,7 @@ const BackgroundContainer = () => { const { alarmCode, errorCode, status } = useTargetContext() const { toasts } = useUiContext() useEffect(() => { - console.log(status) + //console.log(status) if (alarmCode != 0 || errorCode != 0) { toasts.addToast({ diff --git a/src/targets/FLASH-source.js b/src/targets/FLASH-source.js index cf04468f1..554bbe47f 100644 --- a/src/targets/FLASH-source.js +++ b/src/targets/FLASH-source.js @@ -100,7 +100,7 @@ const commands = { (path == '/' ? '' : '/') + filename ).replaceAll('//', '/') - console.log('Upath:', upath) + //console.log('Upath:', upath) return { type: 'url', url: upath, diff --git a/src/targets/Printer3D/Marlin/FLASH-source.js b/src/targets/Printer3D/Marlin/FLASH-source.js index 2ec7d90be..3272d0367 100644 --- a/src/targets/Printer3D/Marlin/FLASH-source.js +++ b/src/targets/Printer3D/Marlin/FLASH-source.js @@ -106,7 +106,7 @@ const commands = { (path == '/' ? '' : '/') + filename ).replaceAll('//', '/') - console.log('Upath:', upath) + //console.log('Upath:', upath) return { type: 'url', url: upath, diff --git a/src/targets/Printer3D/Marlin/SD-source.js b/src/targets/Printer3D/Marlin/SD-source.js index b46c7f0ed..e9034edbc 100644 --- a/src/targets/Printer3D/Marlin/SD-source.js +++ b/src/targets/Printer3D/Marlin/SD-source.js @@ -119,7 +119,7 @@ const commands = { } }, filterResult: (data, path) => { - console.log(data) + //console.log(data) const res = {} res.files = sortedFilesList(filterResultFiles(data.files, path), false) res.status = formatStatus(data.status) diff --git a/src/targets/Printer3D/Marlin/TargetContext.js b/src/targets/Printer3D/Marlin/TargetContext.js index ea8068ded..3da364cbe 100644 --- a/src/targets/Printer3D/Marlin/TargetContext.js +++ b/src/targets/Printer3D/Marlin/TargetContext.js @@ -251,6 +251,7 @@ const TargetContextProvider = ({ children }) => { if (type === 'response') { //check if the response is a command answer if (data[0] === '{') { + console.log('response', data) if (isStreamingStatus(data)) { setStatus({ printState: null }) const preStatus = getStreamingStatus(data) @@ -415,7 +416,7 @@ const TargetContextProvider = ({ children }) => { fanSpeed: { current: fanSpeed, set: (index, value) => { - console.log('set fan speed', index, '=', value) + //console.log('set fan speed', index, '=', value) fansSpeed[index] = value setFanSpeed(fanSpeed) }, diff --git a/src/targets/Printer3D/Marlin/filters.js b/src/targets/Printer3D/Marlin/filters.js index c94f76eb6..fbb68cf3d 100644 --- a/src/targets/Printer3D/Marlin/filters.js +++ b/src/targets/Printer3D/Marlin/filters.js @@ -17,21 +17,19 @@ 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 { useSettingsContextFn } from "../../../contexts" - +import { h } from 'preact' +import { useSettingsContextFn } from '../../../contexts' //////////////////////////////////////////////////////// // // ok acknowledge const isOk = (str) => { - if (str.startsWith("ok") && !str.startsWith("ok T:")) { + if (str.startsWith('ok') && !str.startsWith('ok T:')) { return true } return false } - //////////////////////////////////////////////////////// // //Temperatures @@ -49,7 +47,7 @@ const isTemperatures = (str) => { } const getTemperatures = (str) => { - const isMKS = useSettingsContextFn.getValue("SerialProtocol") == "MKS" + const isMKS = useSettingsContextFn.getValue('SerialProtocol') == 'MKS' let result = null const response = { T: [], //0->8 T0->T8 Extruders @@ -71,7 +69,7 @@ const getTemperatures = (str) => { while ((result = regex_search.exec(str)) !== null) { //MKS always have T0,T1,B even no second extruder is present neither bed if (!(isMKS && parseFloat(result[3]) == 0)) - response[result[1]][result[2] == "" ? 0 : result[2]] = { + response[result[1]][result[2] == '' ? 0 : result[2]] = { value: result[3], target: result[4], } @@ -109,7 +107,8 @@ const isPrintStatus = (str) => { let result = null const reg_search1 = /(Not\sSD\sprinting|Done\sprinting\sfile)/ const reg_search2 = /SD\sprinting\sbyte\s([0-9]*)\/([0-9]*)/ - const reg_search3 =/echo:\sM73\sProgress:\s+([0-9.]*)%;\sTime\sleft:\s([0-9]*)m;\sChange:\s([0-9]*)m;/ + const reg_search3 = + /echo:\sM73\sProgress:\s+([0-9.]*)%;\sTime\sleft:\s([0-9]*)m;\sChange:\s([0-9]*)m;/ if ((result = reg_search1.exec(str)) !== null) { return true } @@ -119,7 +118,7 @@ const isPrintStatus = (str) => { if ((result = reg_search3.exec(str)) !== null) { return true } - if (str.startsWith("echo:Print time:")) { + if (str.startsWith('echo:Print time:')) { return true } return false @@ -129,17 +128,18 @@ const getPrintStatus = (str) => { let result = null const reg_search1 = /(Not\sSD\sprinting|Done\sprinting\sfile)/ const reg_search2 = /SD\sprinting\sbyte\s([0-9]*)\/([0-9]*)/ - const reg_search3 =/echo:\sM73\sProgress:\s+([0-9.]*)%;\sTime\sleft:\s([0-9]*)m;\sChange:\s([0-9]*)m;/ + const reg_search3 = + /echo:\sM73\sProgress:\s+([0-9.]*)%;\sTime\sleft:\s([0-9]*)m;\sChange:\s([0-9]*)m;/ if ((result = reg_search1.exec(str)) !== null) { return { status: result[1], printing: false, - progress: result[1].startsWith("Done") ? 100 : 0, + progress: result[1].startsWith('Done') ? 100 : 0, } } if ((result = reg_search2.exec(str)) !== null) { return { - status: "Printing", + status: 'Printing', printing: true, progress: ( (100 * parseFloat(result[1])) / @@ -150,12 +150,17 @@ const getPrintStatus = (str) => { if ((result = reg_search3.exec(str)) !== null) { let progress = parseFloat(result[1]) return { - status: (progress === 100) ? "Done" : ((progress === 0) ? "Not printing" : `Printing: ${result[2]}m remaining`), - printing: (!(progress === 100 || progress === 0)), + status: + progress === 100 + ? 'Done' + : progress === 0 + ? 'Not printing' + : `Printing: ${result[2]}m remaining`, + printing: !(progress === 100 || progress === 0), progress: progress.toFixed(2), } } - if (str.startsWith("echo:Print time:")) { + if (str.startsWith('echo:Print time:')) { const regex_search = /echo:Print time:\s((?[0-9]*)y\s)*((?[0-9]*)d\s)*((?[0-9]*)h\s)*((?[0-9]*)m\s)*((?[0-9]*)s)/ result = regex_search.exec(str) @@ -171,7 +176,7 @@ const getPrintStatus = (str) => { }, {}) return { time: printTime, printing: isprinting } } - return { status: "Unknown", printing: false, progress: 0 } + return { status: 'Unknown', printing: false, progress: 0 } } //////////////////////////////////////////////////////// @@ -193,7 +198,7 @@ const getPrintFileName = (str) => { if ((result = reg_search1.exec(str)) !== null) { return result[1] } - return "Unknown" + return 'Unknown' } //////////////////////////////////////////////////////// @@ -222,7 +227,7 @@ const getStatus = (str) => { if ((result = reg_search2.exec(str)) !== null) { return result[1] } - return "Unknown" + return 'Unknown' } //////////////////////////////////////////////////////// @@ -263,7 +268,10 @@ const getFanSpeed = (str) => { let result = null const reg_search1 = /M106\sP([0-9]+)\sS([0-9]+)/ if ((result = reg_search1.exec(str)) !== null) { - return { index: parseInt(result[1]), value: (result[2]/255.0 * 100.0).toFixed(2) } + return { + index: parseInt(result[1]), + value: ((result[2] / 255.0) * 100.0).toFixed(2), + } } return null } @@ -298,7 +306,7 @@ const getFeedRate = (str) => { //... const isPrinterCapability = (str) => { const reg_search1 = /^Cap:([^:]+):[0-1]$/ - if (str.startsWith("FIRMWARE_NAME:") || reg_search1.test(str)) { + if (str.startsWith('FIRMWARE_NAME:') || reg_search1.test(str)) { return true } return false @@ -310,7 +318,7 @@ const getPrinterCapability = (str) => { const reg_search1 = /^Cap:(?[^:]+):(?[0-1])$/ const reg_search2 = /^FIRMWARE_NAME:(?[^\(]+)\s\((?[^\)]*)\)\sSOURCE_CODE_URL:(?.+?(?=\sPROTOCOL_VERSION))\sPROTOCOL_VERSION:(?.+?(?=\sMACHINE_TYPE))\sMACHINE_TYPE:(?.+?(?=\sEXTRUDER_COUNT))\sEXTRUDER_COUNT:(?.+?(?=\sUUID))\sUUID:(?.+)/ - if (str.startsWith("FIRMWARE_NAME:")) { + if (str.startsWith('FIRMWARE_NAME:')) { if ((result = reg_search2.exec(str)) !== null) { Object.keys(result.groups).forEach((key) => { res.push({ @@ -320,8 +328,8 @@ const getPrinterCapability = (str) => { }) } else { res.push({ - name: "FIRMWARE_NAME", - value: str.split(":")[1].split(" "), + name: 'FIRMWARE_NAME', + value: str.split(':')[1].split(' '), }) } } else if ((result = reg_search1.exec(str)) !== null) { @@ -334,12 +342,12 @@ const getPrinterCapability = (str) => { // //Sensor const isSensor = (str) => { - return str.startsWith("SENSOR:") + return str.startsWith('SENSOR:') } const getSensor = (str) => { const result = [] - const data = " " + str.substring(7) + const data = ' ' + str.substring(7) let res = null const reg_search = /\s(?[^\[]+)\[(?[^\]]+)\]/g while ((res = reg_search.exec(data))) { @@ -352,16 +360,25 @@ const getSensor = (str) => { // // Streaming status const isStreamingStatus = (str) => { + console.log('isStreamingStatus', str) try { const res = JSON.parse(str) - if (res.cmd == "701" && typeof res.data != "undefined") return true + if (res.cmd == '701' && typeof res.data != 'undefined') { + return true + } else { + console.log('isStreamingStatus is not streamining status', str) + return false + } } catch (e) { + console.log('isStreamingStatus is not streamining status because parsing error', e) return false } } const getStreamingStatus = (str) => { + console.log('getStreamingStatus', str) const res = JSON.parse(str) + console.log('getStreamingStatus', res) if (res.data.status) return res.data return { status: res.data } } diff --git a/src/targets/Printer3D/Smoothieware/MachineSettings.js b/src/targets/Printer3D/Smoothieware/MachineSettings.js index 67e42a40d..d658af207 100644 --- a/src/targets/Printer3D/Smoothieware/MachineSettings.js +++ b/src/targets/Printer3D/Smoothieware/MachineSettings.js @@ -83,7 +83,7 @@ const MachineSettings = () => { configSelected ? "configset" : "overrideset", entry ) - console.log(cmd) + //console.log(cmd) createNewRequest( espHttpURL("command", { cmd }), { method: "GET", id: "saveMachineSetting" }, @@ -162,7 +162,7 @@ const MachineSettings = () => { } const saveSettings = () => { - console.log("Save settings") + //console.log("Save settings") machineSettings.totalToSave = 0 machineSettings.toSave = [] const settings = configSelected diff --git a/src/targets/Printer3D/Smoothieware/SD-source.js b/src/targets/Printer3D/Smoothieware/SD-source.js index 7a0976e64..f0d6abbfb 100644 --- a/src/targets/Printer3D/Smoothieware/SD-source.js +++ b/src/targets/Printer3D/Smoothieware/SD-source.js @@ -82,7 +82,7 @@ const capabilities = { const commands = { list: (path, filename) => { - console.log("path: ", path) + //console.log("path: ", path) const spath = (path + (path == '/' ? '' : '/')).replaceAll('//', '/') const cmd = "echo BeginFiles;"+useUiContextFn.getValue('sdlistcmd').replace("#",spath).replaceAll('//', '/')+";echo EndFiles" return { diff --git a/src/targets/Printer3D/Smoothieware/SDEXT-source.js b/src/targets/Printer3D/Smoothieware/SDEXT-source.js index 15d064705..c02c8242f 100644 --- a/src/targets/Printer3D/Smoothieware/SDEXT-source.js +++ b/src/targets/Printer3D/Smoothieware/SDEXT-source.js @@ -83,7 +83,7 @@ const capabilities = { const commands = { list: (path, filename) => { - console.log("path: ", path) + //console.log("path: ", path) const spath = (path + (path == '/' ? '' : '/')).replaceAll('//', '/') const cmd = "echo BeginFiles;"+useUiContextFn.getValue('sdextlistcmd').replace("#",spath).replaceAll('//', '/')+";echo EndFiles" return { diff --git a/src/targets/Printer3D/Smoothieware/TargetContext.js b/src/targets/Printer3D/Smoothieware/TargetContext.js index 9ad3b60ff..965cad89b 100644 --- a/src/targets/Printer3D/Smoothieware/TargetContext.js +++ b/src/targets/Printer3D/Smoothieware/TargetContext.js @@ -190,7 +190,7 @@ const TargetContextProvider = ({ children }) => { value: cap.value, }) }) - console.log(printerCapabilities) + //console.log(printerCapabilities) } } else if (type === "core") { if (isSensor(data)) { @@ -306,7 +306,7 @@ const TargetContextProvider = ({ children }) => { fanSpeed: { current: fanSpeed, set: (index, value) => { - console.log("set fan speed", index, "=", value) + //console.log("set fan speed", index, "=", value) fansSpeed[index] = value setFanSpeed(fanSpeed) }, diff --git a/src/targets/Printer3D/translations/en.json b/src/targets/Printer3D/translations/en.json index 5bbdaaef6..b5122f169 100644 --- a/src/targets/Printer3D/translations/en.json +++ b/src/targets/Printer3D/translations/en.json @@ -60,7 +60,7 @@ "P65": "Move X to", "P66": "Move Y to", "P67": "Printer status", - "P68": "", + "P68": "Streaming status", "P69": "", "P70": "", "P71": "t",