implement a frequency input with switchable exponent
This commit is contained in:
parent
ccdb010e9d
commit
c389d3b619
21
htdocs/lib/settings/FrequencyInput.js
Normal file
21
htdocs/lib/settings/FrequencyInput.js
Normal file
@ -0,0 +1,21 @@
|
||||
$.fn.frequencyInput = function() {
|
||||
this.each(function(){
|
||||
var $group = $(this);
|
||||
var currentExponent = 0;
|
||||
$input = $group.find('input');
|
||||
|
||||
var setExponent = function() {
|
||||
var newExponent = parseInt($exponent.val());
|
||||
var delta = currentExponent - newExponent;
|
||||
$input.val(parseFloat($input.val()) * 10 ** delta);
|
||||
currentExponent = newExponent;
|
||||
};
|
||||
|
||||
$exponent = $group.find('select.frequency-exponent');
|
||||
$exponent.on('change', setExponent);
|
||||
|
||||
// calculate initial exponent
|
||||
$exponent.val(Math.floor(Math.log10($input.val()) / 3) * 3);
|
||||
setExponent();
|
||||
})
|
||||
};
|
@ -7,4 +7,5 @@ $(function(){
|
||||
$('#rf_gain').gainInput();
|
||||
$('.optional-section').optionalSection();
|
||||
$('#scheduler').schedulerInput();
|
||||
$('.frequency-input').frequencyInput();
|
||||
});
|
@ -153,6 +153,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
|
||||
"lib/settings/GainInput.js",
|
||||
"lib/settings/OptionalSection.js",
|
||||
"lib/settings/SchedulerInput.js",
|
||||
"lib/settings/FrequencyInput.js",
|
||||
"settings.js",
|
||||
],
|
||||
}
|
||||
|
@ -319,3 +319,49 @@ class ModesInput(DropdownInput):
|
||||
def __init__(self, id, label):
|
||||
options = [Option(m.modulation, m.name) for m in Modes.getAvailableModes()]
|
||||
super().__init__(id, label, options)
|
||||
|
||||
|
||||
class FrequencyInput(Input):
|
||||
def __init__(self, id, label):
|
||||
super().__init__(id, label)
|
||||
|
||||
def defaultConverter(self):
|
||||
return IntConverter()
|
||||
|
||||
def input_properties(self, value):
|
||||
props = super().input_properties(value)
|
||||
props["type"] = "number"
|
||||
props["step"] = "any"
|
||||
return props
|
||||
|
||||
def render_input(self, value):
|
||||
append = """
|
||||
<div class="input-group-append">
|
||||
<select class="input-group-text frequency-exponent" name="{id}-exponent">
|
||||
<option value="0" selected>Hz</option>
|
||||
<option value="3">kHz</option>
|
||||
<option value="6">MHz</option>
|
||||
<option value="9">GHz</option>
|
||||
<option value="12">THz</option>
|
||||
</select>
|
||||
</div>
|
||||
""".format(
|
||||
id=self.id,
|
||||
)
|
||||
|
||||
return """
|
||||
<div class="input-group input-group-sm frequency-input">
|
||||
{input}
|
||||
{append}
|
||||
</div>
|
||||
""".format(
|
||||
input=super().render_input(value),
|
||||
append=append,
|
||||
)
|
||||
|
||||
def parse(self, data):
|
||||
exponent_id = "{}-exponent".format(self.id)
|
||||
if self.id in data and exponent_id in data:
|
||||
value = int(float(data[self.id][0]) * 10 ** int(data[exponent_id][0]))
|
||||
return {self.id: value}
|
||||
return {}
|
||||
|
@ -11,7 +11,7 @@ from owrx.command import CommandMapper
|
||||
from owrx.socket import getAvailablePort
|
||||
from owrx.property import PropertyStack, PropertyLayer, PropertyFilter
|
||||
from owrx.property.filter import ByLambda
|
||||
from owrx.form import Input, TextInput, NumberInput, CheckboxInput, ModesInput
|
||||
from owrx.form import Input, TextInput, NumberInput, CheckboxInput, ModesInput, FrequencyInput
|
||||
from owrx.form.converter import OptionalConverter
|
||||
from owrx.form.device import GainInput, SchedulerInput, WaterfallLevelsInput
|
||||
from owrx.controllers.settings import Section
|
||||
@ -503,7 +503,7 @@ class SdrDeviceDescription(object):
|
||||
),
|
||||
WaterfallLevelsInput("waterfall_levels", "Waterfall levels"),
|
||||
SchedulerInput("scheduler", "Scheduler"),
|
||||
NumberInput("center_freq", "Center frequency", append="Hz"),
|
||||
FrequencyInput("center_freq", "Center frequency"),
|
||||
NumberInput("samp_rate", "Sample rate", append="S/s"),
|
||||
NumberInput("start_freq", "Initial frequency", append="Hz"),
|
||||
ModesInput("start_mod", "Initial modulation"),
|
||||
|
Loading…
Reference in New Issue
Block a user