diff --git a/htdocs/lib/settings/GainInput.js b/htdocs/lib/settings/GainInput.js new file mode 100644 index 0000000..31552bc --- /dev/null +++ b/htdocs/lib/settings/GainInput.js @@ -0,0 +1,22 @@ +$.fn.gainInput = function() { + this.each(function() { + var $container = $(this); + + var update = function(value){ + $container.find('.option').hide(); + $container.find('.option.' + value).show(); + } + + var $select = $container.find('select'); + $select.on('change', function(e) { + var value = $(e.target).val() + update(value); + if (value == 'auto') { + $input.val('auto'); + } else { + $input + } + }); + update($select.val()); + }); +} \ No newline at end of file diff --git a/htdocs/settings.js b/htdocs/settings.js index 1a76dbe..4a9903b 100644 --- a/htdocs/settings.js +++ b/htdocs/settings.js @@ -1,8 +1,8 @@ $(function(){ $('.map-input').mapInput(); - $('.sdrdevice').sdrdevice(); $('.imageupload').imageUpload(); $('.bookmarks').bookmarktable(); $('.wsjt-decoding-depths').wsjtDecodingDepthsInput(); $('#waterfall_scheme').waterfallDropdown(); + $('#rf_gain').gainInput(); }); \ No newline at end of file diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 51343aa..f090fb6 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -150,6 +150,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/settings/BookmarkTable.js", "lib/settings/WsjtDecodingDepthsInput.js", "lib/settings/WaterfallDropdown.js", + "lib/settings/GainInput.js", "settings.js", ], } diff --git a/owrx/form/device.py b/owrx/form/device.py new file mode 100644 index 0000000..1da6791 --- /dev/null +++ b/owrx/form/device.py @@ -0,0 +1,33 @@ +from owrx.form import Input + + +class GainInput(Input): + def render_input(self, value): + auto_mode = value is None or value == "auto" + + return """ +
+ + +
+ """.format( + id=self.id, + classes=self.input_classes(), + value=value, + label=self.label, + auto_selected="selected" if auto_mode else "", + manual_selected="" if auto_mode else "selected", + ) + + def parse(self, data): + select_id = "{id}-select".format(id=self.id) + if select_id in data: + input_id = "{id}-manual".format(id=self.id) + if data[select_id][0] == "manual" and input_id in data: + return {self.id: float(data[input_id][0])} + return {self.id: None} diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index 0d33fb3..6324235 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -10,8 +10,9 @@ from abc import ABC, abstractmethod from owrx.command import CommandMapper from owrx.socket import getAvailablePort from owrx.property import PropertyStack, PropertyLayer -from owrx.form import Input, TextInput, NumberInput, CheckboxInput, FloatInput -from owrx.form.converter import IntConverter, OptionalConverter, FloatConverter +from owrx.form import Input, TextInput, NumberInput, CheckboxInput +from owrx.form.converter import IntConverter, OptionalConverter +from owrx.form.device import GainInput from owrx.controllers.settings import Section from typing import List @@ -394,7 +395,7 @@ class SdrDeviceDescription(object): "Run background services on this device", converter=OptionalConverter(defaultFormValue=True), ), - FloatInput("rf_gain", "Device gain", converter=OptionalConverter(FloatConverter())), + GainInput("rf_gain", "Device gain"), ] def mergeInputs(self, *args):