2020-04-26 13:17:03 +00:00
|
|
|
var Modes = {
|
|
|
|
modes: [],
|
|
|
|
features: {},
|
|
|
|
setModes:function(json){
|
|
|
|
this.modes = json.map(function(m){ return new Mode(m); });
|
2020-04-26 14:58:31 +00:00
|
|
|
this.updateModePanel();
|
2020-04-26 13:17:03 +00:00
|
|
|
},
|
|
|
|
setFeatures:function(features){
|
|
|
|
this.features = features;
|
2020-04-26 14:58:31 +00:00
|
|
|
this.updateModePanel();
|
2020-04-26 13:17:03 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
updateModePanel:function() {
|
|
|
|
var available = this.modes.filter(function(m){ return m.isAvailable(); });
|
2020-04-26 16:45:41 +00:00
|
|
|
var normalModes = available.filter(function(m){ return m.type === 'analog'; });
|
|
|
|
var digiModes = available.filter(function(m){ return m.type === 'digimode'; });
|
2020-04-26 15:18:48 +00:00
|
|
|
|
|
|
|
var html = []
|
|
|
|
|
|
|
|
var buttons = normalModes.map(function(m){
|
|
|
|
return $(
|
|
|
|
'<div class="openwebrx-button openwebrx-demodulator-button"' +
|
|
|
|
'id="openwebrx-button-' + m.modulation + '"' +
|
|
|
|
'onclick="demodulator_analog_replace(\'' + m.modulation + '\');">' +
|
|
|
|
m.name + '</div>'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-04-26 14:58:31 +00:00
|
|
|
var index = 0;
|
2020-04-26 15:18:48 +00:00
|
|
|
var arrayLength = buttons.length;
|
2020-04-26 14:58:31 +00:00
|
|
|
var chunks = [];
|
|
|
|
|
|
|
|
for (index = 0; index < arrayLength; index += 5) {
|
2020-04-26 15:18:48 +00:00
|
|
|
chunks.push(buttons.slice(index, index + 5));
|
2020-04-26 14:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
html.push.apply(html, chunks.map(function(chunk){
|
2020-04-26 15:18:48 +00:00
|
|
|
$line = $('<div class="openwebrx-panel-line openwebrx-panel-flex-line"></div>');
|
|
|
|
$line.append.apply($line, chunk);
|
|
|
|
return $line
|
2020-04-26 14:58:31 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
html.push($(
|
|
|
|
'<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>' +
|
|
|
|
'<select id="openwebrx-secondary-demod-listbox" onchange="secondary_demod_listbox_changed();">' +
|
|
|
|
'<option value="none"></option>' +
|
|
|
|
digiModes.map(function(m){
|
|
|
|
return '<option value="' + m.modulation + '">' + m.name + '</option>';
|
|
|
|
}).join('') +
|
|
|
|
'</select>' +
|
|
|
|
'</div>'
|
|
|
|
));
|
|
|
|
|
|
|
|
$("#openwebrx-panel-receiver").find(".openwebrx-modes").html(html);
|
2020-04-26 13:17:03 +00:00
|
|
|
}
|
2020-04-26 15:18:48 +00:00
|
|
|
};
|
2020-04-26 13:17:03 +00:00
|
|
|
|
|
|
|
var Mode = function(json){
|
|
|
|
this.modulation = json.modulation;
|
|
|
|
this.name = json.name;
|
2020-04-26 16:45:41 +00:00
|
|
|
this.type = json.type;
|
2020-04-26 13:17:03 +00:00
|
|
|
this.requirements = json.requirements;
|
2020-04-26 16:45:41 +00:00
|
|
|
if (json.bandpass) {
|
|
|
|
this.bandpass = json.bandpass;
|
|
|
|
}
|
|
|
|
if (this.type === 'digimode') {
|
|
|
|
this.underlying = json.underlying;
|
|
|
|
}
|
2020-04-26 13:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Mode.prototype.isAvailable = function(){
|
|
|
|
return this.requirements.map(function(r){
|
|
|
|
return Modes.features[r];
|
|
|
|
}).reduce(function(a, b){
|
|
|
|
return a && b;
|
|
|
|
}, true);
|
|
|
|
}
|