Skip to content

Commit

Permalink
Fixed several scanner bugs, added UI.tuneBookmark(), UI.toggleScanner().
Browse files Browse the repository at this point in the history
  • Loading branch information
luarvique committed Nov 7, 2024
1 parent 0606f3e commit 5844044
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 56 deletions.
10 changes: 4 additions & 6 deletions htdocs/lib/BookmarkBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
25 changes: 5 additions & 20 deletions htdocs/lib/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -82,7 +72,7 @@ Scanner.prototype.stop = function() {
}

// Done
return this.timer == null;
return !this.timer;
}

Scanner.prototype.start = function() {
Expand Down Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion htdocs/lib/Shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Shortcuts.handleKey = function(event) {

case 's':
// S: Toggle scanner
toggleScanner();
UI.toggleScanner();
break;

case 'd':
Expand Down
42 changes: 42 additions & 0 deletions htdocs/lib/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
Expand Down
5 changes: 3 additions & 2 deletions htdocs/lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 4 additions & 27 deletions htdocs/openwebrx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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');
}
}

/*
_____ _ _ _
| __ \(_) (_) | |
Expand Down

0 comments on commit 5844044

Please sign in to comment.