Skip to content

Commit 592794b

Browse files
committed
handling arduion resets
1 parent 6b8b3df commit 592794b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

breath_plot.html

+17-15
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,8 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
11841184
$("#time_start").text((start) ? start.toISOStringSeconds() : null);
11851185
$("#time_finish").text((finish) ? finish.toISOStringSeconds() : null);
11861186
LAST_SAMPLE_DATE = finish;
1187-
console.log("process",start);
1188-
console.log("process",finish);
1187+
// console.log("process",start);
1188+
// console.log("process",finish);
11891189
}
11901190

11911191
// WARNING: This is a hack...if the timestamp is negative,
@@ -1247,7 +1247,7 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
12471247
// console.log("Z",currentDate);
12481248
} else {
12491249
}
1250-
// console.log("url =",url);
1250+
// console.log("url =",decodeURI(url));
12511251
$.ajax({url: url,
12521252
success: function(cur_sam){
12531253

@@ -1260,7 +1260,7 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
12601260
console.log("No return");
12611261
return;
12621262
}
1263-
// console.log("returned ",cur_sam.length);
1263+
// console.log("returned ",cur_sam.length,cur_sam);
12641264
if (cur_sam && cur_sam.length == 0) {
12651265
// This is no longer true now that we are asking for time...
12661266
// console.log("no samples; potential misconfiguration!");
@@ -1270,13 +1270,20 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
12701270
console.log("Error!");
12711271
stop_interval_timer();
12721272
$("#livetoggle").prop("checked",false);
1273-
console.log(cur_sam);
1273+
// console.log(cur_sam);
12741274
} else {
12751275
cur_sam = sanitize_samples(cur_sam);
12761276
if (INITS_ONLY) {
12771277
samples = cur_sam;
12781278
INITS_ONLY = false;
12791279
} else {
1280+
1281+
var first_new_ms = cur_sam[0].ms;
1282+
var cur_first_ms = samples[0].ms;
1283+
if (first_new_ms < cur_first_ms) { // This means a reset of the Arduino, we will dump samples..
1284+
samples = [];
1285+
console.log("DETECTED ARDUINO RESET, DUMPING CURRENT SAMPLES");
1286+
}
12801287
var discard = Math.max(0,
12811288
samples.length + cur_sam.length - MAX_SAMPLES_TO_STORE_S);
12821289
samples = samples.slice(discard);
@@ -1289,6 +1296,7 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
12891296
// This would be more efficient if done after sorting..
12901297
var n = samples.length;
12911298

1299+
// I think this is de-dupeing code...
12921300
samples = samples.filter((s, index, self) =>
12931301
self.findIndex(t => t.ms === s.ms
12941302
&& t.type === s.type
@@ -1297,26 +1305,20 @@ <h1 class="display-4">VentMon Respiration Analysis</h1>
12971305
&& t.event === s.event
12981306
&& t.val === s.val) === index);
12991307
}
1300-
samples = samples.filter((s, index, self) =>
1301-
self.findIndex(t => t.ms === s.ms
1302-
&& t.type === s.type
1303-
&& t.loc === s.loc
1304-
&& t.num === s.num
1305-
&& t.event === s.event
1306-
&& t.val === s.val) === index);
1308+
13071309
if (n != samples.length) {
1308-
console.log("deduped:",n-samples.length);
1310+
// console.log("deduped:",n-samples.length);
13091311
}
13101312

1311-
samples = samples.sort((a,b) => a.ms - b.ms);
13121313
// Now we will trim off samples if we are live...
13131314
if (intervalID) {
13141315
var last_ms = samples[samples.length-1].ms
13151316
samples = samples.filter((s, index, self) =>
13161317
s.ms >= (last_ms - DESIRED_DURATION_S*1000));
13171318
}
1319+
// console.log(samples);
13181320
process(samples);
1319-
console.log("END",LAST_SAMPLE_DATE);
1321+
// console.log("END",LAST_SAMPLE_DATE);
13201322
}
13211323
},
13221324
error: function(xhr, ajaxOptions, thrownError) {

0 commit comments

Comments
 (0)