diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index 9104639d..cffeb295 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -8,12 +8,10 @@ function BookmarkBar() { me.$container.on('click', '.bookmark', function(e){ var $bookmark = $(e.target).closest('.bookmark'); me.$container.find('.bookmark').removeClass('selected'); - var b = $bookmark.data(); - if (!b || !b.frequency || !b.modulation) return; - UI.setFrequency(b.frequency); - UI.setModulation(b.modulation, b.underlying); - $bookmark.addClass('selected'); - stopScanner(); + if (UI.tuneBookmark($bookmark.data())) { + $bookmark.addClass('selected'); + UI.toggleScanner(false); + } }); me.$container.on('click', '.action[data-action=edit]', function(e){ diff --git a/htdocs/lib/Scanner.js b/htdocs/lib/Scanner.js index 309f3803..43e75926 100644 --- a/htdocs/lib/Scanner.js +++ b/htdocs/lib/Scanner.js @@ -5,17 +5,7 @@ function Scanner(bookmarkBar, msec) { this.msec = msec; this.current = -1; this.threshold = -80; -} - -Scanner.prototype.tuneBookmark = function(b) { - //console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation); - - // Tune to the bookmark frequency - UI.setFrequency(b.frequency); - UI.setModulation(b.modulation, b.underlying); - - // Done - return true; + this.timer = 0; } Scanner.prototype.update = function(data) { @@ -61,7 +51,7 @@ Scanner.prototype.scan = function() { //console.log("SCAN: " + b.name + " at " + b.frequency + ": " + b.level); // If level exceeds threshold, tune to the bookmark - if (b.level>this.threshold && this.tuneBookmark(b)) { + if (b.level>this.threshold && UI.tuneBookmark(b)) { this.current = current; return; } @@ -82,7 +72,7 @@ Scanner.prototype.stop = function() { } // Done - return this.timer == null; + return !this.timer; } Scanner.prototype.start = function() { @@ -111,15 +101,10 @@ Scanner.prototype.start = function() { } // Done - return this.timer != null; + return !!this.timer; } -Scanner.prototype.toggle = function() { - // Toggle based on the current timer state - return this.timer? this.stop() : this.start(); -}; - Scanner.prototype.isRunning = function() { // Return current state - return this.timer != null; + return !!this.timer; }; diff --git a/htdocs/lib/Shortcuts.js b/htdocs/lib/Shortcuts.js index b9e7c3e0..2a4449d8 100644 --- a/htdocs/lib/Shortcuts.js +++ b/htdocs/lib/Shortcuts.js @@ -289,7 +289,7 @@ Shortcuts.handleKey = function(event) { case 's': // S: Toggle scanner - toggleScanner(); + UI.toggleScanner(); break; case 'd': diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index 2981f100..19caa0a3 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -130,6 +130,21 @@ UI.setFrequency = function(freq) { return this.setOffsetFrequency(freq - center_freq); }; +UI.tuneBookmark = function(b) { + // Bookmark must have frequency and modulation + if (!b || !b.frequency || !b.modulation) return false; + + //console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation); + + // Tune to the bookmark frequency + var freq = b.modulation === 'cw'? b.frequency - 800 : b.frequency; + UI.setFrequency(freq, b.modulation); + UI.setModulation(b.modulation, b.underlying); + + // Done + return true; +}; + // // Volume Controls // @@ -230,6 +245,33 @@ UI.toggleRecording = function(on) { } }; +// +// Scanner Controls +// + +UI.toggleScanner = function(on) { + // If no argument given, toggle scanner + if (typeof(on) === 'undefined') on = !scanner.isRunning(); + + // Do not change scanner state if not needed + if (scanner.isRunning() == on) return; + + // Start or stop scanner as needed + if (on) scanner.start(); else scanner.stop(); + + // Get current scanner state + on = scanner.isRunning(); + + // Update UI elements + var $scanButton = $('.openwebrx-squelch-auto'); + $scanButton.css('animation-name', on? 'openwebrx-scan-animation' : ''); + if (on) { + $scanButton.addClass('highlighted'); + } else { + $scanButton.removeClass('highlighted'); + } +}; + // // Look & Feel Controls // diff --git a/htdocs/lib/Utils.js b/htdocs/lib/Utils.js index 7b40605b..d3455cee 100644 --- a/htdocs/lib/Utils.js +++ b/htdocs/lib/Utils.js @@ -70,10 +70,11 @@ Utils.offsetFreq = function(freq, mod) { case 'rtty450': case 'rtty170': case 'rtty85': - case 'sitorb': - case 'dsc': case 'bpsk31': case 'bpsk63': + case 'sitorb': + case 'navtex': + case 'dsc': return freq - 1000; } diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 2bf3cccb..08112933 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -290,7 +290,7 @@ function scale_canvas_end_drag(x) { for (var i = 0; i < demodulators.length; i++) event_handled |= demodulators[i].envelope.drag_end(); if (!event_handled) { demodulators[0].set_offset_frequency(scale_offset_freq_from_px(x)); - stopScanner(); + UI.toggleScanner(false); } } @@ -733,7 +733,7 @@ function canvas_mouseup(evt) { // For CW, move offset 800Hz below the actual carrier if (UI.getModulation() === 'cw') f = f - 800; UI.setOffsetFrequency(f); - stopScanner(); + UI.toggleScanner(false); } else { canvas_end_drag(); } @@ -929,7 +929,7 @@ function on_ws_recv(evt) { currentprofile['profile_id'] = config['profile_id'] || currentprofile['profile_id']; $('#openwebrx-sdr-profiles-listbox').val(currentprofile.toString()); - stopScanner(); + UI.toggleScanner(false); tuning_step_reset(); waterfall_clear(); zoom_set(0); @@ -1449,7 +1449,7 @@ function initSliders() { // Enable scanner by pressing the right mouse button on SQUELCH $('.openwebrx-squelch-auto').on('contextmenu', function() { - toggleScanner(); + UI.toggleScanner(); return false; }); } @@ -1578,29 +1578,6 @@ function initSpectrum() { spectrum = new Spectrum(canvas, 150); } -function stopScanner() { - if (scanner.isRunning()) { - // Stop scanner - scanner.stop(); - // Modify scanner button state - var $scanButton = $('.openwebrx-squelch-auto'); - $scanButton.css('animation-name', ''); - $scanButton.removeClass('highlighted'); - } -} - -function toggleScanner() { - var $scanButton = $('.openwebrx-squelch-auto'); - var on = scanner.toggle(); - - $scanButton.css('animation-name', on? 'openwebrx-scan-animation' : ''); - if (on) { - $scanButton.addClass('highlighted'); - } else { - $scanButton.removeClass('highlighted'); - } -} - /* _____ _ _ _ | __ \(_) (_) | |