From 9b9db240e608a9c8acd7039940a7f7cb0d45a76b Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:06:34 +0000 Subject: [PATCH 1/4] Tune step bug fix and improvements Fix AM rounding error tune problem and change smaller step size for AM vs FM frequencies --- web/js/main.js | 72 ++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index af7bdab..d23143b 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -315,34 +315,26 @@ function getCurrentFreq() { function checkKey(e) { e = e || window.event; - - // Check if any input element is focused using jQuery - if ($('input:focus').length > 0) { - return; // Do nothing if an input is focused - } - + getCurrentFreq(); - + if (socket.readyState === WebSocket.OPEN) { - switch (e.keyCode) { - case 82: // RDS Reset (R key) - socket.send("T" + (currentFreq.toFixed(1) * 1000)); - break; - case 38: - socket.send("T" + ((currentFreq + 0.01).toFixed(2) * 1000)); - break; - case 40: - socket.send("T" + ((currentFreq - 0.01).toFixed(2) * 1000)); - break; - case 37: - tuneDown(); - break; - case 39: - tuneUp(); - break; - default: - // Handle default case if needed - break; + if (e.keyCode == '82') { // RDS Reset (R key) + socket.send("T" + (currentFreq.toFixed(1) * 1000)); + } + if (e.keyCode == '38') { + let smallStep = (currentFreq > 30) ? 10 : 1; + socket.send("T" + (Math.round(currentFreq*1000) + smallStep)); + } + else if (e.keyCode == '40') { + let smallStep = (currentFreq > 30) ? 10 : 1; + socket.send("T" + (Math.round(currentFreq*1000) - smallStep)); + } + else if (e.keyCode == '37') { + tuneDown(); + } + else if (e.keyCode == '39') { + tuneUp(); } } } @@ -352,38 +344,38 @@ function tuneUp() { getCurrentFreq(); let addVal = 0; if (currentFreq < 0.52) { - addVal = 9 - ((currentFreq*1000) % 9); + addVal = 9 - (Math.round(currentFreq*1000) % 9); } else if (currentFreq < 1.71) { // TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting - addVal = 9 - ((currentFreq*1000) % 9); + addVal = 9 - (Math.round(currentFreq*1000) % 9); } else if (currentFreq < 29.6) { - addVal = 5 - ((currentFreq*1000) % 5); + addVal = 5 - (Math.round(currentFreq*1000) % 5); } else if (currentFreq >= 65.9 && currentFreq < 74) { - addVal = ((currentFreq*1000) % 30 == 20) ? 30 : (20 - ((currentFreq*1000) % 30)); + addVal = 30 - ((Math.round(currentFreq*1000) - 65900) % 30); } else { - addVal = 100 - ((currentFreq*1000) % 100); + addVal = 100 - (Math.round(currentFreq*1000) % 100); } - socket.send("T" + ((currentFreq*1000) + addVal)); + socket.send("T" + (Math.round(currentFreq*1000) + addVal)); } } - + function tuneDown() { if (socket.readyState === WebSocket.OPEN) { getCurrentFreq(); let subVal = 0; if (currentFreq < 0.52) { - subVal = ((currentFreq*1000) % 9 == 0) ? 9 : ((currentFreq*1000) % 9); + subVal = (Math.round(currentFreq*1000) % 9 == 0) ? 9 : (Math.round(currentFreq*1000) % 9); } else if (currentFreq < 1.71) { // TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting - subVal = ((currentFreq*1000) % 9 == 0) ? 9 : ((currentFreq*1000) % 9); + subVal = (Math.round(currentFreq*1000) % 9 == 0) ? 9 : (Math.round(currentFreq*1000) % 9); } else if (currentFreq < 29.6) { - subVal = ((currentFreq*1000) % 5 == 0) ? 5 : ((currentFreq*1000) % 5); - } else if (currentFreq >= 65.9 && currentFreq < 74) { - subVal = ((currentFreq*1000) % 30 == 20) ? 30 : (10 + ((currentFreq*1000) % 30)); + subVal = (Math.round(currentFreq*1000) % 5 == 0) ? 5 : (Math.round(currentFreq*1000) % 5); + } else if (currentFreq > 65.9 && currentFreq <= 74) { + subVal = ((Math.round(currentFreq*1000) - 65900) % 30 == 0) ? 30 : ((Math.round(currentFreq*1000) - 65900) % 30); } else { - subVal = ((currentFreq*1000) % 100 == 0) ? 100 : ((currentFreq*1000) % 100); + subVal = (Math.round(currentFreq*1000) % 100 == 0) ? 100 : (Math.round(currentFreq*1000) % 100); } - socket.send("T" + ((currentFreq*1000) - subVal)); + socket.send("T" + (Math.round(currentFreq*1000) - subVal)); } } From d5fb93508a435180073105de61170da61c6b9b7c Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:11:20 +0000 Subject: [PATCH 2/4] Fix checkKey function conflict Merge in changes accidentally reverted by modifications --- web/js/main.js | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index d23143b..4dc4f5b 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -315,26 +315,36 @@ function getCurrentFreq() { function checkKey(e) { e = e || window.event; - + + // Check if any input element is focused using jQuery + if ($('input:focus').length > 0) { + return; // Do nothing if an input is focused + } + getCurrentFreq(); - + if (socket.readyState === WebSocket.OPEN) { - if (e.keyCode == '82') { // RDS Reset (R key) - socket.send("T" + (currentFreq.toFixed(1) * 1000)); - } - if (e.keyCode == '38') { - let smallStep = (currentFreq > 30) ? 10 : 1; - socket.send("T" + (Math.round(currentFreq*1000) + smallStep)); - } - else if (e.keyCode == '40') { - let smallStep = (currentFreq > 30) ? 10 : 1; - socket.send("T" + (Math.round(currentFreq*1000) - smallStep)); - } - else if (e.keyCode == '37') { - tuneDown(); - } - else if (e.keyCode == '39') { - tuneUp(); + switch (e.keyCode) { + case 82: // RDS Reset (R key) + socket.send("T" + (currentFreq.toFixed(1) * 1000)); + break; + case 38: + let smallStep = (currentFreq > 30) ? 10 : 1; + socket.send("T" + (Math.round(currentFreq*1000) + smallStep)); + break; + case 40: + let smallStep = (currentFreq > 30) ? 10 : 1; + socket.send("T" + (Math.round(currentFreq*1000) - smallStep)); + break; + case 37: + tuneDown(); + break; + case 39: + tuneUp(); + break; + default: + // Handle default case if needed + break; } } } From 09822cc285a2b4b019fbeb92b56b4111688ec588 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Fri, 9 Feb 2024 09:26:32 +0000 Subject: [PATCH 3/4] Improve small tune step logic to fix bug Remove variable for small tune step to fix double assignment error. --- web/js/main.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index 4dc4f5b..3082fed 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -329,12 +329,10 @@ function checkKey(e) { socket.send("T" + (currentFreq.toFixed(1) * 1000)); break; case 38: - let smallStep = (currentFreq > 30) ? 10 : 1; - socket.send("T" + (Math.round(currentFreq*1000) + smallStep)); + socket.send("T" + (Math.round(currentFreq*1000) + ((currentFreq > 30) ? 10 : 1))); break; case 40: - let smallStep = (currentFreq > 30) ? 10 : 1; - socket.send("T" + (Math.round(currentFreq*1000) - smallStep)); + socket.send("T" + (Math.round(currentFreq*1000) - ((currentFreq > 30) ? 10 : 1))); break; case 37: tuneDown(); From 4cbc90ad486b132401dfcaba72e990363d1eb41d Mon Sep 17 00:00:00 2001 From: Konrad Kosmatka Date: Sat, 10 Feb 2024 17:56:34 +0100 Subject: [PATCH 4/4] Fix signal level formatting --- web/js/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index af7bdab..9b7f81a 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -496,11 +496,11 @@ function updateSignalUnits(parsedData) { break; } - const integerPart = Math.floor(signalValue); - const decimalPart = (signalValue - integerPart).toFixed(1).slice(1); + const formatted = (Math.round(signalValue * 10) / 10).toFixed(1); + const [integerPart, decimalPart] = formatted.split('.'); $('#data-signal').text(integerPart); - $('#data-signal-decimal').text(decimalPart); + $('#data-signal-decimal').text('.' + decimalPart); } function updateDataElements(parsedData) {