From ba00fe3efc420108a7eacd744ddd9075c2e97a52 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Dec 2024 19:04:09 +0200 Subject: [PATCH] GrblHal Build date on Troubleshooting tab, and Restore AutoBackups --- app/js/grbl-settings.js | 45 ++++++++++++++++++++++++++++++++++++----- app/js/websocket.js | 8 +++++--- index.js | 15 ++++++++++---- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/app/js/grbl-settings.js b/app/js/grbl-settings.js index 1ba01702..e43a40f9 100644 --- a/app/js/grbl-settings.js +++ b/app/js/grbl-settings.js @@ -36,6 +36,7 @@ function loadGrblBackupFile(f) { checkifchanged(); enableLimits(); // Enable or Disable displayDirInvert(); + $("#grblSettingsAdvTab").click(); } } } @@ -78,6 +79,40 @@ function restoreAutoBackup(index) { console.log('Restoring backup:', selectedBackup); // Call your function to restore the backup here, e.g., update grblParams // Example: grblParams = selectedBackup.grblParams; + + // Retrieve grblParams from the backup + const grblParamsBackup = selectedBackup.grblParams; + + // Iterate through the keys in the grblParams object and apply them using jQuery + for (const key in grblParamsBackup) { + if (grblParamsBackup.hasOwnProperty(key)) { + const paramValue = grblParamsBackup[key]; + const parsedValue = parseFloat(paramValue); + + // Check if the parsed value is a valid number + if (!isNaN(parsedValue)) { + // Update the input field based on the parameter using jQuery + const inputElement = $("#val-" + key.substring(1) + "-input"); + + if (inputElement.length) { + inputElement.val(parsedValue); // Apply the value to the input field + } + } else { + console.warn(`Invalid value for ${key}: ${paramValue}`); + } + + // Optionally, fix or apply any GrblHAL-specific settings + fixGrblHALSettings(key.substring(1)); // Adjust as needed + + // Optionally, other functions you might call for updating the machine state + // Example: checkifchanged(); enableLimits(); displayDirInvert(); + } + } + // Call any post-restoration functions you need (e.g., re-enable limits, etc.) + checkifchanged(); + enableLimits(); + displayDirInvert(); + $("#grblSettingsAdvTab").click(); } @@ -189,8 +224,8 @@ function grblPopulate() {
@@ -521,9 +556,9 @@ function checkifchanged() { (!compareAsNumber && newVal !== oldVal)) { hasChanged = true; - console.log("changed: " + key); - console.log("old: " + oldVal); - console.log("new: " + newVal); + // console.log("changed: " + key); + // console.log("old: " + oldVal); + // console.log("new: " + newVal); if (!$("#val-" + j + "-input").parent().is('td')) { $("#val-" + j + "-input").parent().addClass('alert'); diff --git a/app/js/websocket.js b/app/js/websocket.js index c499a6f9..1b223630 100644 --- a/app/js/websocket.js +++ b/app/js/websocket.js @@ -60,9 +60,7 @@ function showGrbl(bool, firmware) { if (localStorage.getItem('jogOverride')) { jogOverride(localStorage.getItem('jogOverride')) } - if (laststatus !== undefined) { - $("#firmwareversionstatus").html(laststatus.machine.firmware.platform + " " + laststatus.machine.firmware.version); - }; + } function printLogModern(icon, source, string, printLogCls) { @@ -743,6 +741,10 @@ function initSocket() { } + $("#firmwareversionstatus").html(status.machine.firmware.platform + " " + status.machine.firmware.version + " (" + status.machine.firmware.date + ")"); + + + diff --git a/index.js b/index.js index 918978ca..dbc4b299 100644 --- a/index.js +++ b/index.js @@ -1197,10 +1197,18 @@ io.on("connection", function(socket) { // Grbl $I parser if (data.indexOf("[VER:") === 0) { - status.machine.name = data.split(':')[2].split(']')[0].toLowerCase() + // Extracting the full version (1.1f) + const version = data.split(':')[1].split('.')[0] + '.' + data.split(':')[1].split('.')[1]; + // Extracting the date (20240402) + const date = data.split(':')[1].split('.')[2]; + + status.machine.firmware.version = version; + status.machine.firmware.date = date; + io.sockets.emit("status", status); + + status.machine.name = data.split(':')[2].split(']')[0].toLowerCase() io.sockets.emit("machinename", data.split(':')[2].split(']')[0].toLowerCase()); - status.machine.firmware.date = data.split(':')[1].split(".")[2]; } if (data.indexOf("[OPT:") === 0) { @@ -1393,7 +1401,6 @@ io.on("connection", function(socket) { io.sockets.emit('data', output); } } - status.machine.firmware.date = ""; // debug_log("GRBL detected"); // setTimeout(function() { // io.sockets.emit('grbl', status.machine.firmware) @@ -4002,7 +4009,7 @@ async function getSystemInfo() { }, 60000); // 60,000 ms = 1 minute // Log the initial systemInformation object - console.log(JSON.stringify(systemInformation, null, 2)); + debug_log(JSON.stringify(systemInformation, null, 2)); // Return the systemInformation object (if needed for further use) io.sockets.emit("sysinfo", systemInformation);