[feat](trx-frontend-http): add editable SDR bandwidth control
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -888,8 +888,7 @@ function render(update) {
|
|||||||
// Sync filter state (SDR backends only)
|
// Sync filter state (SDR backends only)
|
||||||
if (update.filter && typeof update.filter.bandwidth_hz === "number") {
|
if (update.filter && typeof update.filter.bandwidth_hz === "number") {
|
||||||
currentBandwidthHz = update.filter.bandwidth_hz;
|
currentBandwidthHz = update.filter.bandwidth_hz;
|
||||||
const bwLabel = document.getElementById("spectrum-bw-label");
|
syncBandwidthInput(currentBandwidthHz);
|
||||||
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(currentBandwidthHz);
|
|
||||||
}
|
}
|
||||||
if (update.status && update.status.freq && typeof update.status.freq.hz === "number") {
|
if (update.status && update.status.freq && typeof update.status.freq.hz === "number") {
|
||||||
lastFreqHz = update.status.freq.hz;
|
lastFreqHz = update.status.freq.hz;
|
||||||
@@ -1544,7 +1543,7 @@ const MODE_BW_DEFAULTS = {
|
|||||||
USB: [2_700, 300, 6_000, 100],
|
USB: [2_700, 300, 6_000, 100],
|
||||||
AM: [6_000, 500, 15_000, 500],
|
AM: [6_000, 500, 15_000, 500],
|
||||||
FM: [12_500, 2_500, 25_000, 500],
|
FM: [12_500, 2_500, 25_000, 500],
|
||||||
WFM: [75_000, 50_000,300_000,5_000],
|
WFM: [180_000, 50_000,300_000,5_000],
|
||||||
DIG: [3_000, 300, 6_000, 100],
|
DIG: [3_000, 300, 6_000, 100],
|
||||||
PKT: [3_000, 300, 25_000, 100],
|
PKT: [3_000, 300, 25_000, 100],
|
||||||
};
|
};
|
||||||
@@ -1561,18 +1560,48 @@ function formatBwLabel(hz) {
|
|||||||
|
|
||||||
// Current receive bandwidth (Hz) — updated by server sync and BW drag.
|
// Current receive bandwidth (Hz) — updated by server sync and BW drag.
|
||||||
let currentBandwidthHz = 3_000;
|
let currentBandwidthHz = 3_000;
|
||||||
|
const spectrumBwInput = document.getElementById("spectrum-bw-input");
|
||||||
|
|
||||||
|
function syncBandwidthInput(hz) {
|
||||||
|
if (!spectrumBwInput || !Number.isFinite(hz) || hz <= 0) return;
|
||||||
|
spectrumBwInput.value = String(Math.round(hz));
|
||||||
|
}
|
||||||
|
|
||||||
// Apply mode-specific BW default and optionally push to server.
|
// Apply mode-specific BW default and optionally push to server.
|
||||||
async function applyBwDefaultForMode(mode, sendToServer) {
|
async function applyBwDefaultForMode(mode, sendToServer) {
|
||||||
const [def] = mwDefaultsForMode(mode);
|
const [def] = mwDefaultsForMode(mode);
|
||||||
currentBandwidthHz = def;
|
currentBandwidthHz = def;
|
||||||
const bwLabel = document.getElementById("spectrum-bw-label");
|
syncBandwidthInput(def);
|
||||||
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(def);
|
|
||||||
if (sendToServer) {
|
if (sendToServer) {
|
||||||
try { await postPath(`/set_bandwidth?hz=${def}`); } catch (_) {}
|
try { await postPath(`/set_bandwidth?hz=${def}`); } catch (_) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function applyBandwidthFromInput() {
|
||||||
|
if (!spectrumBwInput) return;
|
||||||
|
const [, minBw, maxBw] = mwDefaultsForMode(modeEl ? modeEl.value : "USB");
|
||||||
|
const next = Math.round(Number(spectrumBwInput.value));
|
||||||
|
if (!Number.isFinite(next) || next <= 0) {
|
||||||
|
syncBandwidthInput(currentBandwidthHz);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const clamped = Math.max(minBw, Math.min(maxBw, next));
|
||||||
|
currentBandwidthHz = clamped;
|
||||||
|
syncBandwidthInput(clamped);
|
||||||
|
if (lastSpectrumData) drawSpectrum(lastSpectrumData);
|
||||||
|
try { await postPath(`/set_bandwidth?hz=${clamped}`); } catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spectrumBwInput) {
|
||||||
|
spectrumBwInput.addEventListener("change", () => { applyBandwidthFromInput(); });
|
||||||
|
spectrumBwInput.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
applyBandwidthFromInput();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// --- Tab navigation ---
|
// --- Tab navigation ---
|
||||||
document.querySelector(".tab-bar").addEventListener("click", (e) => {
|
document.querySelector(".tab-bar").addEventListener("click", (e) => {
|
||||||
const btn = e.target.closest(".tab[data-tab]");
|
const btn = e.target.closest(".tab[data-tab]");
|
||||||
@@ -2827,8 +2856,7 @@ if (spectrumCanvas) {
|
|||||||
const [, minBw, maxBw] = mwDefaultsForMode(modeEl ? modeEl.value : "USB");
|
const [, minBw, maxBw] = mwDefaultsForMode(modeEl ? modeEl.value : "USB");
|
||||||
newBw = Math.round(Math.max(minBw, Math.min(maxBw, newBw)));
|
newBw = Math.round(Math.max(minBw, Math.min(maxBw, newBw)));
|
||||||
currentBandwidthHz = newBw;
|
currentBandwidthHz = newBw;
|
||||||
const bwLabel = document.getElementById("spectrum-bw-label");
|
syncBandwidthInput(newBw);
|
||||||
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(newBw);
|
|
||||||
drawSpectrum(lastSpectrumData);
|
drawSpectrum(lastSpectrumData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
<div id="spectrum-freq-axis"></div>
|
<div id="spectrum-freq-axis"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="spectrum-controls">
|
<div id="spectrum-controls">
|
||||||
<span id="spectrum-bw-label">BW: --</span>
|
<label id="spectrum-bw-label">Bandwidth <input type="number" id="spectrum-bw-input" value="" step="100" min="1" /> Hz</label>
|
||||||
<div id="spectrum-level-row">
|
<div id="spectrum-level-row">
|
||||||
<label id="spectrum-floor-label">Floor <input type="number" id="spectrum-floor-input" value="-100" step="5" /> dB</label>
|
<label id="spectrum-floor-label">Floor <input type="number" id="spectrum-floor-input" value="-100" step="5" /> dB</label>
|
||||||
<button id="spectrum-auto-btn" type="button">Auto</button>
|
<button id="spectrum-auto-btn" type="button">Auto</button>
|
||||||
|
|||||||
@@ -654,10 +654,24 @@ button:focus-visible, input:focus-visible, select:focus-visible {
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
#spectrum-bw-label {
|
#spectrum-bw-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.3rem;
|
||||||
font-size: 0.78rem;
|
font-size: 0.78rem;
|
||||||
color: var(--accent-yellow);
|
color: var(--accent-yellow);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
min-width: 5rem;
|
min-width: 0;
|
||||||
|
}
|
||||||
|
#spectrum-bw-input {
|
||||||
|
width: 5.25rem;
|
||||||
|
padding: 1px 4px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: var(--text);
|
||||||
|
text-align: right;
|
||||||
|
height: 1.5rem;
|
||||||
}
|
}
|
||||||
#spectrum-level-row {
|
#spectrum-level-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user