From 5e5d2e2f72f9c0a0c3fc7f028548b9868e411fb0 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sun, 12 Mar 2023 17:01:04 +0100 Subject: [PATCH 1/3] Fix timezone config parser (#2169) * make sure to parse the whole config line * fix crash on empty timezone parameter --------- Co-authored-by: CaCO3 --- code/components/jomjol_time_sntp/time_sntp.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/components/jomjol_time_sntp/time_sntp.cpp b/code/components/jomjol_time_sntp/time_sntp.cpp index 8a92c2c0..78df9d5b 100644 --- a/code/components/jomjol_time_sntp/time_sntp.cpp +++ b/code/components/jomjol_time_sntp/time_sntp.cpp @@ -175,10 +175,15 @@ bool setupTime() { while (configFile.getNextLine(&line, disabledLine, eof) && !configFile.isNewParagraph(line)) { - splitted = ZerlegeZeile(line); + splitted = ZerlegeZeile(line, "="); if (toUpper(splitted[0]) == "TIMEZONE") { - timeZone = splitted[1]; + if (splitted.size() <= 1) { // parameter part is empty + timeZone = ""; + } + else { + timeZone = splitted[1]; + } } if (toUpper(splitted[0]) == "TIMESERVER") { From ff81fcbd7f30904e9160474a6b442d746381a99e Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sun, 12 Mar 2023 17:03:03 +0100 Subject: [PATCH 2/3] Enhance ROI pages (#2161) * Check if the ROIs are equidistant. Only if not, untick the checkbox * renaming * Check if the ROIs have same y, dy and dx. If so, tick the sync checkbox * only allow editing space when box is checked * fix sync check * show inner frame on all ROIs * cleanup * Check if the ROIs have same dy and dx. If so, tick the sync checkbox * checkbox position * renaming * renaming * show inner frame and cross hairs on all ROIs * update ROIs on ticking checkboxes * show timezone hint * fix deleting last ROI * cleanup --------- Co-authored-by: CaCO3 --- sd-card/html/common.js | 2 +- sd-card/html/edit_analog.html | 81 ++++++++++++++++------ sd-card/html/edit_config_param.html | 1 + sd-card/html/edit_digits.html | 102 +++++++++++++++++++++++----- 4 files changed, 146 insertions(+), 40 deletions(-) diff --git a/sd-card/html/common.js b/sd-card/html/common.js index ba170dee..3c73bb51 100644 --- a/sd-card/html/common.js +++ b/sd-card/html/common.js @@ -1,7 +1,7 @@ /* The UI can also be run locally, but you have to set the IP of your devide accordingly. * And you also might have to disable CORS in your webbrowser! */ -var domainname_for_testing = "192.168.178.62"; +var domainname_for_testing = "192.168.1.153"; diff --git a/sd-card/html/edit_analog.html b/sd-card/html/edit_analog.html index 3c104131..a30bb2a5 100644 --- a/sd-card/html/edit_analog.html +++ b/sd-card/html/edit_analog.html @@ -85,9 +85,6 @@ th, td { Number: @@ -105,8 +102,6 @@ th, td { @@ -120,16 +115,16 @@ th, td { x: Δx: - + y: Δy: - + - + @@ -159,8 +154,8 @@ th, td { cofcat, param, enhanceCon = false; - lockAR = true; - lockSizes = true; + lockAspectRatio = true; + lockSizes = false; domainname = getDomainname(); @@ -222,6 +217,7 @@ function deleteROI(){ aktindex = ROIInfo.length - 1; } UpdateROIs(); + draw(); } function newROI(){ @@ -259,12 +255,13 @@ function moveNext(){ UpdateROIs(); } -function changelockAR(){ - lockAR = document.getElementById("lockAR").checked; +function changelockAspectRatio(){ + lockAspectRatio = document.getElementById("lockAspectRatio").checked; } function changelockSizes(){ lockSizes = document.getElementById("lockSizes").checked; + UpdateROIs(); } function changeCCW(){ @@ -283,7 +280,7 @@ function changeCCW(){ function ChangeSelection(){ aktindex = parseInt(document.getElementById("index").value); -// lockAR = true; +// lockAspectRatio = true; UpdateROIs(); } @@ -317,6 +314,7 @@ function UpdateROIs(_sel){ document.getElementById("newROI").disabled = false; document.getElementById("deleteROI").disabled = true; document.getElementById("index").disabled = true; + document.getElementById("saveroi").disabled = true; document.getElementById("renameROI").disabled = true; document.getElementById("moveNext").disabled = true; document.getElementById("movePrevious").disabled = true; @@ -361,7 +359,7 @@ function UpdateROIs(_sel){ document.getElementById("moveNext").disabled = true; } - document.getElementById("lockAR").checked = lockAR; + document.getElementById("lockAspectRatio").checked = lockAspectRatio; document.getElementById("lockSizes").checked = lockSizes; document.getElementById("refx").value = ROIInfo[aktindex]["x"]; @@ -419,6 +417,29 @@ function UpdateROIs(_sel){ param = getConfigParameters(); cofcat = getConfigCategory(); UpdateNUMBERS(); + + /* Check if the ROIs have same dy and dx. If so, tick the sync checkbox */ + var all_dx_dy_Identical = true; + if (ROIInfo.length > 1) { + for (var i = 1; i < (ROIInfo.length); ++i) { // 2nd .. last ROI + if (parseInt(ROIInfo[i].dx) != parseInt(ROIInfo[0].dx) || + parseInt(ROIInfo[i].dy) != parseInt(ROIInfo[0].dy)) { + all_dx_dy_Identical = false; + break; + } + } + } + + if (all_dx_dy_Identical) { + lockSizes = true; + console.log("All ROI have the same dX and dY, ticking the sync checkbox!"); + document.getElementById("lockSizes").checked = lockSizes; + } + else { + console.log("Not all ROI have the same dX and dY, unticking the sync checkbox!"); + } + + drawImage(); draw(); } @@ -510,11 +531,17 @@ function drawTextBG(context, txt, x, y, padding) { if (typeof ROIInfo === 'undefined') { // During init, ROIInfo is not defined yet return; } + + var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); context.drawImage(imageObj, 0, 0); + if (ROIInfo.length == 0) { + return; + } + context.font = "15px Arial"; context.fillStyle = "red"; context.textAlign = "center"; @@ -540,7 +567,7 @@ function drawTextBG(context, txt, x, y, padding) { { if (_nb != _number) { - lw = 1; + lw = 2; context.lineWidth = lw; context.strokeStyle = "#990000"; var x0 = parseInt(ROIInfo[_nb].x) - parseInt(lw/2); @@ -549,12 +576,24 @@ function drawTextBG(context, txt, x, y, padding) { var dy = parseInt(ROIInfo[_nb].dy) + parseInt(lw); context.strokeRect(x0, y0, dx, dy); drawTextBG(context, ROIInfo[_nb]["name"], x0+dx/2-0.5, y0-13, 5); + + lw = 1; + var x0 = parseInt(ROIInfo[_nb].x) - parseInt(lw/2); + var y0 = parseInt(ROIInfo[_nb].y) - parseInt(lw/2); + var dx = parseInt(ROIInfo[_nb].dx) + parseInt(lw); + var dy = parseInt(ROIInfo[_nb].dy) + parseInt(lw); + context.strokeRect(x0, y0, dx, dy); + context.lineWidth = lw; + context.beginPath(); + context.arc(x0+dx/2, y0+dy/2, dx/2, 0, 2 * Math.PI); + context.moveTo(x0+dx/2, y0); + context.lineTo(x0+dx/2, y0+dy); + context.moveTo(x0, y0+dy/2); + context.lineTo(x0+dx, y0+dy/2); + context.stroke(); } - } - - lw = 4 context.lineWidth = lw; context.strokeStyle = "#FF0000"; @@ -622,7 +661,7 @@ function drawTextBG(context, txt, x, y, padding) { zw = getCoords(this) - if (lockAR) { + if (lockAspectRatio) { rect.h = (e.pageY - zw.top) - rect.startY; rect.w = Math.round(rect.h * ROIInfo[aktindex]["ar"]); } else { @@ -657,7 +696,7 @@ function drawTextBG(context, txt, x, y, padding) { if (!drag) { rect.w = document.getElementById("refdx").value; rect.h = document.getElementById("refdy").value; - if (lockAR) { + if (lockAspectRatio) { rect.w = Math.round(rect.h * ROIInfo[aktindex]["ar"]); document.getElementById("refdx").value = rect.w; } @@ -672,7 +711,7 @@ function drawTextBG(context, txt, x, y, padding) { if (!drag) { rect.w = document.getElementById("refdx").value; rect.h = document.getElementById("refdy").value; - if (lockAR) { + if (lockAspectRatio) { rect.h = Math.round(rect.w / ROIInfo[aktindex]["ar"]); document.getElementById("refdy").value = rect.h; } diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index 0853b0b6..625c8d7f 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -1309,6 +1309,7 @@ textarea { +

Use timezones.html to find your correct settings.

$TOOLTIP_System_TimeZone diff --git a/sd-card/html/edit_digits.html b/sd-card/html/edit_digits.html index b8e8fce8..12b70356 100644 --- a/sd-card/html/edit_digits.html +++ b/sd-card/html/edit_digits.html @@ -81,9 +81,6 @@ th, td { Number: @@ -101,8 +98,6 @@ th, td { @@ -115,7 +110,7 @@ th, td { x: Δx: - + y: @@ -154,8 +149,8 @@ th, td { cofcat, param, enhanceCon = false; - lockAR = true; - lockSizes = true; + lockAspectRatio = true; + lockSizes = false; lockSpaceEquidistant = true; space = 3; domainname = getDomainname(); @@ -269,12 +264,14 @@ function moveNext(){ valuemanualchanged(); } -function changelockAR(){ - lockAR = document.getElementById("lockAR").checked; +function changelockAspectRatio(){ + lockAspectRatio = document.getElementById("lockAspectRatio").checked; } function changelockSizes(){ lockSizes = document.getElementById("lockSizes").checked; + UpdateROIs(); + valuemanualchangedspace(); if (!lockSizes) { firework.launch("For best results it is in most cases advised to keep the y, Δx and Δy identical!", 'warning', 10000); @@ -283,11 +280,18 @@ function changelockSizes(){ function changeLockSpaceEquidistant(){ lockSpaceEquidistant = document.getElementById("lockSpaceEquidistant").checked; + if (!lockSpaceEquidistant) { + document.getElementById("space").disabled = true; + } + else { + document.getElementById("space").disabled = false; + } + UpdateROIs(); } function ChangeSelection(){ aktindex = parseInt(document.getElementById("index").value); -// lockAR = true; +// lockAspectRatio = true; UpdateROIs(); } @@ -367,10 +371,16 @@ function UpdateROIs(_sel){ document.getElementById("moveNext").disabled = true; } - document.getElementById("lockAR").checked = lockAR; + document.getElementById("lockAspectRatio").checked = lockAspectRatio; document.getElementById("lockSizes").checked = lockSizes; document.getElementById("lockSpaceEquidistant").checked = lockSpaceEquidistant; document.getElementById("space").value = space; + if (!lockSpaceEquidistant) { + document.getElementById("space").disabled = true; + } + else { + document.getElementById("space").disabled = false; + } document.getElementById("refx").value = ROIInfo[aktindex]["x"]; document.getElementById("refy").value = ROIInfo[aktindex]["y"]; @@ -423,8 +433,53 @@ function UpdateROIs(_sel){ cofcat = getConfigCategory(); UpdateNUMBERS(); - space = ROIInfo[1].x - parseInt(ROIInfo[0].x) - parseInt(ROIInfo[0].dx); - document.getElementById("space").value = space; + + /* Check if the ROIs are equidistant. Only if not, untick the checkbox */ + if (ROIInfo.length > 1) { + var distanceROI0_to_ROI1 = parseInt(ROIInfo[1].x) - (parseInt(ROIInfo[0].x) + parseInt(ROIInfo[0].dx)); // Distance between 1st and 2nd ROI + //console.log("0->1: " + distanceROI0_to_ROI1); + for (var i = 1; i < (ROIInfo.length - 1); ++i) { // 2nd .. 2nd-last ROI + //console.log(i + "->" + i+1 + ": " + (parseInt(ROIInfo[i+1].x) - (parseInt(ROIInfo[i].x) + parseInt(ROIInfo[i].dx)))); + if (distanceROI0_to_ROI1 != (parseInt(ROIInfo[i+1].x) - (parseInt(ROIInfo[i].x) + parseInt(ROIInfo[i].dx)))) { + console.log("Not equidistant, unticking the checkbox!"); + lockSpaceEquidistant = false; + document.getElementById("lockSpaceEquidistant").checked = lockSpaceEquidistant; + if (!lockSpaceEquidistant) { + document.getElementById("space").disabled = true; + } + else { + document.getElementById("space").disabled = false; + } + break; + } + } + } + /* Check if the ROIs have same y, dy and dx. If so, tick the sync checkbox */ + var all_y_dx_dy_Identical = true; + if (ROIInfo.length > 1) { + for (var i = 1; i < (ROIInfo.length); ++i) { // 2nd .. last ROI + if (parseInt(ROIInfo[i].y) != parseInt(ROIInfo[0].y) || + parseInt(ROIInfo[i].dx) != parseInt(ROIInfo[0].dx) || + parseInt(ROIInfo[i].dy) != parseInt(ROIInfo[0].dy)) { + all_y_dx_dy_Identical = false; + break; + } + } + } + + if (all_y_dx_dy_Identical) { + lockSizes = true; + console.log("All ROI have the same Y, dX and dY, ticking the sync checkbox!"); + document.getElementById("lockSizes").checked = lockSizes; + } + else { + console.log("Not all ROI have the same Y, dX and dY, unticking the sync checkbox!"); + } + + if (ROIInfo.length > 1) { + space = ROIInfo[1].x - parseInt(ROIInfo[0].x) - parseInt(ROIInfo[0].dx); + document.getElementById("space").value = space; + } drawImage(); draw(); @@ -558,8 +613,19 @@ function draw() { var dy = parseInt(ROIInfo[_nb].dy) + parseInt(lw); context.strokeRect(x0, y0, dx, dy); drawTextBG(context, ROIInfo[_nb]["name"], x0+dx/2, y0-12, 5); - } + lw = 1 + var x0 = parseInt(ROIInfo[_nb].x) - parseInt(lw/2); + var y0 = parseInt(ROIInfo[_nb].y) - parseInt(lw/2); + var dx = parseInt(ROIInfo[_nb].dx) + parseInt(lw); + var dy = parseInt(ROIInfo[_nb].dy) + parseInt(lw); + context.lineWidth = lw; + context.beginPath(); + context.moveTo(x0, y0+dy/2); + context.lineTo(x0+dx, y0+dy/2); + context.stroke(); + context.strokeRect(x0+dx*0.2, y0+dy*0.2, dx*0.6, dy*0.6); + } } lw = 4 @@ -635,7 +701,7 @@ function draw() { return; } - if (lockAR) { + if (lockAspectRatio) { rect.h = (e.pageY - zw.top) - rect.startY; rect.w = Math.round(rect.h * ROIInfo[aktindex]["ar"]); } else { @@ -675,7 +741,7 @@ function draw() { rect.w = document.getElementById("refdx").value; rect.h = document.getElementById("refdy").value; - if (lockAR) { + if (lockAspectRatio) { rect.w = Math.round(rect.h * ROIInfo[aktindex]["ar"]); document.getElementById("refdx").value = rect.w; } @@ -700,7 +766,7 @@ function draw() { rect.w = document.getElementById("refdx").value; rect.h = document.getElementById("refdy").value; - if (lockAR) { + if (lockAspectRatio) { rect.h = Math.round(rect.w / ROIInfo[aktindex]["ar"]); document.getElementById("refdy").value = rect.h; } From 4dd41c486f8828777e0cc7bcdabd29210443b5ca Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sun, 12 Mar 2023 21:30:23 +0100 Subject: [PATCH 3/3] restart timeout on progress, catch error (#2170) * restart timeout on progress, catch error * . --------- Co-authored-by: CaCO3 --- sd-card/html/backup.html | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sd-card/html/backup.html b/sd-card/html/backup.html index 260354d9..c55c3d3d 100644 --- a/sd-card/html/backup.html +++ b/sd-card/html/backup.html @@ -122,13 +122,13 @@ function fetchFiles(urls, filesData, index, retry, zipFilename) { xhr.timeout = 5000; // time in milliseconds } else if (retry == 2) { // longer timeout - xhr.timeout = 20000; // time in milliseconds + xhr.timeout = 10000; // time in milliseconds } else if (retry == 3) { // longer timeout - xhr.timeout = 30000; // time in milliseconds + xhr.timeout = 20000; // time in milliseconds } else { // very long timeout - xhr.timeout = 60000; // time in milliseconds + xhr.timeout = 30000; // time in milliseconds } xhr.onload = () => { // Request finished @@ -146,6 +146,20 @@ function fetchFiles(urls, filesData, index, retry, zipFilename) { } }; + xhr.onprogress = (e) => { // XMLHttpRequest progress ... extend timeout + xhr.timeout = xhr.timeout + 500; + }; + + xhr.onerror = (e) => { // XMLHttpRequest error loading + console.log("Error on fetching " + url + "!"); + if (retry > 5) { + setStatus("Backup failed, please restart the device and try again!"); + } + else { + fetchFiles(urls, filesData, index, retry+1, zipFilename); + } + }; + xhr.ontimeout = (e) => { // XMLHttpRequest timed out console.log("Timeout on fetching " + url + "!"); if (retry > 5) {