1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-27 06:23:53 +01:00

Allow mousewheel tuning in steps of 1 Mhz with ctrl pressed, 0.01 Mhz with shift pressed.

This commit is contained in:
Mark de Bruijn
2024-02-10 12:06:12 +01:00
parent 0453cdc75a
commit 4d4089381e

View File

@@ -16,7 +16,7 @@ const europe_programmes = [
"Oldies Music", "Folk Music", "Documentary", "Alarm Test" "Oldies Music", "Folk Music", "Documentary", "Alarm Test"
]; ];
$(document).ready(function() { $(document).ready(function () {
var canvas = $('#signal-canvas')[0]; var canvas = $('#signal-canvas')[0];
var signalToggle = $("#signal-units-toggle"); var signalToggle = $("#signal-units-toggle");
@@ -28,7 +28,7 @@ $(document).ready(function() {
// Start updating the canvas // Start updating the canvas
initCanvas(); initCanvas();
signalToggle.on("change", function() { signalToggle.on("change", function () {
const signalText = localStorage.getItem('signalUnit'); const signalText = localStorage.getItem('signalUnit');
if (signalText == 'dbuv') { if (signalText == 'dbuv') {
@@ -100,14 +100,27 @@ $(document).ready(function() {
document.onkeydown = checkKey; document.onkeydown = checkKey;
$('#freq-container').on('wheel', function(e) { $('#freq-container').on('wheel keypress', function (e) {
getCurrentFreq();
var delta = e.originalEvent.deltaY; var delta = e.originalEvent.deltaY;
var adjustment = 0;
if (e.shiftKey) {
adjustment = e.altKey ? 1 : 0.01;
} else if (e.ctrlKey) {
adjustment = 1;
} else {
if (delta > 0) { if (delta > 0) {
tuneDown(); tuneDown();
} else { } else {
tuneUp(); tuneUp();
} }
return false; return false;
}
var newFreq = currentFreq + (delta > 0 ? -adjustment : adjustment);
socket.send("T" + (newFreq.toFixed(2) * 1000));
return false;
}); });
var freqUpButton = $('#freq-up')[0]; var freqUpButton = $('#freq-up')[0];
@@ -132,7 +145,7 @@ $(document).ready(function() {
$(rtContainer).on("click", copyRt); $(rtContainer).on("click", copyRt);
$(txContainer).on("click", copyTx); $(txContainer).on("click", copyTx);
$(piCodeContainer).on("click", findOnMaps); $(piCodeContainer).on("click", findOnMaps);
$(freqContainer).on("click", function() { $(freqContainer).on("click", function () {
textInput.focus(); textInput.focus();
}); });
}); });
@@ -141,14 +154,14 @@ function getInitialSettings() {
$.ajax({ $.ajax({
url: './static_data', url: './static_data',
dataType: 'json', dataType: 'json',
success: function(data) { success: function (data) {
// Use the received data (data.qthLatitude, data.qthLongitude) as needed // Use the received data (data.qthLatitude, data.qthLongitude) as needed
localStorage.setItem('qthLatitude', data.qthLatitude); localStorage.setItem('qthLatitude', data.qthLatitude);
localStorage.setItem('qthLongitude', data.qthLongitude); localStorage.setItem('qthLongitude', data.qthLongitude);
localStorage.setItem('audioPort', data.audioPort); localStorage.setItem('audioPort', data.audioPort);
localStorage.setItem('streamEnabled', data.streamEnabled); localStorage.setItem('streamEnabled', data.streamEnabled);
}, },
error: function(error) { error: function (error) {
console.error('Error:', error); console.error('Error:', error);
} }
}); });
@@ -174,7 +187,7 @@ function initCanvas(parsedData) {
function updateCanvas(parsedData, signalChart) { function updateCanvas(parsedData, signalChart) {
const color2 = getComputedStyle(document.documentElement).getPropertyValue('--color-2').trim(); const color2 = getComputedStyle(document.documentElement).getPropertyValue('--color-2').trim();
const color4 = getComputedStyle(document.documentElement).getPropertyValue('--color-4').trim(); const color4 = getComputedStyle(document.documentElement).getPropertyValue('--color-4').trim();
const {context, canvas, maxDataPoints, pointWidth} = signalChart; const { context, canvas, maxDataPoints, pointWidth } = signalChart;
while (data.length >= signalChart.maxDataPoints) { while (data.length >= signalChart.maxDataPoints) {
data.shift(); data.shift();
@@ -187,7 +200,7 @@ function updateCanvas(parsedData, signalChart) {
zoomAvgValue = (zoomMaxValue - zoomMinValue) / 2 + zoomMinValue; zoomAvgValue = (zoomMaxValue - zoomMinValue) / 2 + zoomMinValue;
// Clear the canvas // Clear the canvas
if(context) { if (context) {
context.clearRect(0, 0, canvas.width, canvas.height); context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the signal graph with smooth shifting // Draw the signal graph with smooth shifting
@@ -352,18 +365,18 @@ function tuneUp() {
getCurrentFreq(); getCurrentFreq();
let addVal = 0; let addVal = 0;
if (currentFreq < 0.52) { if (currentFreq < 0.52) {
addVal = 9 - ((currentFreq*1000) % 9); addVal = 9 - ((currentFreq * 1000) % 9);
} else if (currentFreq < 1.71) { } else if (currentFreq < 1.71) {
// TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting // TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting
addVal = 9 - ((currentFreq*1000) % 9); addVal = 9 - ((currentFreq * 1000) % 9);
} else if (currentFreq < 29.6) { } else if (currentFreq < 29.6) {
addVal = 5 - ((currentFreq*1000) % 5); addVal = 5 - ((currentFreq * 1000) % 5);
} else if (currentFreq >= 65.9 && currentFreq < 74) { } else if (currentFreq >= 65.9 && currentFreq < 74) {
addVal = ((currentFreq*1000) % 30 == 20) ? 30 : (20 - ((currentFreq*1000) % 30)); addVal = ((currentFreq * 1000) % 30 == 20) ? 30 : (20 - ((currentFreq * 1000) % 30));
} else { } else {
addVal = 100 - ((currentFreq*1000) % 100); addVal = 100 - ((currentFreq * 1000) % 100);
} }
socket.send("T" + ((currentFreq*1000) + addVal)); socket.send("T" + ((currentFreq * 1000) + addVal));
} }
} }
@@ -372,18 +385,18 @@ function tuneDown() {
getCurrentFreq(); getCurrentFreq();
let subVal = 0; let subVal = 0;
if (currentFreq < 0.52) { if (currentFreq < 0.52) {
subVal = ((currentFreq*1000) % 9 == 0) ? 9 : ((currentFreq*1000) % 9); subVal = ((currentFreq * 1000) % 9 == 0) ? 9 : ((currentFreq * 1000) % 9);
} else if (currentFreq < 1.71) { } else if (currentFreq < 1.71) {
// TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting // TODO: Rework to replace 9 with 9 or 10 based on regionalisation setting
subVal = ((currentFreq*1000) % 9 == 0) ? 9 : ((currentFreq*1000) % 9); subVal = ((currentFreq * 1000) % 9 == 0) ? 9 : ((currentFreq * 1000) % 9);
} else if (currentFreq < 29.6) { } else if (currentFreq < 29.6) {
subVal = ((currentFreq*1000) % 5 == 0) ? 5 : ((currentFreq*1000) % 5); subVal = ((currentFreq * 1000) % 5 == 0) ? 5 : ((currentFreq * 1000) % 5);
} else if (currentFreq >= 65.9 && currentFreq < 74) { } else if (currentFreq >= 65.9 && currentFreq < 74) {
subVal = ((currentFreq*1000) % 30 == 20) ? 30 : (10 + ((currentFreq*1000) % 30)); subVal = ((currentFreq * 1000) % 30 == 20) ? 30 : (10 + ((currentFreq * 1000) % 30));
} else { } else {
subVal = ((currentFreq*1000) % 100 == 0) ? 100 : ((currentFreq*1000) % 100); subVal = ((currentFreq * 1000) % 100 == 0) ? 100 : ((currentFreq * 1000) % 100);
} }
socket.send("T" + ((currentFreq*1000) - subVal)); socket.send("T" + ((currentFreq * 1000) - subVal));
} }
} }
@@ -402,8 +415,8 @@ async function copyPs() {
var signalUnit = $('#signal-units').text(); var signalUnit = $('#signal-units').text();
try { try {
await copyToClipboard(frequency + " - " + pi + " | " + ps + " [" + signal + signalDecimal + " " + signalUnit + "]"); await copyToClipboard(frequency + " - " + pi + " | " + ps + " [" + signal + signalDecimal + " " + signalUnit + "]");
} catch(error) { } catch (error) {
console.error(error); console.error(error);
} }
} }
@@ -418,8 +431,8 @@ async function copyTx() {
const stationErp = $('#data-station-erp').text(); const stationErp = $('#data-station-erp').text();
try { try {
await copyToClipboard(frequency + " - " + pi + " | " + stationName + " [" + stationCity + ", " + stationItu + "] - " + stationDistance + " km | " + stationErp + " kW"); await copyToClipboard(frequency + " - " + pi + " | " + stationName + " [" + stationCity + ", " + stationItu + "] - " + stationDistance + " km | " + stationErp + " kW");
} catch(error) { } catch (error) {
console.error(error); console.error(error);
} }
} }
@@ -430,7 +443,7 @@ async function copyRt() {
try { try {
await copyToClipboard("[0] RT: " + rt0 + "\n[1] RT: " + rt1); await copyToClipboard("[0] RT: " + rt0 + "\n[1] RT: " + rt1);
} catch(error) { } catch (error) {
console.error(error); console.error(error);
} }
} }
@@ -439,9 +452,9 @@ function copyToClipboard(textToCopy) {
// Navigator clipboard api needs a secure context (https) // Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(textToCopy) navigator.clipboard.writeText(textToCopy)
.catch(function(err) { .catch(function (err) {
console.error('Error:', err); console.error('Error:', err);
}); });
} else { } else {
var textArea = $('<textarea></textarea>'); var textArea = $('<textarea></textarea>');
textArea.val(textToCopy); textArea.val(textToCopy);
@@ -515,7 +528,7 @@ function updateDataElements(parsedData) {
: (parsedData.ms === -1 : (parsedData.ms === -1
? "<span class='opacity-half'>M</span><span class='opacity-half'>S</span>" ? "<span class='opacity-half'>M</span><span class='opacity-half'>S</span>"
: "<span class='opacity-full'>M</span><span class='opacity-half'>S</span>" : "<span class='opacity-full'>M</span><span class='opacity-half'>S</span>"
) )
); );
$('.data-pty').html(europe_programmes[parsedData.pty]); $('.data-pty').html(europe_programmes[parsedData.pty]);
$('.data-st').html(parsedData.st === false ? "<span class='text-gray'>ST</span>" : "ST"); $('.data-st').html(parsedData.st === false ? "<span class='text-gray'>ST</span>" : "ST");
@@ -524,7 +537,7 @@ function updateDataElements(parsedData) {
$('.data-flag').html(`<i title="${parsedData.country_name}" class="flag-sm flag-sm-${parsedData.country_iso}"></i>`); $('.data-flag').html(`<i title="${parsedData.country_name}" class="flag-sm flag-sm-${parsedData.country_iso}"></i>`);
$('#data-ant input').val($('#data-ant li[data-value="' + parsedData.ant + '"]').text()); $('#data-ant input').val($('#data-ant li[data-value="' + parsedData.ant + '"]').text());
if(parsedData.txInfo.station.length > 1) { if (parsedData.txInfo.station.length > 1) {
$('#data-station-name').text(decodeURIComponent(parsedData.txInfo.station.replace(/\u009e/g, '\u017E'))); $('#data-station-name').text(decodeURIComponent(parsedData.txInfo.station.replace(/\u009e/g, '\u017E')));
$('#data-station-erp').text(parsedData.txInfo.erp); $('#data-station-erp').text(parsedData.txInfo.erp);
$('#data-station-city').text(parsedData.txInfo.city); $('#data-station-city').text(parsedData.txInfo.city);