implement gain dialog with AGC option

This commit is contained in:
Jakob Ketterl 2021-02-19 21:07:13 +01:00
parent 86278ff44d
commit d0d946e09f
5 changed files with 61 additions and 4 deletions

View File

@ -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());
});
}

View File

@ -1,8 +1,8 @@
$(function(){
$('.map-input').mapInput();
$('.sdrdevice').sdrdevice();
$('.imageupload').imageUpload();
$('.bookmarks').bookmarktable();
$('.wsjt-decoding-depths').wsjtDecodingDepthsInput();
$('#waterfall_scheme').waterfallDropdown();
$('#rf_gain').gainInput();
});

View File

@ -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",
],
}

33
owrx/form/device.py Normal file
View File

@ -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 """
<div id="{id}">
<select class="{classes}" id="{id}-select" name="{id}-select">
<option value="auto" {auto_selected}>Enable hardware AGC</option>
<option value="manual" {manual_selected}>Specify manual gain</option>
</select>
<div class="option manual" style="display: none;">
<input type="number" id="{id}-manual" name="{id}-manual" value="{value}" class="{classes}" placeholder="Manual device gain" value="{value}" step="any">
</div>
</div>
""".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}

View File

@ -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):