openwebrx-clone/htdocs/lib/Modes.js

54 lines
1.4 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();
},
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);
},
updatePanels: function() {
2020-05-01 23:07:44 +00:00
var init_complete = this.modes.length && Object.keys(this.features).length;
2020-05-01 22:05:20 +00:00
this.panels.forEach(function(p) {
p.render();
if (init_complete) {
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;
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
};