/** * SSTV General Mode * Terrestrial Slow-Scan Television decoder interface */ const SSTVGeneral = (function() { // State let isRunning = false; let eventSource = null; let images = []; let currentMode = null; let progress = 0; /** * Initialize the SSTV General mode */ function init() { checkStatus(); loadImages(); } /** * Select a preset frequency from the dropdown */ function selectPreset(value) { if (!value) return; const parts = value.split('|'); const freq = parseFloat(parts[0]); const mod = parts[1]; const freqInput = document.getElementById('sstvGeneralFrequency'); const modSelect = document.getElementById('sstvGeneralModulation'); if (freqInput) freqInput.value = freq; if (modSelect) modSelect.value = mod; // Update strip display const stripFreq = document.getElementById('sstvGeneralStripFreq'); const stripMod = document.getElementById('sstvGeneralStripMod'); if (stripFreq) stripFreq.textContent = freq.toFixed(3); if (stripMod) stripMod.textContent = mod.toUpperCase(); } /** * Check current decoder status */ async function checkStatus() { try { const response = await fetch('/sstv-general/status'); const data = await response.json(); if (!data.available) { updateStatusUI('unavailable', 'Decoder not installed'); showStatusMessage('SSTV decoder not available. Install slowrx: apt install slowrx', 'warning'); return; } if (data.running) { isRunning = true; updateStatusUI('listening', 'Listening...'); startStream(); } else { updateStatusUI('idle', 'Idle'); } updateImageCount(data.image_count || 0); } catch (err) { console.error('Failed to check SSTV General status:', err); } } /** * Start SSTV decoder */ async function start() { const freqInput = document.getElementById('sstvGeneralFrequency'); const modSelect = document.getElementById('sstvGeneralModulation'); const deviceSelect = document.getElementById('deviceSelect'); const frequency = parseFloat(freqInput?.value || '14.230'); const modulation = modSelect?.value || 'usb'; const device = parseInt(deviceSelect?.value || '0', 10); updateStatusUI('connecting', 'Starting...'); try { const response = await fetch('/sstv-general/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ frequency, modulation, device }) }); const data = await response.json(); if (data.status === 'started' || data.status === 'already_running') { isRunning = true; updateStatusUI('listening', `${frequency} MHz ${modulation.toUpperCase()}`); startStream(); showNotification('SSTV', `Listening on ${frequency} MHz ${modulation.toUpperCase()}`); // Update strip const stripFreq = document.getElementById('sstvGeneralStripFreq'); const stripMod = document.getElementById('sstvGeneralStripMod'); if (stripFreq) stripFreq.textContent = frequency.toFixed(3); if (stripMod) stripMod.textContent = modulation.toUpperCase(); } else { updateStatusUI('idle', 'Start failed'); showStatusMessage(data.message || 'Failed to start decoder', 'error'); } } catch (err) { console.error('Failed to start SSTV General:', err); updateStatusUI('idle', 'Error'); showStatusMessage('Connection error: ' + err.message, 'error'); } } /** * Stop SSTV decoder */ async function stop() { try { await fetch('/sstv-general/stop', { method: 'POST' }); isRunning = false; stopStream(); updateStatusUI('idle', 'Stopped'); showNotification('SSTV', 'Decoder stopped'); } catch (err) { console.error('Failed to stop SSTV General:', err); } } /** * Update status UI elements */ function updateStatusUI(status, text) { const dot = document.getElementById('sstvGeneralStripDot'); const statusText = document.getElementById('sstvGeneralStripStatus'); const startBtn = document.getElementById('sstvGeneralStartBtn'); const stopBtn = document.getElementById('sstvGeneralStopBtn'); if (dot) { dot.className = 'sstv-general-strip-dot'; if (status === 'listening' || status === 'detecting') { dot.classList.add('listening'); } else if (status === 'decoding') { dot.classList.add('decoding'); } else { dot.classList.add('idle'); } } if (statusText) { statusText.textContent = text || status; } if (startBtn && stopBtn) { if (status === 'listening' || status === 'decoding') { startBtn.style.display = 'none'; stopBtn.style.display = 'inline-block'; } else { startBtn.style.display = 'inline-block'; stopBtn.style.display = 'none'; } } // Update live content area const liveContent = document.getElementById('sstvGeneralLiveContent'); if (liveContent) { if (status === 'idle' || status === 'unavailable') { liveContent.innerHTML = renderIdleState(); } } } /** * Render idle state HTML */ function renderIdleState() { return `
Select a frequency and click Start to listen for SSTV transmissions
No images decoded yet