openwebrx-clone/htdocs/lib/Modes.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

var Modes = {
modes: [],
features: {},
2020-05-01 22:05:20 +00:00
panels: [],
setModes:function(json){
this.modes = json.map(function(m){ return new Mode(m); });
2020-05-01 22:05:20 +00:00
this.updatePanels();
$('#openwebrx-dialog-bookmark').bookmarkDialog().setModes(this.modes);
2020-05-01 22:05:20 +00:00
},
getModes:function(){
return this.modes;
},
setFeatures:function(features){
this.features = features;
2020-05-01 22:05:20 +00:00
this.updatePanels();
},
findByModulation:function(modulation){
matches = this.modes.filter(function(m) { return m.modulation === modulation; });
if (matches.length) return matches[0]
2020-04-26 14:58:31 +00:00
},
2020-05-01 22:05:20 +00:00
registerModePanel: function(el) {
this.panels.push(el);
},
2020-05-02 13:07:47 +00:00
initComplete: function() {
return this.modes.length && Object.keys(this.features).length;
},
2020-05-01 22:05:20 +00:00
updatePanels: function() {
this.panels.forEach(function(p) {
p.render();
2020-05-02 13:07:47 +00:00
p.startDemodulator();
2020-04-26 15:18:48 +00:00
});
}
2020-04-26 15:18:48 +00:00
};
var Mode = function(json){
this.modulation = json.modulation;
this.name = json.name;
this.type = json.type;
this.requirements = json.requirements;
this.squelch = json.squelch;
if (json.bandpass) {
this.bandpass = json.bandpass;
}
if (this.type === 'digimode') {
this.underlying = json.underlying;
}
};
Mode.prototype.isAvailable = function(){
return this.requirements.map(function(r){
return Modes.features[r];
}).reduce(function(a, b){
return a && b;
}, true);
2020-05-01 22:05:20 +00:00
};