Skip to content

Commit

Permalink
www: fix short sentry event
Browse files Browse the repository at this point in the history
When there is a new Sentry event detected while the car is still
recording video for the previous Sentry events, it can create a 1-minute
event whose event time preceeds the recordings for the event.
In this case the car's viewer (and, prior to this change, the TeslaUSB
web viewer) would not show the event marker on the progress slider.
With this change, TeslaUSB will check if the event time from event.json
precedes the event recording timestamp, and if so it will add the
previous minute's recordings from RecentClips.
  • Loading branch information
marcone committed Aug 14, 2024
1 parent 29c23ad commit a49c152
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion teslausb-www/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2173,11 2173,40 @@
var s = segment.datetime;
eventSegmentStartMs = Date.parse(
s.substring(0,10) "T" s.substring(11,13) ":" s.substring(14,16) ":" s.substring(17, 19));
if (eventSegmentStartMs <= eventTimeMs) {
if (eventSegmentStartMs <= eventTimeMs || segmentIdx == 0) {
break;
}
}
var offsetIntoSegment = eventTimeMs - eventSegmentStartMs;
if (offsetIntoSegment < 0) {
/* The event time is before the first video segment. This can
happen if there are two sentry events in short succession */
log("negative sentry offset");
if (offsetIntoSegment > -60000) {
/* add one segment to the start of the sequence */
//return drawTickForIndex(idx);
var segment = this.getSegmentByIndex(0);
var s = segment.datetime.substring(0,10);
var dayclips = videos["RecentClips"][s];
if (dayclips != undefined) {
var prevseg;
for (var seg of dayclips.segments) {
if (seg.datetime == segment.datetime) {
break;
}
prevseg = seg;
}
if (prevseg != undefined) {
/* add found segment to start of this sequence */
log(this);
this.segments.unshift(prevseg);
log(this);
return this.select();
}
}
}
offsetIntoSegment = 0;
}
var eventOffsetMs = (segmentIdx * 60 * 1000) offsetIntoSegment;
var sequenceLengthMs = this.length() * 60 * 1000;
var reloffset = eventOffsetMs / sequenceLengthMs;
Expand Down

0 comments on commit a49c152

Please sign in to comment.