adjustable sg, better reliability, use f_bw in sg and fft

master
Ondřej Hruška 9 years ago
parent 55ed773298
commit b9727dfef4
  1. 2
      html/css/app.css
  2. 6
      html/js/all.js
  3. 16
      html/pages/fft.html
  4. 6
      html/pages/wfm.html
  5. 2
      html_src/css/app.css
  6. 2
      html_src/css/app.css.map
  7. 10
      html_src/js-src/app.js
  8. 19
      html_src/js-src/lib/chibi.js
  9. 34
      html_src/js-src/page_spectrogram.js
  10. 39
      html_src/js-src/page_waveform.js
  11. 8
      html_src/js-src/utils.js
  12. 6
      html_src/js/all.js
  13. 2
      html_src/js/all.js.map
  14. 16
      html_src/page_fft.php
  15. 19
      html_src/page_spectrogram.php
  16. 6
      html_src/page_waveform.php
  17. 4
      html_src/sass/app.scss
  18. 4
      html_src/sass/form/_select.scss

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -30,11 +30,11 @@
<label for="count">Bins</label> <label for="count">Bins</label>
<label for="count" class="select-wrap"> <label for="count" class="select-wrap">
<select name="count" id="count"> <select name="count" id="count">
<!-- <option value="16">8--> <option value="16">8
<!-- <option value="32">16--> <option value="32">16
<!-- <option value="64">32--> <option value="64">32
<!-- <option value="128">64--> <option value="128">64
<!-- <option value="256">128--> <option value="256">128
<option value="512">256 <option value="512">256
<option value="1024">512 <option value="1024">512
<option value="2048" selected>1024 <option value="2048" selected>1024
@ -42,8 +42,8 @@
</label> </label>
</div> </div>
<div> <div>
<label for="freq">Rate <span class="mq-tablet-max" style="font-weight:normal;">(Hz)</span></label> <label for="freq">f<sub>bw</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
<input id="freq" type="number" value="4096"> <input id="freq" type="number" value="2048">
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
@ -73,7 +73,7 @@
</tr> </tr>
</table> </table>
<div class="ar"><!-- auto reload --> <div class="ar"><!-- auto reload -->
<input type="number" id="ar-time" step="0.5" value="1" min="0">&nbsp;s <input type="number" id="ar-time" step="100" value="1000" min="0">&nbsp;ms
<input type="button" id="ar-btn" class="btn-blue narrow" value="Auto"> <input type="button" id="ar-btn" class="btn-blue narrow" value="Auto">
</div> </div>
</div> </div>

@ -31,8 +31,8 @@
<input id="count" type="number" value="500"> <input id="count" type="number" value="500">
</div> </div>
<div> <div>
<label for="freq">Rate <span class="mq-tablet-max" style="font-weight:normal;">(Hz)</span></label> <label for="freq">f<sub>s</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
<input id="freq" type="number" value="4000"> <input id="freq" type="number" value="2048">
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
@ -62,7 +62,7 @@
</tr> </tr>
</table> </table>
<div class="ar"><!-- auto reload --> <div class="ar"><!-- auto reload -->
<input type="number" id="ar-time" step="0.5" value="1" min="0">&nbsp;s <input type="number" id="ar-time" step="100" value="1000" min="0">&nbsp;ms
<input type="button" id="ar-btn" class="btn-blue narrow" value="Auto"> <input type="button" id="ar-btn" class="btn-blue narrow" value="Auto">
</div> </div>
</div> </div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -23,12 +23,18 @@ $().ready(function () {
$('input[type=number]').on('mousewheel', function(e) { $('input[type=number]').on('mousewheel', function(e) {
var val = +$(this).val(); var val = +$(this).val();
var step = +($(this).attr('step') || 1); var step = +($(this).attr('step') || 1);
var min = $(this).attr('min');
var max = $(this).attr('max');
if(e.wheelDelta > 0) { if(e.wheelDelta > 0) {
val += step; val += step;
} else { } else {
val -= step; val -= step;
} }
if (!_.isUndefined(min)) val = Math.max(val, min);
if (!_.isUndefined(max)) val = Math.min(val, max);
$(this).val(val); $(this).val(val);
e.preventDefault();
}); });
modal.init(); modal.init();
@ -36,6 +42,6 @@ $().ready(function () {
}); });
function errorMsg(msg) { function errorMsg(msg, time) {
notify.show(msg, 3000); notify.show(msg, time || 3000);
} }

@ -513,7 +513,7 @@
// Get/Set form element values // Get/Set form element values
cb.val = function (value) { cb.val = function (value) {
var values, i, j; var values, i, j;
if (value || value === '') { if (!_.isUndefined(value)) { // FIXED A BUG HERE
nodeLoop(function (elm) { nodeLoop(function (elm) {
switch (elm.nodeName) { switch (elm.nodeName) {
case 'SELECT': case 'SELECT':
@ -608,11 +608,10 @@
}; };
// Basic XHR 1, no file support. Shakes fist at IE // Basic XHR 1, no file support. Shakes fist at IE
cb.ajax = function (url, method, callback, options) { // if options is a number, it's timeout in ms cb.ajax = function (url, method, callback, options) { // if options is a number, it's timeout in ms
var xhr, var xhr;
query = serializeData(nodes), var query = serializeData(nodes);
type = (method) ? method.toUpperCase() : 'GET', var type = (method) ? method.toUpperCase() : 'GET';
timestamp = '_ts=' + (+new Date()), var abortTmeo;
abortTmeo;
if (_.isNumber(options)) options = {timeout: options}; if (_.isNumber(options)) options = {timeout: options};
@ -622,7 +621,7 @@
loader: true, loader: true,
}, options); }, options);
console.log('ajax to = ' + opts.timeout); //console.log('ajax to = ' + opts.timeout);
if (query && (type === 'GET')) { if (query && (type === 'GET')) {
url += (url.indexOf('?') === -1) ? '?' + query : '&' + query; url += (url.indexOf('?') === -1) ? '?' + query : '&' + query;
@ -633,8 +632,10 @@
if (xhr) { if (xhr) {
// prevent caching // prevent caching
if (opts.nocache) if (opts.nocache) {
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp; var ts = (+(+new Date())).toString(36);
url += ((url.indexOf('?') === -1) ? '?' : '&') + '_=' + ts;
}
if (opts.loader) if (opts.loader)
$('#loader').addClass('show'); $('#loader').addClass('show');

@ -13,14 +13,20 @@ var page_spectrogram = (function () {
dy: 1 dy: 1
}; };
var opts = {
interval: 0,
sampCount: 0,
binCount: 0,
freq:0
};
var interval = 1000; var interval = 1000;
var running = false; var running = false;
var readTimeout; // timer var readTimeout; // timer
var readoutPending; var readoutPending;
var readXhr; var readXhr;
var sampCount = 1024; var lastLoadMs;
var binCount = sampCount/2;
var colormap = { var colormap = {
r: [ r: [
@ -83,9 +89,10 @@ var page_spectrogram = (function () {
function drawSg(col) { function drawSg(col) {
shiftSg(); shiftSg();
for (var i = 0; i < binCount; i++) { var bc = opts.sampCount/2;
for (var i = 0; i < bc; i++) {
// resolve color from the value // resolve color from the value
var y = binCount - i; var y = bc - i - 1;
var clr; var clr;
if (i > col.length) { if (i > col.length) {
@ -109,17 +116,17 @@ var page_spectrogram = (function () {
// display // display
drawSg(j.samples); drawSg(j.samples);
} else { } else {
errorMsg("Sampling failed."); errorMsg("Sampling failed.", 1000);
} }
} catch(e) { } catch(e) {
errorMsg(e); errorMsg(e);
} }
} else { } else {
errorMsg("Request failed."); errorMsg("Request failed.", 1000);
} }
if (running) if (running)
readTimeout = setTimeout(requestData, interval); // TODO should actually compute time remaining, this adds interval to the request time. readTimeout = setTimeout(requestData, Math.max(0, opts.interval - msElapsed(lastLoadMs))); // TODO should actually compute time remaining, this adds interval to the request time.
} }
function requestData() { function requestData() {
@ -128,11 +135,13 @@ var page_spectrogram = (function () {
readXhr.abort(); readXhr.abort();
} }
readoutPending = true; readoutPending = true;
lastLoadMs = msNow();
var fs = $('#freq').val(); var fs = opts.freq;
var url = _root+'/measure/fft?n='+sampCount+'&fs='+fs; var n = opts.sampCount;
var url = _root+'/measure/fft?n='+n+'&fs='+fs;
readXhr = $().get(url, onRxData, estimateLoadTime(fs,sampCount)); readXhr = $().get(url, onRxData, estimateLoadTime(fs,n));
return true; return true;
} }
@ -145,7 +154,10 @@ var page_spectrogram = (function () {
ctx.fillRect(plot.x, plot.y, plot.w, plot.h); ctx.fillRect(plot.x, plot.y, plot.w, plot.h);
$('#go-btn').on('click', function() { $('#go-btn').on('click', function() {
interval = +$('#interval').val(); // ms opts.interval = +$('#interval').val(); // ms
opts.freq = $('#freq').val()*2;
opts.sampCount = $('#count').val();
plot.dx = plot.dy = plot.h/(opts.sampCount/2);
running = !running; running = !running;
if (running) { if (running) {

@ -9,8 +9,15 @@ var page_waveform = (function () {
var autoReloadTime = 1; var autoReloadTime = 1;
var arTimeout = -1; var arTimeout = -1;
var lastLoadMs;
var zoomSavedX, zoomSavedY; var zoomSavedX, zoomSavedY;
var opts = {
count: 0, // sample count
freq: 0 // sampling freq
};
function buildChart(j) { function buildChart(j) {
// Build the chart // Build the chart
var mql = window.matchMedia('screen and (min-width: 544px)'); var mql = window.matchMedia('screen and (min-width: 544px)');
@ -137,7 +144,7 @@ var page_waveform = (function () {
readoutPending = false; readoutPending = false;
if (status != 200) { if (status != 200) {
errorMsg("Request failed."); errorMsg("Request failed.", 1000);
if (autoReload) if (autoReload)
toggleAutoReload(); // turn it off. toggleAutoReload(); // turn it off.
@ -145,7 +152,7 @@ var page_waveform = (function () {
} else { } else {
var j = JSON.parse(resp); var j = JSON.parse(resp);
if (!j.success) { if (!j.success) {
errorMsg("Sampling / readout failed."); errorMsg("Sampling failed.", 1000);
if (autoReload) if (autoReload)
toggleAutoReload(); // turn it off. toggleAutoReload(); // turn it off.
@ -156,18 +163,23 @@ var page_waveform = (function () {
buildChart(j); buildChart(j);
if (autoReload) if (autoReload)
arTimeout = setTimeout(requestReload, autoReloadTime); arTimeout = setTimeout(requestReload, Math.max(0, autoReloadTime - msElapsed(lastLoadMs)));
} }
} }
function readInputs() {
opts.count = $('#count').val();
opts.freq = $('#freq').val() * (dataFormat == 'fft' ? 2 : 1); // bw 2x -> f_s
}
function requestReload() { function requestReload() {
if (readoutPending) return false; if (readoutPending) return false;
readoutPending = true; readoutPending = true;
lastLoadMs = msNow();
var n = $('#count').val(); var n = opts.count;
var fs = $('#freq').val(); var fs = opts.freq;
var url = _root+'/measure/'+dataFormat+'?n='+n+'&fs='+fs; var url = _root+'/measure/'+dataFormat+'?n='+n+'&fs='+fs;
$().get(url, onRxData, estimateLoadTime(fs,n)); $().get(url, onRxData, estimateLoadTime(fs,n));
@ -175,7 +187,9 @@ var page_waveform = (function () {
} }
function toggleAutoReload() { function toggleAutoReload() {
autoReloadTime = +$('#ar-time').val() * 1000; // ms autoReloadTime = +$('#ar-time').val(); // ms
readInputs();
autoReload = !autoReload; autoReload = !autoReload;
if (autoReload) { if (autoReload) {
@ -194,13 +208,16 @@ var page_waveform = (function () {
// --- Load data --- // --- Load data ---
dataFormat = format; dataFormat = format;
// initial function onLoadClick() {
// requestReload(); readInputs();
requestReload();
}
$('#load').on('click', onLoadClick);
$('#load').on('click', requestReload);
$('#count,#freq').on('keyup', function (e) { $('#count,#freq').on('keyup', function (e) {
if (e.which == 13) { if (e.which == 13) {
requestReload(); onLoadClick();
} }
}); });

@ -11,6 +11,14 @@ function estimateLoadTime(fs, n) {
return (1000/fs)*n+1500; return (1000/fs)*n+1500;
} }
function msNow() {
return +(new Date);
}
function msElapsed(start) {
return msNow() - start;
}
/** /**
* Perform a substitution in the given string. * Perform a substitution in the given string.
* *

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -7,11 +7,11 @@
<label for="count">Bins</label> <label for="count">Bins</label>
<label for="count" class="select-wrap"> <label for="count" class="select-wrap">
<select name="count" id="count"> <select name="count" id="count">
<!-- <option value="16">8--> <option value="16">8
<!-- <option value="32">16--> <option value="32">16
<!-- <option value="64">32--> <option value="64">32
<!-- <option value="128">64--> <option value="128">64
<!-- <option value="256">128--> <option value="256">128
<option value="512">256 <option value="512">256
<option value="1024">512 <option value="1024">512
<option value="2048" selected>1024 <option value="2048" selected>1024
@ -19,8 +19,8 @@
</label> </label>
</div> </div>
<div> <div>
<label for="freq">Rate <span class="mq-tablet-max" style="font-weight:normal;">(Hz)</span></label> <label for="freq">f<sub>bw</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
<input id="freq" type="number" value="4096"> <input id="freq" type="number" value="2048">
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
@ -50,7 +50,7 @@
</tr> </tr>
</table> </table>
<div class="ar"><!-- auto reload --> <div class="ar"><!-- auto reload -->
<input type="number" id="ar-time" step="0.5" value="1" min="0">&nbsp;s <input type="number" id="ar-time" step="100" value="1000" min="0">&nbsp;ms
<input type="button" id="ar-btn" class="btn-blue narrow" value="Auto"> <input type="button" id="ar-btn" class="btn-blue narrow" value="Auto">
</div> </div>
</div> </div>

@ -4,8 +4,23 @@
<div class="Box center" id="samp-ctrl"> <div class="Box center" id="samp-ctrl">
<div> <div>
<label for="freq">Rate <span class="mq-tablet-max" style="font-weight:normal;">(Hz)</span></label> <label for="count">Bins</label>
<input id="freq" type="number" value="4096"> <label for="count" class="select-wrap">
<select name="count" id="count">
<option value="16">8
<option value="32">16
<option value="64">32
<option value="128">64
<option value="256">128
<option value="512">256
<option value="1024" selected>512
<!-- <option value="2048" selected>1024-->
</select>
</label>
</div>
<div>
<label for="freq">f<sub>bw</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
<input id="freq" type="number" value="2048">
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>

@ -8,8 +8,8 @@
<input id="count" type="number" value="500"> <input id="count" type="number" value="500">
</div> </div>
<div> <div>
<label for="freq">Rate <span class="mq-tablet-max" style="font-weight:normal;">(Hz)</span></label> <label for="freq">f<sub>s</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
<input id="freq" type="number" value="4000"> <input id="freq" type="number" value="2048">
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
@ -39,7 +39,7 @@
</tr> </tr>
</table> </table>
<div class="ar"><!-- auto reload --> <div class="ar"><!-- auto reload -->
<input type="number" id="ar-time" step="0.5" value="1" min="0">&nbsp;s <input type="number" id="ar-time" step="100" value="1000" min="0">&nbsp;ms
<input type="button" id="ar-btn" class="btn-blue narrow" value="Auto"> <input type="button" id="ar-btn" class="btn-blue narrow" value="Auto">
</div> </div>
</div> </div>

@ -38,6 +38,10 @@ $c-form-highlight-a: #28bc65;
display: none; display: none;
} }
.nb {
font-weight: normal;
}
@import "layout/index"; @import "layout/index";
@import "form/index"; @import "form/index";

@ -10,8 +10,8 @@ select {
appearance: none; appearance: none;
cursor: pointer; cursor: pointer;
line-height: 1.4em; line-height: 1.2em;
padding: 3.5px; //padding: 3.5px;
padding-right: 1em; padding-right: 1em;

Loading…
Cancel
Save