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"
];
$(document).ready(function() {
$(document).ready(function () {
var canvas = $('#signal-canvas')[0];
var signalToggle = $("#signal-units-toggle");
@@ -28,7 +28,7 @@ $(document).ready(function() {
// Start updating the canvas
initCanvas();
signalToggle.on("change", function() {
signalToggle.on("change", function () {
const signalText = localStorage.getItem('signalUnit');
if (signalText == 'dbuv') {
@@ -100,14 +100,27 @@ $(document).ready(function() {
document.onkeydown = checkKey;
$('#freq-container').on('wheel', function(e) {
$('#freq-container').on('wheel keypress', function (e) {
getCurrentFreq();
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) {
tuneDown();
} else {
tuneUp();
}
return false;
}
var newFreq = currentFreq + (delta > 0 ? -adjustment : adjustment);
socket.send("T" + (newFreq.toFixed(2) * 1000));
return false;
});
var freqUpButton = $('#freq-up')[0];
@@ -132,7 +145,7 @@ $(document).ready(function() {
$(rtContainer).on("click", copyRt);
$(txContainer).on("click", copyTx);
$(piCodeContainer).on("click", findOnMaps);
$(freqContainer).on("click", function() {
$(freqContainer).on("click", function () {
textInput.focus();
});
});
@@ -141,14 +154,14 @@ function getInitialSettings() {
$.ajax({
url: './static_data',
dataType: 'json',
success: function(data) {
success: function (data) {
// Use the received data (data.qthLatitude, data.qthLongitude) as needed
localStorage.setItem('qthLatitude', data.qthLatitude);
localStorage.setItem('qthLongitude', data.qthLongitude);
localStorage.setItem('audioPort', data.audioPort);
localStorage.setItem('streamEnabled', data.streamEnabled);
},
error: function(error) {
error: function (error) {
console.error('Error:', error);
}
});
@@ -174,7 +187,7 @@ function initCanvas(parsedData) {
function updateCanvas(parsedData, signalChart) {
const color2 = getComputedStyle(document.documentElement).getPropertyValue('--color-2').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) {
data.shift();
@@ -187,7 +200,7 @@ function updateCanvas(parsedData, signalChart) {
zoomAvgValue = (zoomMaxValue - zoomMinValue) / 2 + zoomMinValue;
// Clear the canvas
if(context) {
if (context) {
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the signal graph with smooth shifting
@@ -352,18 +365,18 @@ function tuneUp() {
getCurrentFreq();
let addVal = 0;
if (currentFreq < 0.52) {
addVal = 9 - ((currentFreq*1000) % 9);
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);
addVal = 9 - ((currentFreq * 1000) % 9);
} else if (currentFreq < 29.6) {
addVal = 5 - ((currentFreq*1000) % 5);
addVal = 5 - ((currentFreq * 1000) % 5);
} 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 {
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();
let subVal = 0;
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) {
// 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) {
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) {
subVal = ((currentFreq*1000) % 30 == 20) ? 30 : (10 + ((currentFreq*1000) % 30));
subVal = ((currentFreq * 1000) % 30 == 20) ? 30 : (10 + ((currentFreq * 1000) % 30));
} 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));
}
}
@@ -403,7 +416,7 @@ async function copyPs() {
try {
await copyToClipboard(frequency + " - " + pi + " | " + ps + " [" + signal + signalDecimal + " " + signalUnit + "]");
} catch(error) {
} catch (error) {
console.error(error);
}
}
@@ -419,7 +432,7 @@ async function copyTx() {
try {
await copyToClipboard(frequency + " - " + pi + " | " + stationName + " [" + stationCity + ", " + stationItu + "] - " + stationDistance + " km | " + stationErp + " kW");
} catch(error) {
} catch (error) {
console.error(error);
}
}
@@ -430,7 +443,7 @@ async function copyRt() {
try {
await copyToClipboard("[0] RT: " + rt0 + "\n[1] RT: " + rt1);
} catch(error) {
} catch (error) {
console.error(error);
}
}
@@ -439,7 +452,7 @@ function copyToClipboard(textToCopy) {
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(textToCopy)
.catch(function(err) {
.catch(function (err) {
console.error('Error:', err);
});
} else {
@@ -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-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-erp').text(parsedData.txInfo.erp);
$('#data-station-city').text(parsedData.txInfo.city);