diff --git a/htdocs/lib/Scanner.js b/htdocs/lib/Scanner.js index 87170fda..23b6257e 100644 --- a/htdocs/lib/Scanner.js +++ b/htdocs/lib/Scanner.js @@ -2,22 +2,16 @@ function Scanner(bookmarkBar, msec) { this.bbar = bookmarkBar; this.bookmarks = null; this.msec = msec; - this.current = null; + this.current = -1; this.threshold = -80; - this.data = []; } Scanner.prototype.tuneBookmark = function(b) { // Must have frequency, skip digital voice modes - if (!b || !b.frequency || !b.modulation || b.modulation=='dmr') { - return false; - } + if (!b.frequency || !b.modulation || b.modulation=='dmr') return false; //console.log("TUNE: " + b.name + " at " + b.frequency + ": " + b.modulation); - // Make this bookmark current - this.current = b; - // Tune to the bookmark frequency var panel = $('#openwebrx-panel-receiver').demodulatorPanel(); panel.getDemodulator().set_offset_frequency(b.frequency - center_freq); @@ -27,58 +21,45 @@ Scanner.prototype.tuneBookmark = function(b) { return true; } -Scanner.prototype.getLevel = function(b) { - // Must have bookmark and frequency - if(!b || !b.frequency || !this.data.length) return -1000; - - // Compute relevant FFT slot index - var x = this.data.length * ((b.frequency - center_freq) / bandwidth + 0.5); - return this.data[x | 0]; -} - Scanner.prototype.update = function(data) { - // Do not update if no timer - if (!this.timer) return; + // Do not update if no timer or no bookmarks + if (!this.timer || !this.bookmarks || !this.bookmarks.length) return; - var i = this.data.length < data.length? this.data.length : data.length; - - // Truncate stored data length, add and fill missing data - if (this.data.length > i) { - this.data.length = i; - } else if(this.data.length < data.length) { - this.data.length = data.length; - for(var j=i; j 0) { + var l = data[(b.pos * data.length) | 0]; + b.level += (l - b.level) / 5.0; + } } - - // Average level over time - for(var j=0; jthis.threshold) return; else this.current = null; + if (this.current>=0) { + var level = this.bookmarks[this.current].level; + if (level>this.threshold) return; else this.current = -1; } // For every shown bookmark... for(var j=0 ; jthis.threshold && this.tuneBookmark(b)) return; + if (b.level>this.threshold && this.tuneBookmark(b)) { + this.current = j; + return; + } } }; @@ -88,10 +69,8 @@ Scanner.prototype.stop = function() { // Stop redraw timer clearInterval(this.timer); this.timer = 0; - // Remove current bookmarks and data + // Remove current bookmarks this.bookmarks = null; - this.current = null; - this.data.length = 0; } // Done @@ -103,9 +82,17 @@ Scanner.prototype.start = function() { if (!this.timer) { // Get all bookmarks from the bookmark bar this.bookmarks = this.bbar.getAllBookmarks(); + this.current = -1; // If there are bookmarks to scan... if (this.bookmarks && this.bookmarks.length>0) { + // Precompute FFT offsets, initialize levels + for(var j=0 ; j0? (f - center_freq) / bandwidth + 0.5 : 0; + } + // Start redraw timer var me = this; this.timer = setInterval(function() { me.scan(); }, this.msec); diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index fdbfd24d..e39445c5 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1051,6 +1051,7 @@ function on_ws_recv(evt) { currentprofile['profile_id'] = config['profile_id'] || currentprofile['profile_id']; $('#openwebrx-sdr-profiles-listbox').val(currentprofile.toString()); + stopScanner(); tuning_step_reset(); waterfall_clear(); zoom_set(0); @@ -1710,6 +1711,11 @@ function toggleSpectrum() { spectrum.toggle(); } +function stopScanner() { + $('.openwebrx-scan-button').css('animation-name', ''); + scanner.stop(); +} + function toggleScanner() { var $scanButton = $('.openwebrx-scan-button'); var on = scanner.toggle();