From a4e6a71dbdfc4598434fa5ad71f1ba38e41abfe4 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:44:41 +0000 Subject: [PATCH] Logic for AM and OIRT steps Up and down tuning steps in 9kHz for MW/LW, 5kHz for SW and 30kHz for OIRT FM --- web/js/main.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index 780929e..c44fee8 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -312,10 +312,10 @@ function checkKey(e) { socket.send("T" + ((currentFreq - 0.01).toFixed(2) * 1000)); } else if (e.keyCode == '37') { - socket.send("T" + ((currentFreq - 0.10).toFixed(1) * 1000)); + tuneDown(); } else if (e.keyCode == '39') { - socket.send("T" + ((currentFreq + 0.10).toFixed(1) * 1000)); + tuneUp(); } } } @@ -323,14 +323,40 @@ function checkKey(e) { function tuneUp() { if (socket.readyState === WebSocket.OPEN) { getCurrentFreq(); - socket.send("T" + ((currentFreq + 0.10).toFixed(1) * 1000)); + let addVal = 0; + if (currentFreq < 0.52) { + addVal = 9 - ((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); + } else if (currentFreq < 29.6) { + addVal = 5 - ((currentFreq*1000) % 5); + } else if (currentFreq >= 65.9 && currentFreq < 74) { + addVal = ((currentFreq*1000) % 30 == 20) ? 30 : (20 - ((currentFreq*1000) % 30)); + } else { + addVal = 100 - ((currentFreq*1000) % 100); + } + socket.send("T" + ((currentFreq*1000) + addVal)); } } - + function tuneDown() { if (socket.readyState === WebSocket.OPEN) { getCurrentFreq(); - socket.send("T" + ((currentFreq - 0.10).toFixed(1) * 1000)); + let subVal = 0; + if (currentFreq < 0.52) { + subVal = ((currentFreq*1000) % 9 == 0) ? 9 : ((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); + } 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)); + } else { + subVal = ((currentFreq*1000) % 100 == 0) ? 100 : ((currentFreq*1000) % 100); + } + socket.send("T" + ((currentFreq*1000) - subVal)); } }