[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:
2026-02-27 23:34:51 +01:00
parent b8c154af60
commit 8827b2fa21
3 changed files with 51 additions and 9 deletions
@@ -888,8 +888,7 @@ function render(update) {
// Sync filter state (SDR backends only)
if (update.filter && typeof update.filter.bandwidth_hz === "number") {
currentBandwidthHz = update.filter.bandwidth_hz;
const bwLabel = document.getElementById("spectrum-bw-label");
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(currentBandwidthHz);
syncBandwidthInput(currentBandwidthHz);
}
if (update.status && update.status.freq && typeof update.status.freq.hz === "number") {
lastFreqHz = update.status.freq.hz;
@@ -1544,7 +1543,7 @@ const MODE_BW_DEFAULTS = {
USB: [2_700, 300, 6_000, 100],
AM: [6_000, 500, 15_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],
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.
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.
async function applyBwDefaultForMode(mode, sendToServer) {
const [def] = mwDefaultsForMode(mode);
currentBandwidthHz = def;
const bwLabel = document.getElementById("spectrum-bw-label");
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(def);
syncBandwidthInput(def);
if (sendToServer) {
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 ---
document.querySelector(".tab-bar").addEventListener("click", (e) => {
const btn = e.target.closest(".tab[data-tab]");
@@ -2827,8 +2856,7 @@ if (spectrumCanvas) {
const [, minBw, maxBw] = mwDefaultsForMode(modeEl ? modeEl.value : "USB");
newBw = Math.round(Math.max(minBw, Math.min(maxBw, newBw)));
currentBandwidthHz = newBw;
const bwLabel = document.getElementById("spectrum-bw-label");
if (bwLabel) bwLabel.textContent = "BW: " + formatBwLabel(newBw);
syncBandwidthInput(newBw);
drawSpectrum(lastSpectrumData);
return;
}
@@ -65,7 +65,7 @@
<div id="spectrum-freq-axis"></div>
</div>
<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">
<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>
@@ -654,10 +654,24 @@ button:focus-visible, input:focus-visible, select:focus-visible {
color: var(--text-muted);
}
#spectrum-bw-label {
display: flex;
align-items: center;
gap: 0.3rem;
font-size: 0.78rem;
color: var(--accent-yellow);
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 {
display: flex;