make a more generic ExponentialInput and use that for the sample_rate input

This commit is contained in:
Jakob Ketterl 2021-02-27 23:14:41 +01:00
parent 7a0c934af5
commit 0537e23e38
5 changed files with 22 additions and 19 deletions

View File

@ -1,4 +1,4 @@
$.fn.frequencyInput = function() { $.fn.exponentialInput = function() {
var suffixes = { var suffixes = {
"K": 3, "K": 3,
"M": 6, "M": 6,
@ -9,7 +9,7 @@ $.fn.frequencyInput = function() {
this.each(function(){ this.each(function(){
var $group = $(this); var $group = $(this);
var currentExponent = 0; var currentExponent = 0;
$input = $group.find('input'); var $input = $group.find('input');
var setExponent = function() { var setExponent = function() {
var newExponent = parseInt($exponent.val()); var newExponent = parseInt($exponent.val());
@ -26,7 +26,7 @@ $.fn.frequencyInput = function() {
} }
}); });
$exponent = $group.find('select.frequency-exponent'); var $exponent = $group.find('select.exponent');
$exponent.on('change', setExponent); $exponent.on('change', setExponent);
// calculate initial exponent // calculate initial exponent

View File

@ -7,5 +7,5 @@ $(function(){
$('#rf_gain').gainInput(); $('#rf_gain').gainInput();
$('.optional-section').optionalSection(); $('.optional-section').optionalSection();
$('#scheduler').schedulerInput(); $('#scheduler').schedulerInput();
$('.frequency-input').frequencyInput(); $('.exponential-input').exponentialInput();
}); });

View File

@ -153,7 +153,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
"lib/settings/GainInput.js", "lib/settings/GainInput.js",
"lib/settings/OptionalSection.js", "lib/settings/OptionalSection.js",
"lib/settings/SchedulerInput.js", "lib/settings/SchedulerInput.js",
"lib/settings/FrequencyInput.js", "lib/settings/ExponentialInput.js",
"settings.js", "settings.js",
], ],
} }

View File

@ -321,9 +321,10 @@ class ModesInput(DropdownInput):
super().__init__(id, label, options) super().__init__(id, label, options)
class FrequencyInput(Input): class ExponentialInput(Input):
def __init__(self, id, label, infotext=None): def __init__(self, id, label, unit, infotext=None):
super().__init__(id, label, infotext=infotext) super().__init__(id, label, infotext=infotext)
self.unit = unit
def defaultConverter(self): def defaultConverter(self):
return IntConverter() return IntConverter()
@ -337,21 +338,22 @@ class FrequencyInput(Input):
def render_input(self, value): def render_input(self, value):
append = """ append = """
<div class="input-group-append"> <div class="input-group-append">
<select class="input-group-text frequency-exponent" name="{id}-exponent" {disabled}> <select class="input-group-text exponent" name="{id}-exponent" {disabled}>
<option value="0" selected>Hz</option> <option value="0" selected>{unit}</option>
<option value="3">kHz</option> <option value="3">k{unit}</option>
<option value="6">MHz</option> <option value="6">M{unit}</option>
<option value="9">GHz</option> <option value="9">G{unit}</option>
<option value="12">THz</option> <option value="12">T{unit}</option>
</select> </select>
</div> </div>
""".format( """.format(
id=self.id, id=self.id,
disabled="disabled" if self.disabled else "", disabled="disabled" if self.disabled else "",
unit=self.unit,
) )
return """ return """
<div class="input-group input-group-sm frequency-input"> <div class="input-group input-group-sm exponential-input">
{input} {input}
{append} {append}
</div> </div>

View File

@ -11,7 +11,7 @@ from owrx.command import CommandMapper
from owrx.socket import getAvailablePort from owrx.socket import getAvailablePort
from owrx.property import PropertyStack, PropertyLayer, PropertyFilter from owrx.property import PropertyStack, PropertyLayer, PropertyFilter
from owrx.property.filter import ByLambda from owrx.property.filter import ByLambda
from owrx.form import Input, TextInput, NumberInput, CheckboxInput, ModesInput, FrequencyInput from owrx.form import Input, TextInput, NumberInput, CheckboxInput, ModesInput, ExponentialInput
from owrx.form.converter import OptionalConverter from owrx.form.converter import OptionalConverter
from owrx.form.device import GainInput, SchedulerInput, WaterfallLevelsInput from owrx.form.device import GainInput, SchedulerInput, WaterfallLevelsInput
from owrx.controllers.settings import Section from owrx.controllers.settings import Section
@ -494,17 +494,18 @@ class SdrDeviceDescription(object):
"services", "services",
"Run background services on this device", "Run background services on this device",
), ),
FrequencyInput( ExponentialInput(
"lfo_offset", "lfo_offset",
"Oscilator offset", "Oscilator offset",
"Hz",
infotext="Use this when the actual receiving frequency differs from the frequency to be tuned on the" infotext="Use this when the actual receiving frequency differs from the frequency to be tuned on the"
+ " device. <br/> Formula: Center frequency + oscillator offset = sdr tune frequency", + " device. <br/> Formula: Center frequency + oscillator offset = sdr tune frequency",
), ),
WaterfallLevelsInput("waterfall_levels", "Waterfall levels"), WaterfallLevelsInput("waterfall_levels", "Waterfall levels"),
SchedulerInput("scheduler", "Scheduler"), SchedulerInput("scheduler", "Scheduler"),
FrequencyInput("center_freq", "Center frequency"), ExponentialInput("center_freq", "Center frequency", "Hz"),
NumberInput("samp_rate", "Sample rate", append="S/s"), ExponentialInput("samp_rate", "Sample rate", "S/s"),
FrequencyInput("start_freq", "Initial frequency"), ExponentialInput("start_freq", "Initial frequency", "Hz"),
ModesInput("start_mod", "Initial modulation"), ModesInput("start_mod", "Initial modulation"),
NumberInput("initial_squelch_level", "Initial squelch level", append="dBFS"), NumberInput("initial_squelch_level", "Initial squelch level", append="dBFS"),
] ]