refactor demodulator classes, part 2

This commit is contained in:
Jakob Ketterl 2020-05-02 01:07:44 +02:00
parent b8f7686a6d
commit d9a818525d
3 changed files with 70 additions and 41 deletions

View File

@ -13,7 +13,8 @@ function BookmarkBar() {
if (b.modulation) { if (b.modulation) {
me.getDemodulatorPanel().setMode(b.modulation); me.getDemodulatorPanel().setMode(b.modulation);
} else if (b.digital_modulation) { } else if (b.digital_modulation) {
me.getDemodulatorPanel().setDigiMode(b.digital_modulation); // TODO: update bookmarks so they don't contain digital_modulation
me.getDemodulatorPanel().setMode(b.digital_modulation);
} }
$bookmark.addClass('selected'); $bookmark.addClass('selected');
}); });

View File

@ -10,13 +10,22 @@ function DemodulatorPanel(el) {
}); });
Modes.registerModePanel(this); Modes.registerModePanel(this);
el.on('click', '.openwebrx-demodulator-button[data-modulation]', function() { el.on('click', '.openwebrx-demodulator-button', function() {
self.setMode($(this).data('modulation')); var modulation = $(this).data('modulation');
if (modulation) {
self.setMode(modulation);
} else {
self.disableDigiMode();
}
}); });
el.on('change', '.openwebrx-secondary-demod-listbox', function() { el.on('change', '.openwebrx-secondary-demod-listbox', function() {
self.setDigiMode($(this).val()); var value = $(this).val();
if (value === 'none') {
self.disableDigiMode();
} else {
self.setMode(value);
}
}); });
// TODO: disable digimodes
}; };
DemodulatorPanel.prototype.render = function() { DemodulatorPanel.prototype.render = function() {
@ -52,7 +61,7 @@ DemodulatorPanel.prototype.render = function() {
html.push($( html.push($(
'<div class="openwebrx-panel-line openwebrx-panel-flex-line">' + '<div class="openwebrx-panel-line openwebrx-panel-flex-line">' +
'<div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-dig" onclick="demodulator_digital_replace_last();">DIG</div>' + '<div class="openwebrx-button openwebrx-demodulator-button openwebrx-button-dig">DIG</div>' +
'<select class="openwebrx-secondary-demod-listbox">' + '<select class="openwebrx-secondary-demod-listbox">' +
'<option value="none"></option>' + '<option value="none"></option>' +
digiModes.map(function(m){ digiModes.map(function(m){
@ -65,45 +74,60 @@ DemodulatorPanel.prototype.render = function() {
this.el.find(".openwebrx-modes").html(html); this.el.find(".openwebrx-modes").html(html);
}; };
DemodulatorPanel.prototype.setMode = function(mode) { DemodulatorPanel.prototype.setMode = function(modulation) {
var offset_frequency = 0;
if (this.demodulator) {
if (this.demodulator.get_modulation() === mode) {
return;
}
offset_frequency = this.demodulator.get_offset_frequency();
this.demodulator.stop();
}
this.demodulator = new Demodulator(offset_frequency, mode);
var self = this;
this.demodulator.on("frequencychange", function(freq) {
self.tuneableFrequencyDisplay.setFrequency(center_freq + freq);
});
this.demodulator.start();
this.updateButtons();
};
DemodulatorPanel.prototype.setDigiMode = function(modulation) {
var mode = Modes.findByModulation(modulation); var mode = Modes.findByModulation(modulation);
if (!mode) { if (!mode) {
return; return;
} }
if (!mode.isAvailable()) { if (!mode.isAvailable()) {
divlog('Digital mode "' + mode.name + '" not supported. Please check requirements', true); divlog('Modulation "' + mode.name + '" not supported. Please check requirements', true);
return; return;
} }
this.setMode(mode.underlying[0]);
this.getDemodulator().set_secondary_demod(modulation); if (mode.type === 'digimode') {
if (mode.bandpass) { modulation = mode.underlying[0];
this.getDemodulator().setBandpass(mode.bandpass);
} }
var current_offset_frequency = 0;
var current_modulation = false;
if (this.demodulator) {
current_modulation = this.demodulator.get_modulation();
current_offset_frequency = this.demodulator.get_offset_frequency();
}
if (current_modulation !== modulation) {
if (this.demodulator) this.demodulator.stop();
this.demodulator = new Demodulator(current_offset_frequency, modulation);
var self = this;
this.demodulator.on("frequencychange", function(freq) {
self.tuneableFrequencyDisplay.setFrequency(center_freq + freq);
});
}
if (mode.type === 'digimode') {
this.demodulator.set_secondary_demod(mode.modulation);
} else {
this.demodulator.set_secondary_demod(false);
}
this.demodulator.start();
this.updateButtons();
this.updatePanels();
updateHash();
};
DemodulatorPanel.prototype.disableDigiMode = function() {
var modulation = this.el.find('.openwebrx-button.highlighted[data-modulation]').data('modulation');
this.setMode(modulation);
};
DemodulatorPanel.prototype.updatePanels = function() {
var modulation = this.getDemodulator().get_secondary_demod();
$('#openwebrx-panel-digimodes').attr('data-mode', modulation); $('#openwebrx-panel-digimodes').attr('data-mode', modulation);
toggle_panel("openwebrx-panel-digimodes", true); toggle_panel("openwebrx-panel-digimodes", !!modulation);
toggle_panel("openwebrx-panel-wsjt-message", ['ft8', 'wspr', 'jt65', 'jt9', 'ft4'].indexOf(modulation) >= 0); toggle_panel("openwebrx-panel-wsjt-message", ['ft8', 'wspr', 'jt65', 'jt9', 'ft4'].indexOf(modulation) >= 0);
toggle_panel("openwebrx-panel-js8-message", modulation == "js8"); toggle_panel("openwebrx-panel-js8-message", modulation == "js8");
toggle_panel("openwebrx-panel-packet-message", modulation === "packet"); toggle_panel("openwebrx-panel-packet-message", modulation === "packet");
toggle_panel("openwebrx-panel-pocsag-message", modulation === "pocsag"); toggle_panel("openwebrx-panel-pocsag-message", modulation === "pocsag");
updateHash();
}; };
DemodulatorPanel.prototype.getDemodulator = function() { DemodulatorPanel.prototype.getDemodulator = function() {
@ -126,7 +150,10 @@ DemodulatorPanel.prototype.setInitialParams = function(params) {
}; };
DemodulatorPanel.prototype.setHashParams = function(params) { DemodulatorPanel.prototype.setHashParams = function(params) {
this._apply(params); this._apply({
mod: params.secondary_mod || params.mod,
offset_frequency: params.offset_frequency
});
}; };
DemodulatorPanel.prototype.updateButtons = function() { DemodulatorPanel.prototype.updateButtons = function() {
@ -134,19 +161,20 @@ DemodulatorPanel.prototype.updateButtons = function() {
$buttons.removeClass("highlighted").removeClass('disabled'); $buttons.removeClass("highlighted").removeClass('disabled');
var demod = this.getDemodulator() var demod = this.getDemodulator()
if (!demod) return; if (!demod) return;
var mod = demod.get_modulation(); this.el.find('[data-modulation=' + demod.get_modulation() + ']').addClass("highlighted");
this.el.find('[data-modulation=' + mod + ']').addClass("highlighted"); var secondary_demod = demod.get_secondary_demod()
var secondary_demod = this.getDemodulator().get_secondary_demod()
if (secondary_demod) { if (secondary_demod) {
this.el.find("#openwebrx-button-dig").addClass("highlighted"); this.el.find(".openwebrx-button-dig").addClass("highlighted");
this.el.find('#openwebrx-secondary-demod-listbox').val(secondary_demod); this.el.find('.openwebrx-secondary-demod-listbox').val(secondary_demod);
var mode = Modes.findByModulation(secondary_demod); var mode = Modes.findByModulation(secondary_demod);
if (mode) { if (mode) {
var active = mode.underlying.map(function(u){ return 'openwebrx-button-' + u; });
$buttons.filter(function(){ $buttons.filter(function(){
return this.id !== "openwebrx-button-dig" && active.indexOf(this.id) < 0; var mod = $(this).data('modulation');
return mod && mode.underlying.indexOf(mod) < 0;
}).addClass('disabled'); }).addClass('disabled');
} }
} else {
this.el.find('.openwebrx-secondary-demod-listbox').val('none');
} }
} }

View File

@ -21,7 +21,7 @@ var Modes = {
this.panels.push(el); this.panels.push(el);
}, },
updatePanels: function() { updatePanels: function() {
var init_complete = this.modes && this.features; var init_complete = this.modes.length && Object.keys(this.features).length;
this.panels.forEach(function(p) { this.panels.forEach(function(p) {
p.render(); p.render();
if (init_complete) { if (init_complete) {