From 34312dd402e5b602fe10c38fe505ecc97ef54312 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 25 Jan 2020 20:53:55 +0100 Subject: [PATCH 1/6] fix url hash parsing --- htdocs/openwebrx.js | 75 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 50cfdec6..4546b9af 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1050,8 +1050,11 @@ function on_ws_recv(evt) { waterfall_auto_level_margin = config['waterfall_auto_level_margin']; waterfallColorsDefault(); - starting_mod = config['start_mod']; - starting_offset_frequency = config['start_offset_freq']; + var initial_demodulator_params = { + mod: config['start_mod'], + offset_frequency: config['start_offset_freq'] + }; + bandwidth = config['samp_rate']; center_freq = config['center_freq']; fft_size = config['fft_size']; @@ -1067,7 +1070,7 @@ function on_ws_recv(evt) { updateSquelch(); waterfall_init(); - initialize_demodulator(); + initialize_demodulator(initial_demodulator_params); bookmarks.loadLocalBookmarks(); waterfall_clear(); @@ -1489,28 +1492,37 @@ function webrx_set_param(what, value) { ws.send(JSON.stringify({"type": "dspcontrol", "params": params})); } -var starting_offset_frequency; -var starting_mod; - function parseHash() { - var h; - if (h = window.location.hash) { - h.substring(1).split(",").forEach(function (x) { - var harr = x.split("="); - if (harr[0] === "mute") toggleMute(); - else if (harr[0] === "mod") starting_mod = harr[1]; - else if (harr[0] === "sql") { - e("openwebrx-panel-squelch").value = harr[1]; - updateSquelch(); - } - else if (harr[0] === "freq") { - console.log(parseInt(harr[1])); - console.log(center_freq); - starting_offset_frequency = parseInt(harr[1]) - center_freq; - } - }); - + if (!window.location.hash) { + return {}; } + return window.location.hash.substring(1).split(",").map(function(x) { + var harr = x.split('='); + return [harr[0], harr.slice(1).join('=')]; + }).reduce(function(params, p){ + params[p[0]] = p[1]; + return params; + }, {}); +} + +function validateHash() { + var params = parseHash(); + params = Object.keys(params).filter(function(key) { + if (key == 'freq') { + return Math.abs(params[key] - center_freq) < bandwidth; + } + return true; + }).reduce(function(p, key) { + p[key] = params[key]; + return p; + }, {}); + + if (params['freq']) { + params['offset_frequency'] = params['freq'] - center_freq; + delete params['freq']; + } + + return params; } function onAudioStart(success, apiType){ @@ -1528,14 +1540,14 @@ function onAudioStart(success, apiType){ updateVolume(); } -function initialize_demodulator() { - demodulator_analog_replace(starting_mod); - if (starting_offset_frequency) { - demodulators[0].offset_frequency = starting_offset_frequency; - tunedFrequencyDisplay.setFrequency(center_freq + starting_offset_frequency); - demodulators[0].set(); - mkscale(); - } +function initialize_demodulator(initialParams) { + mkscale(); + var params = $.extend(initialParams || {}, validateHash()); + console.info(params); + if (!params.mod) return; + demodulator_analog_replace(params.mod); + if (!params.offset_frequency) return; + demodulators[0].set_offset_frequency(params.offset_frequency); } var reconnect_timeout = false; @@ -1794,7 +1806,6 @@ function openwebrx_init() { check_top_bar_congestion(); init_header(); bookmarks = new BookmarkBar(); - parseHash(); initSliders(); } From 92254c8c4d0c87275e5d03695d378444089d31ab Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 25 Jan 2020 21:15:05 +0100 Subject: [PATCH 2/6] update hash when demodulator params change --- htdocs/openwebrx.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 4546b9af..10653465 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -558,6 +558,7 @@ function demodulator_analog_replace(subtype, for_digital) { //this function shou demodulator_add(new Demodulator_default_analog(temp_offset, subtype)); demodulator_buttons_update(); update_digitalvoice_panels("openwebrx-panel-metadata-" + subtype); + updateHash(); } Demodulator.prototype.set_offset_frequency = function(to_what) { @@ -566,6 +567,11 @@ Demodulator.prototype.set_offset_frequency = function(to_what) { this.set(); mkenvelopes(get_visible_freq_range()); tunedFrequencyDisplay.setFrequency(center_freq + to_what); + updateHash(); +} + +Demodulator.prototype.get_offset_frequency = function() { + return this.offset_frequency; } function waterfallWidth() { @@ -1525,6 +1531,16 @@ function validateHash() { return params; } +function updateHash() { + var demod = demodulators[0]; + window.location.hash = $.map({ + freq: demod.get_offset_frequency() + center_freq, + mod: demod.subtype + }, function(value, key){ + return key + '=' + value; + }).join(','); +} + function onAudioStart(success, apiType){ divlog('Web Audio API succesfully initialized, using ' + apiType + ' API, sample rate: ' + audioEngine.getSampleRate() + " Hz"); @@ -1543,11 +1559,12 @@ function onAudioStart(success, apiType){ function initialize_demodulator(initialParams) { mkscale(); var params = $.extend(initialParams || {}, validateHash()); - console.info(params); - if (!params.mod) return; - demodulator_analog_replace(params.mod); - if (!params.offset_frequency) return; - demodulators[0].set_offset_frequency(params.offset_frequency); + if (params.mod) { + demodulator_analog_replace(params.mod); + } + if (params.offset_frequency) { + demodulators[0].set_offset_frequency(params.offset_frequency); + } } var reconnect_timeout = false; @@ -1807,6 +1824,9 @@ function openwebrx_init() { init_header(); bookmarks = new BookmarkBar(); initSliders(); + window.addEventListener('hashchange', function() { + initialize_demodulator(); + }); } function initSliders() { From 4b60b7e0463d5461458c358ce458ee6ffcc4203d Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 25 Jan 2020 22:35:44 +0100 Subject: [PATCH 3/6] frequency editor on click --- htdocs/css/openwebrx.css | 19 ++++++++++++++----- htdocs/lib/FrequencyDisplay.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/htdocs/css/openwebrx.css b/htdocs/css/openwebrx.css index 556558f1..349ea4de 100644 --- a/htdocs/css/openwebrx.css +++ b/htdocs/css/openwebrx.css @@ -311,16 +311,25 @@ input[type=range]:focus::-ms-fill-upper font-style: normal; } -#webrx-actual-freq -{ +#webrx-actual-freq { width: 100%; text-align: left; - font-size: 16pt; - font-family: 'roboto-mono'; padding: 0; margin: 0; - line-height:22px; +} +#webrx-actual-freq input { + font-family: 'roboto-mono'; + width: 98%; + box-sizing: border-box; + border: 0; + padding: 0; +} + +#webrx-actual-freq, #webrx-actual-freq input { + font-size: 16pt; + font-family: 'roboto-mono'; + line-height: 22px; } #webrx-mouse-freq diff --git a/htdocs/lib/FrequencyDisplay.js b/htdocs/lib/FrequencyDisplay.js index 0353fd83..8c749ca9 100644 --- a/htdocs/lib/FrequencyDisplay.js +++ b/htdocs/lib/FrequencyDisplay.js @@ -1,8 +1,10 @@ function FrequencyDisplay(element) { this.element = $(element); this.digits = []; + this.displayContainer = $('
'); this.digitContainer = $(''); - this.element.html([this.digitContainer, $(' MHz')]); + this.displayContainer.html([this.digitContainer, $(' MHz')]); + this.element.html(this.displayContainer); this.decimalSeparator = (0.1).toLocaleString().substring(1, 2); this.setFrequency(0); } @@ -38,7 +40,7 @@ TuneableFrequencyDisplay.prototype = new FrequencyDisplay(); TuneableFrequencyDisplay.prototype.setupEvents = function() { var me = this; - this.element.on('wheel', function(e){ + me.element.on('wheel', function(e){ e.preventDefault(); e.stopPropagation(); @@ -53,7 +55,30 @@ TuneableFrequencyDisplay.prototype.setupEvents = function() { l(newFrequency); }); }); - this.listeners = []; + me.listeners = []; + me.element.on('click', function(){ + var input = $(''); + var submit = function(){ + var freq = parseInt(input.val()); + if (!isNaN(freq)) { + me.listeners.forEach(function(l) { + l(freq); + }); + } + input.remove(); + me.displayContainer.show(); + }; + input.on('blur', submit).on('keyup', function(e){ + if (e.keyCode == 13) return submit(); + }); + input.on('click', function(e){ + e.stopPropagation(); + }); + input.val(me.frequency); + me.displayContainer.hide(); + me.element.append(input); + input.focus(); + }); }; TuneableFrequencyDisplay.prototype.onFrequencyChange = function(listener){ From 8fc981c8a07f49f03fb5242dc05b92ca51be66eb Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 25 Jan 2020 22:47:47 +0100 Subject: [PATCH 4/6] use static elements --- htdocs/index.html | 4 +-- htdocs/lib/FrequencyDisplay.js | 61 ++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index d9296c9a..3fabf734 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -144,8 +144,8 @@
-
---.--- MHz
-
---.--- MHz
+
+