function Scanner(bookmarkBar, msec) { this.bbar = bookmarkBar; this.bookmarks = null; this.msec = msec; this.current = null; 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; } //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); panel.setMode(b.modulation, b.underlying); // Done 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; 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; jthis.threshold) return; else this.current = null; } // For every shown bookmark... for(var j=0 ; jthis.threshold && this.tuneBookmark(b)) return; } }; Scanner.prototype.stop = function() { // If timer running... if (this.timer) { // Stop redraw timer clearInterval(this.timer); this.timer = 0; // Remove current bookmarks and data this.bookmarks = null; this.current = null; this.data.length = 0; } // Done return this.timer == null; } Scanner.prototype.start = function() { // If timer is not running... if (!this.timer) { // Get all bookmarks from the bookmark bar this.bookmarks = this.bbar.getAllBookmarks(); // If there are bookmarks to scan... if (this.bookmarks && this.bookmarks.length>0) { // Start redraw timer var me = this; this.timer = setInterval(function() { me.scan(); }, this.msec); } } // Done return this.timer != null; } Scanner.prototype.toggle = function() { // Toggle based on the current timer state return this.timer? this.stop() : this.start(); };