provision for a custom gain control

This commit is contained in:
Jakob Ketterl 2020-05-17 21:21:37 +02:00
parent 63475dda78
commit 48b177defa

View File

@ -1,7 +1,8 @@
function Input(name, value, label) { function Input(name, value, options) {
this.name = name; this.name = name;
this.value = value; this.value = value;
this.label = label; this.options = options;
this.label = options && options.label || name;
}; };
Input.prototype.bootstrapify = function(input) { Input.prototype.bootstrapify = function(input) {
@ -36,6 +37,16 @@ NumberInput.prototype.render = function() {
return this.bootstrapify($('<input type="number" name="' + this.name + '" value="' + this.value + '">')); return this.bootstrapify($('<input type="number" name="' + this.name + '" value="' + this.value + '">'));
}; };
function SoapyGainInput() {
Input.apply(this, arguments);
}
SoapyGainInput.prototype = new Input();
SoapyGainInput.prototype.render = function(){
return this.bootstrapify($('<div>Soapy gain settings go here</div>'));
};
function ProfileInput() { function ProfileInput() {
Input.apply(this, arguments); Input.apply(this, arguments);
}; };
@ -94,37 +105,49 @@ SdrDevice.prototype.getMappings = function() {
return { return {
"name": { "name": {
constructor: TextInput, constructor: TextInput,
label: "Name", inputOptions: {
label: "Name"
},
initialValue: "", initialValue: "",
includeInDefault: true includeInDefault: true
}, },
"type": { "type": {
constructor: TextInput, constructor: TextInput,
label: "Type", inputOptions: {
label: "Type"
},
initialValue: '', initialValue: '',
includeInDefault: true includeInDefault: true
}, },
"ppm": { "ppm": {
constructor: NumberInput, constructor: NumberInput,
label: "PPM", inputOptions: {
label: "PPM"
},
initialValue: 0 initialValue: 0
}, },
"profiles": { "profiles": {
constructor: ProfileInput, constructor: ProfileInput,
label: "Profiles", inputOptions: {
label: "Profiles"
},
initialValue: [], initialValue: [],
includeInDefault: true, includeInDefault: true,
position: 100 position: 100
}, },
"scheduler": { "scheduler": {
constructor: SchedulerInput, constructor: SchedulerInput,
label: "Scheduler", inputOptions: {
label: "Scheduler",
},
initialValue: {}, initialValue: {},
position: 101 position: 101
}, },
"rf_gain": { "rf_gain": {
constructor: TextInput, constructor: TextInput,
label: "Gain", inputOptions: {
label: "Gain",
},
initialValue: 0 initialValue: 0
} }
}; };
@ -140,11 +163,6 @@ SdrDevice.prototype.getInputClass = function(key) {
return mapping && mapping.constructor || TextInput; return mapping && mapping.constructor || TextInput;
}; };
SdrDevice.prototype.getLabel = function(key) {
var mapping = this.getMapping(key);
return mapping && mapping.label || key;
};
SdrDevice.prototype.getInitialValue = function(key) { SdrDevice.prototype.getInitialValue = function(key) {
var mapping = this.getMapping(key); var mapping = this.getMapping(key);
return mapping && ('initialValue' in mapping) ? mapping['initialValue'] : false; return mapping && ('initialValue' in mapping) ? mapping['initialValue'] : false;
@ -155,6 +173,16 @@ SdrDevice.prototype.getPosition = function(key) {
return mapping && mapping.position || 10; return mapping && mapping.position || 10;
}; };
SdrDevice.prototype.getInputOptions = function(key) {
var mapping = this.getMapping(key);
return mapping && mapping.inputOptions || {};
};
SdrDevice.prototype.getLabel = function(key) {
var options = this.getInputOptions(key);
return options && options.label || key;
};
SdrDevice.prototype.render = function() { SdrDevice.prototype.render = function() {
var self = this; var self = this;
self.el.empty(); self.el.empty();
@ -164,7 +192,7 @@ SdrDevice.prototype.render = function() {
}).forEach(function(key){ }).forEach(function(key){
var value = data[key]; var value = data[key];
var inputClass = self.getInputClass(key); var inputClass = self.getInputClass(key);
var input = new inputClass(key, value, self.getLabel(key)); var input = new inputClass(key, value, self.getInputOptions(key));
self.inputs[key] = input; self.inputs[key] = input;
self.el.append(input.render()); self.el.append(input.render());
}); });
@ -190,7 +218,7 @@ SdrDevice.prototype.renderFieldSelector = function() {
'</div>'; '</div>';
}; };
RtlSdrDevice = function(el, data) { RtlSdrDevice = function() {
SdrDevice.apply(this, arguments); SdrDevice.apply(this, arguments);
}; };
@ -202,14 +230,58 @@ RtlSdrDevice.prototype.getMappings = function() {
return $.extend(new Object(), mappings, { return $.extend(new Object(), mappings, {
"device": { "device": {
constructor: TextInput, constructor: TextInput,
label: "Serial Number", inputOptions:{
label: "Serial number"
},
initialValue: "" initialValue: ""
} }
}); });
}; };
SoapySdrDevice = function() {
SdrDevice.apply(this, arguments);
};
SoapySdrDevice.prototype = Object.create(SdrDevice.prototype);
SoapySdrDevice.prototype.constructor = SoapySdrDevice;
SoapySdrDevice.prototype.getMappings = function() {
var mappings = SdrDevice.prototype.getMappings.apply(this, arguments);
return $.extend(new Object(), mappings, {
"device": {
constructor: TextInput,
inputOptions:{
label: "Soapy device selector"
},
initialValue: ""
}
});
};
SdrplaySdrDevice = function() {
SoapySdrDevice.apply(this, arguments);
};
SdrplaySdrDevice.prototype = Object.create(SoapySdrDevice.prototype);
SdrplaySdrDevice.prototype.constructor = SdrplaySdrDevice;
SdrplaySdrDevice.prototype.getMappings = function() {
var mappings = SoapySdrDevice.prototype.getMappings.apply(this, arguments);
return $.extend(new Object(), mappings, {
"rf_gain": {
constructor: SoapyGainInput,
initialValue: 0,
inputOptions: {
label: "Gain",
gains: ['RFGR', 'IFGR']
}
}
});
};
SdrDevice.types = { SdrDevice.types = {
'rtl_sdr': RtlSdrDevice 'rtl_sdr': RtlSdrDevice,
'sdrplay': SdrplaySdrDevice
}; };
$.fn.sdrdevice = function() { $.fn.sdrdevice = function() {