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