more reliable JS + fixed broken second marks

master
Ondřej Hruška 9 years ago
parent 09aa63e5a0
commit f3611453ad
  1. 2
      esp_meas.pro.user
  2. 2
      html/css/app.css
  3. 4
      html/js/all.js
  4. 6
      html/pages/sgm.html
  5. 2
      html_src/css/app.css
  6. 2
      html_src/css/app.css.map
  7. 2
      html_src/js-src/lib/chibi.js
  8. 10
      html_src/js-src/notif.js
  9. 47
      html_src/js-src/page_spectrogram.js
  10. 28
      html_src/js-src/page_waveform.js
  11. 4
      html_src/js/all.js
  12. 2
      html_src/js/all.js.map
  13. 6
      html_src/page_spectrogram.php
  14. 6
      html_src/sass/pages/_wfm.scss
  15. 8
      user/page_waveform.c
  16. 3
      user/sampling.c

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.1, 2016-04-05T20:46:29. --> <!-- Written by QtCreator 3.6.1, 2016-04-05T21:58:52. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -45,7 +45,7 @@
<label for="tile-x">Tile</label> <label for="tile-x">Tile</label>
<input id="tile-x" type="number" min=1 step=1 value=4> <input id="tile-x" type="number" min=1 step=1 value=4>
× ×
<input id="tile-y" type="number" min=1 step=1 value=4> <input id="tile-y" type="number" min=1 step=1 value=1>
</div> </div>
<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> <label for="freq">f<sub>bw</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
@ -53,8 +53,8 @@
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
<label for="interval">t<sub>s</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max" style="font-weight:normal;">(ms)</span></label> <label for="interval">Interval <span class="mq-tablet-max" style="font-weight:normal;">(ms)</span></label>
<input id="interval" type="number" value="500" step=100 min=0> <input id="interval" type="number" value="0" step=100 min=0>
<span class="mq-normal-min">ms</span> <span class="mq-normal-min">ms</span>
</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

@ -628,6 +628,8 @@
query = null; query = null;
} }
// FIXME the XHR sometimes seemingly silently fails
xhr = new XMLHttpRequest(); // we dont support IE < 9 xhr = new XMLHttpRequest(); // we dont support IE < 9
if (xhr) { if (xhr) {

@ -2,19 +2,25 @@ var notify = (function () {
var nt = {}; var nt = {};
var sel = '#notif'; var sel = '#notif';
var hideTmeo1;
var hideTmeo2;
nt.show = function (message, timeout) { nt.show = function (message, timeout) {
$(sel).html(message); $(sel).html(message);
modal.show(sel); modal.show(sel);
clearTimeout(hideTmeo1);
clearTimeout(hideTmeo2);
if (!_.isUndefined(timeout)) { if (!_.isUndefined(timeout)) {
setTimeout(nt.hide, timeout); hideTmeo1 = setTimeout(nt.hide, timeout);
} }
}; };
nt.hide = function () { nt.hide = function () {
var $m = $(sel); var $m = $(sel);
$m.removeClass('visible'); $m.removeClass('visible');
setTimeout(function () { hideTmeo2 = setTimeout(function () {
$m.addClass('hidden'); $m.addClass('hidden');
}, 250); // transition time }, 250); // transition time
}; };

@ -82,10 +82,11 @@ var page_spectrogram = (function () {
} }
function shiftSg() { function shiftSg() {
var imageData = ctx.getImageData(plot.x+plot.dx, plot.y, plot.w-plot.dx, plot.h+6); var imageData = ctx.getImageData(plot.x+plot.dx, plot.y, plot.w-plot.dx, plot.h+10);
ctx.fillStyle = 'black'; ctx.fillStyle = 'black';
ctx.fillRect(plot.x, plot.y, plot.w, plot.h); ctx.fillRect(plot.x, plot.y, plot.w, plot.h);
ctx.clearRect(plot.x, plot.y+plot.h+1, plot.w, 10); // clear the second marks box
ctx.putImageData(imageData, plot.x, plot.y); ctx.putImageData(imageData, plot.x, plot.y);
} }
@ -123,7 +124,7 @@ var page_spectrogram = (function () {
} }
// mark every 10 s // mark every 10 s
console.log('remain',msElapsed(lastMarkMs)); //console.log('remain',msElapsed(lastMarkMs));
if (msElapsed(lastMarkMs) >= 950) { if (msElapsed(lastMarkMs) >= 950) {
lastMarkMs = msNow(); lastMarkMs = msNow();
@ -138,8 +139,6 @@ var page_spectrogram = (function () {
ctx.moveTo(plot.x+plot.w-.5, plot.y+plot.h+1); ctx.moveTo(plot.x+plot.w-.5, plot.y+plot.h+1);
ctx.lineTo(plot.x+plot.w-.5, plot.y+plot.h+1+(long?6:2)); ctx.lineTo(plot.x+plot.w-.5, plot.y+plot.h+1+(long?6:2));
ctx.stroke(); ctx.stroke();
} else {
ctx.clearRect(plot.x+plot.w-1, plot.y+plot.h+1,2,10);
} }
} }
@ -231,29 +230,25 @@ var page_spectrogram = (function () {
var totalBins = (plot.h / plot.dy); var totalBins = (plot.h / plot.dy);
var totalHz = totalBins*perBin; var totalHz = totalBins*perBin;
console.log("perbin=",perBin,"totalBins=",totalBins,"totalHz=",totalHz); //console.log("perbin=",perBin,"totalBins=",totalBins,"totalHz=",totalHz);
var step; var step;
var steps = [ // get the best step size
[200, 10], var steps = [10, 25, 50];
[1000, 50], var multiplier = 1;
[3000, 250], var suc = false;
[5000, 500], do {
[10000, 1000], for (var i = 0; i < steps.length; i++) {
[25000, 2500], if ((totalHz / (steps[i] * multiplier)) <= 21) {
[50000, 5000], step = (steps[i] * multiplier);
[100000, 10000], suc = true;
[500000, 50000], break;
[1000000, 100000], }
[1/0, 250000],
];
for(var i = 0; i <= steps.length; i++) {
if (totalHz <= steps[i][0]) {
step = steps[i][1];
break;
} }
} if (suc) break;
multiplier *= 10;
} while (true);
step = step/perBin; step = step/perBin;
@ -263,8 +258,6 @@ var page_spectrogram = (function () {
ctx.strokeStyle = 'white'; ctx.strokeStyle = 'white';
ctx.textAlign = 'left'; ctx.textAlign = 'left';
var kilos = totalHz >= 10000;
// labels and dashes // labels and dashes
for(var i = 0; i <= totalBins+step; i+= step) { for(var i = 0; i <= totalBins+step; i+= step) {
if (i >= totalBins) { if (i >= totalBins) {
@ -332,13 +325,13 @@ var page_spectrogram = (function () {
var count = +$('#count').val(); var count = +$('#count').val();
var tile = Math.max(1, plot.h/(count/2)); var tile = Math.max(1, plot.h/(count/2));
$('#tile-x').val(tile); $('#tile-x').val(Math.max(4, tile)); // use width 4 for smaller by default (rolls more nicely)
$('#tile-y').val(tile); $('#tile-y').val(tile);
}); });
// chain Y with X // chain Y with X
$('#tile-y').on('change', function() { $('#tile-y').on('change', function() {
$('#tile-x').val($(this).val()); $('#tile-x').val(Math.max(4,$(this).val()));
}); });
$('#go-btn').on('click', function() { $('#go-btn').on('click', function() {

@ -13,6 +13,8 @@ var page_waveform = (function () {
var zoomSavedX, zoomSavedY; var zoomSavedX, zoomSavedY;
var readXhr; // read xhr
var opts = { var opts = {
count: 0, // sample count count: 0, // sample count
freq: 0 // sampling freq freq: 0 // sampling freq
@ -145,26 +147,17 @@ var page_waveform = (function () {
if (status != 200) { if (status != 200) {
errorMsg("Request failed.", 1000); errorMsg("Request failed.", 1000);
if (autoReload)
toggleAutoReload(); // turn it off.
} else { } else {
var j = JSON.parse(resp); var j = JSON.parse(resp);
if (!j.success) { if (!j.success) {
errorMsg("Sampling failed.", 1000); errorMsg("Sampling failed.", 1000);
} else {
if (autoReload) buildChart(j);
toggleAutoReload(); // turn it off.
return;
} }
buildChart(j);
if (autoReload)
arTimeout = setTimeout(requestReload, Math.max(0, autoReloadTime - msElapsed(lastLoadMs)));
} }
if (autoReload)
arTimeout = setTimeout(requestReload, Math.max(0, autoReloadTime - msElapsed(lastLoadMs)));
} }
function readInputs() { function readInputs() {
@ -173,7 +166,10 @@ var page_waveform = (function () {
} }
function requestReload() { function requestReload() {
if (readoutPending) return false; if (readoutPending) {
errorMsg("Request already pending - aborting.");
readXhr.abort();
}
readoutPending = true; readoutPending = true;
lastLoadMs = msNow(); lastLoadMs = msNow();
@ -181,7 +177,7 @@ var page_waveform = (function () {
var n = opts.count; var n = opts.count;
var fs = opts.freq; 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)); readXhr = $().get(url, onRxData, estimateLoadTime(fs,n));
return true; return true;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -22,7 +22,7 @@
<label for="tile-x">Tile</label> <label for="tile-x">Tile</label>
<input id="tile-x" type="number" min=1 step=1 value=4> <input id="tile-x" type="number" min=1 step=1 value=4>
× ×
<input id="tile-y" type="number" min=1 step=1 value=4> <input id="tile-y" type="number" min=1 step=1 value=1>
</div> </div>
<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> <label for="freq">f<sub>bw</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max nb">(Hz)</span></label>
@ -30,8 +30,8 @@
<span class="mq-normal-min">Hz</span> <span class="mq-normal-min">Hz</span>
</div> </div>
<div> <div>
<label for="interval">t<sub>s</sub> <span class="mq-normal-min nb">=</span><span class="mq-tablet-max" style="font-weight:normal;">(ms)</span></label> <label for="interval">Interval <span class="mq-tablet-max" style="font-weight:normal;">(ms)</span></label>
<input id="interval" type="number" value="500" step=100 min=0> <input id="interval" type="number" value="0" step=100 min=0>
<span class="mq-normal-min">ms</span> <span class="mq-normal-min">ms</span>
</div> </div>
<div> <div>

@ -27,9 +27,15 @@
} }
} }
// -- spectrogram --
#tile-cfg input { #tile-cfg input {
width: 3em; width: 3em;
} }
#interval {
width: 4.5em;
}
} }
.Box.chartbox { .Box.chartbox {

@ -42,8 +42,14 @@ static int FLASH_FN tplSamplesJSON(MEAS_FORMAT fmt, HttpdConnData *connData, cha
tplReadSamplesJSON_state *st = *arg; tplReadSamplesJSON_state *st = *arg;
if (token == NULL) { if (token == NULL) {
// end of template, cleanup // end of template, or connection closed.
if (st != NULL) free(st); if (st != NULL) free(st);
// make sure resources are freed
if (!meas_is_closed()) {
meas_close();
}
return HTTPD_CGI_DONE; // cleanup return HTTPD_CGI_DONE; // cleanup
} }

@ -226,8 +226,7 @@ bool FLASH_FN meas_request_data(MEAS_FORMAT format, uint16_t count, uint32_t fre
info("Requesting data capture - %d samples @ %d Hz, fmt %d.", count, freq, format); info("Requesting data capture - %d samples @ %d Hz, fmt %d.", count, freq, format);
if (rd.pending) { if (rd.pending) {
error("Acquire request already in progress."); warn("Acquire request already in progress; shouldn't happen, IGNORING");
return false;
} }
if (sbmp_ep_handshake_status(dlnk_ep) != SBMP_HSK_SUCCESS) { if (sbmp_ep_handshake_status(dlnk_ep) != SBMP_HSK_SUCCESS) {

Loading…
Cancel
Save