From 807b18c08eade9c0f5c695930d6d69accef380c7 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 31 Oct 2012 17:39:09 +0100 Subject: fix scroll extents Signed-off-by: Andy Green --- aepd/aepd.h | 1 + aepd/main.c | 5 +++ aepd/share/aepscope.html | 94 ++++++++++++++++++++++++++--------------------- aepd/websocket-protocol.c | 4 +- 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/aepd/aepd.h b/aepd/aepd.h index df6763b..0e013af 100644 --- a/aepd/aepd.h +++ b/aepd/aepd.h @@ -54,6 +54,7 @@ struct aepd_shared { int chans; unsigned long fifo_pos; double fifo_head_time; + double fifo_tail_time; unsigned long modulo_integer_chan_size; int stop_flag; double trigger_level; diff --git a/aepd/main.c b/aepd/main.c index b060361..080381d 100644 --- a/aepd/main.c +++ b/aepd/main.c @@ -45,6 +45,8 @@ void zero_fifo(void) aepd_shared->modulo_integer_chan_size = (MAX_FIFO_EXTENT / (aepd_shared->chans * sizeof(double) * 3)) * (aepd_shared->chans * sizeof(double) * 3); + aepd_shared->fifo_head_time = 0; + aepd_shared->fifo_tail_time = 0; } int add_fifo(void *data, unsigned int length) @@ -316,6 +318,9 @@ int main(int argc, char *argv[]) add_fifo(&sam[0], aepd_interface_result->chans * 3 * sizeof(double)); aepd_shared->fifo_head_time = aepd_interface_result->samtime; + if ((aepd_shared->fifo_head_time - aepd_shared->fifo_tail_time) > max_fifo_extent_seconds) + aepd_shared->fifo_tail_time = aepd_shared->fifo_head_time - max_fifo_extent_seconds; + if (aepd_shared->chans != aepd_interface_result->chans) { aepd_shared->chans = aepd_interface_result->chans; diff --git a/aepd/share/aepscope.html b/aepd/share/aepscope.html index aa63d9c..68427ef 100644 --- a/aepd/share/aepscope.html +++ b/aepd/share/aepscope.html @@ -212,6 +212,8 @@ var order; var do_title = 0; var sent_time = 0; var peak_time = 0; +var ring_start_time = 0; +var ring_head_time = 0; var viewport_offset_time = 0; var dirty = 1; @@ -256,12 +258,12 @@ function event_wheel(e) // " Raw Value: " + raw + " Normalized Value: " + normal; f = viewport_offset_time + (normal / 3) * rates[rate] * 0.0001 * xlen / 10; - if (f < (-peak_time + (rates[rate] * 0.0001 * xlen) - 0.0001) || f > 0) + if (f < (-ring_head_time + ((rates[rate] * 0.0001 * xlen))) || f > 0) return cancelEvent(e); viewport_offset_time = f; -// document.getElementById("val").textContent = viewport_offset_time.toFixed(4)+" "+(-peak_time).toFixed(4); +// document.getElementById("val").textContent = viewport_offset_time.toFixed(4)+" "+(-ring_head_time).toFixed(4); update_options(); @@ -348,6 +350,7 @@ function event_drag_end(e) { caliper_drag_index = -1; trigger_drag = 0; + dirty = 1; } function update_measure() @@ -634,7 +637,7 @@ function channel_list_changed() function conn_retry() { - var r1, r2, r3, x, y, chan, z, block, channel_data = 0; + var r1, r2, r3, x, y, chan, z, block, channel_data = 0, tpt; if (connection) return; @@ -676,8 +679,10 @@ function conn_retry() f = msg.data.substr(1); y = f.split(' '); sent_time = parseFloat(y[0]); - peak_time = sent_time; // + ((rates[rate] * 0.0001) * xlen); - running = y[1]; + tpt = sent_time; // + ((rates[rate] * 0.0001) * xlen); + ring_start_time = parseFloat(y[1]); + ring_head_time = parseFloat(y[2]); + running = y[3]; if (running != 0) document.getElementById("run").checked = true; else @@ -828,7 +833,7 @@ function conn_retry() if (ring_head == ring_size) ring_head = 0; - peak_time += (rates[rate] * 0.0001); + tpt += (rates[rate] * 0.0001); if (loading) loading--; @@ -836,7 +841,8 @@ function conn_retry() block++; } - + if (!channel_data) + peak_time = tpt; if (!channel_data && do_title) channel_list_changed(); @@ -937,7 +943,7 @@ function units3(n) { function show(cv) { var n, p, y, chan, q, z, peak, ro, rx, extent, x2, xx, q1, - effective_channels; + effective_channels, eff_peak_time; if (!connection || !ring_size) return; @@ -945,6 +951,8 @@ function show(cv) if (!dirty) return; + eff_peak_time = peak_time; + dirty = 0; last_running = running; @@ -973,22 +981,26 @@ function show(cv) x2 = xlen + y_axis_width; extent = rates[rate] * 0.0001 * xlen; - ro = peak_time + viewport_offset_time; + ro = (ring_head_time - ring_start_time) + viewport_offset_time; rx = ro - extent; if (rx < 0) rx = 0; - x = (x2 * (rx / peak_time)); - xx = x2 * (extent / peak_time); + x = (x2 * (rx / (ring_head_time - ring_start_time))); + xx = x2 * (extent / (ring_head_time - ring_start_time)); if (xx < 10) { // minimum width x -= (10 - xx) / 2; xx = 10; } -// document.getElementById("val").textContent = peak_time+" "+ro+" "+extent+" "+rx+" "+x; +// document.getElementById("val").textContent = (ring_head_time - ring_start_time)+" "+ro+" "+extent+" "+rx+" "+x; ctx.fillRect(x, ylen + x_axis_height + caliper_headroom - 12, xx, 8); + /* + * waveform drawing + */ + q1 = ring_head; last_head = q1; @@ -1017,10 +1029,6 @@ function show(cv) for (n = xlen - 1; n >= 0; n--) { - q--; - if (q < 0) - q = ring_size - 1; - ctx.beginPath(); if (q >= 0) @@ -1037,6 +1045,11 @@ function show(cv) height[n] -= p; } ctx.stroke(); + + q--; + if (q < 0) + q = ring_size - 1; + } chan++; @@ -1044,7 +1057,7 @@ function show(cv) /* x (time) axis marks */ - ro = peak_time + viewport_offset_time; + ro = eff_peak_time /* + viewport_offset_time; */ r = ro; /* rates[rate] * 0.0001s per pixel */ time_pp = rates[rate] * 0.0001; @@ -1061,29 +1074,28 @@ function show(cv) while (r >= limit) { var f; - - if (r >= 0) { - x = xlen - (xlen * ((ro - r) / (ro - limit))); - - f = r.toFixed(sigs[rate]); - if (sigs[rate]) { - while (f.charAt(f.length - 1) == '0') - f = f.substring(0, f.length - 1); - if (f.charAt(f.length - 1) == '.') - f = f.substring(0, f.length - 1); - } - ctx.lineWidth = 1; - if ( r.toFixed(0) == r) - ctx.lineWidth = 2; - - if (x < xlen) { - ctx.beginPath(); - ctx.moveTo(x, caliper_headroom + ylen); - ctx.lineTo(x, caliper_headroom + 1); - ctx.stroke(); - } - ctx.fillText(f, x, caliper_headroom + ylen + 16 - 2); + + x = xlen - (xlen * ((ro - r) / (ro - limit))); + + f = r.toFixed(sigs[rate]); + if (sigs[rate]) { + while (f.charAt(f.length - 1) == '0') + f = f.substring(0, f.length - 1); + if (f.charAt(f.length - 1) == '.') + f = f.substring(0, f.length - 1); } + ctx.lineWidth = 1; + if ( r.toFixed(0) == r) + ctx.lineWidth = 2; + + if (x < xlen) { + ctx.beginPath(); + ctx.moveTo(x, caliper_headroom + ylen); + ctx.lineTo(x, caliper_headroom + 1); + ctx.stroke(); + } + ctx.fillText(f, x, caliper_headroom + ylen + 16 - 2); + r -= interval; } @@ -1195,8 +1207,8 @@ function update_options() localStorage["aepd.rate"] = document.getElementById("rate").value; document.getElementById("tb").textContent = units(xlen * rates[rate] * 0.0001)+"s"; - if (viewport_offset_time < (-peak_time + (rates[rate] * 0.0001 * xlen) - 0.0001)) - viewport_offset_time = (-peak_time + (rates[rate] * 0.0001 * xlen) - 0.0001); + if (viewport_offset_time < (-ring_head_time /*+ ((rates[rate] * 0.0001 * xlen)) - 0.0001*/)) + viewport_offset_time = (-ring_head_time /*+ ((rates[rate] * 0.0001 * xlen)) - 0.0001*/); if (viewport_offset_time > 0) viewport_offset_time = 0; diff --git a/aepd/websocket-protocol.c b/aepd/websocket-protocol.c index df9d96a..a59df63 100644 --- a/aepd/websocket-protocol.c +++ b/aepd/websocket-protocol.c @@ -214,7 +214,7 @@ bad_caliper: } /* - * do we need to isse a sync timestamp? + * do we need to issue a sync timestamp? */ if (pss->issue_timestamp && aepd_shared->chans) { @@ -236,7 +236,7 @@ bad_caliper: extent /= aepd_shared->chans * sizeof(double) * 3; - p += sprintf(p, "t%f %d", aepd_shared->fifo_head_time - ((double)extent * 0.0001), aepd_shared->stop_flag ^ 1); + p += sprintf(p, "t%f %f %f %d", aepd_shared->fifo_head_time - ((double)extent * 0.0001), aepd_shared->fifo_tail_time, aepd_shared->fifo_head_time, aepd_shared->stop_flag ^ 1); goto send; } -- cgit v1.2.3