-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
main.js
1308 lines (1069 loc) · 46.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
function BlackboxLogViewer() {
function supportsRequiredAPIs() {
return window.File && window.FileReader && window.FileList && Modernizr.canvas;
}
if (!supportsRequiredAPIs()) {
alert("Your browser does not support the APIs required for reading log files.");
}
var
GRAPH_STATE_PAUSED = 0,
GRAPH_STATE_PLAY = 1,
SMALL_JUMP_TIME = 100 * 1000,
LARGE_JUMP_TIME = 1000 * 1000,
PLAYBACK_MIN_RATE = 5,
PLAYBACK_MAX_RATE = 300,
PLAYBACK_DEFAULT_RATE = 100,
PLAYBACK_RATE_STEP = 5,
GRAPH_MIN_ZOOM = 10,
GRAPH_MAX_ZOOM = 1000,
GRAPH_DEFAULT_ZOOM = 100,
GRAPH_ZOOM_STEP = 10;
var
graphState = GRAPH_STATE_PAUSED,
currentBlackboxTime = 0,
lastRenderTime = false,
flightLog, flightLogDataArray,
graph = null,
prefs = new PrefStorage(),
// User's video render config:
videoConfig = {},
// JSON graph configuration:
graphConfig = {},
offsetCache = [], // Storage for the offset cache (last 20 files)
currentOffsetCache = {log:null, index:null, video:null, offset:null},
// JSON array of graph configurations for New Workspaces feature
lastGraphConfig = null, // Undo feature - go back to last configuration.
workspaceGraphConfigs = {}, // Workspaces
bookmarkTimes = [], // Empty array for bookmarks (times)
// Graph configuration which is currently in use, customised based on the current flight log from graphConfig
activeGraphConfig = new GraphConfig(),
graphLegend = null,
fieldPresenter = FlightLogFieldPresenter,
hasVideo = false, hasLog = false, hasMarker = false, // add measure feature
hasTable = true, hasCraft = true, hasSticks = true, hasAnalyser, hasAnalyserFullscreen,
hasAnalyserSticks = false, viewVideo = true,
isFullscreen = false, // New fullscreen feature (to hide table)
video = $(".log-graph video")[0],
canvas = $("#graphCanvas")[0],
analyserCanvas = $("#analyserCanvas")[0],
analyserStickCanvas = $("#analyserStickCanvas")[0],
craftCanvas = $("#craftCanvas")[0],
videoURL = false,
videoOffset = 0.0,
videoExportInTime = false,
videoExportOutTime = false,
markerTime = 0, // New marker time
graphRendersCount = 0,
seekBarCanvas = $(".log-seek-bar canvas")[0],
seekBar = new SeekBar(seekBarCanvas),
seekBarRepaintRateLimited = $.throttle(200, $.proxy(seekBar.repaint, seekBar)),
updateValuesChartRateLimited,
animationFrameIsQueued = false,
playbackRate = PLAYBACK_DEFAULT_RATE,
graphZoom = GRAPH_DEFAULT_ZOOM;
function blackboxTimeFromVideoTime() {
return (video.currentTime - videoOffset) * 1000000 + flightLog.getMinTime();
}
function syncLogToVideo() {
if (hasLog) {
currentBlackboxTime = blackboxTimeFromVideoTime();
}
}
function setVideoOffset(offset, withoutRefresh) { // optionally prevent the graph refresh until later
videoOffset = offset;
/*
* Round to 2 dec places for display and put a plus at the start for positive values to emphasize the fact it's
* an offset
*/
$(".video-offset").val((videoOffset >= 0 ? "+" : "") + (videoOffset.toFixed(3) != videoOffset ? videoOffset.toFixed(3) : videoOffset));
if (withoutRefresh) invalidateGraph();
}
function isInteger(value) {
return (value | 0) == value || Math.trunc(value) == value;
}
function atMost2DecPlaces(value) {
if (isInteger(value))
return value; //it's an integer already
if (value === null)
return "(absent)";
return value.toFixed(2);
}
function updateValuesChart() {
var
table = $(".log-field-values table"),
i,
frame = flightLog.getSmoothedFrameAtTime(currentBlackboxTime),
fieldNames = flightLog.getMainFieldNames();
$("tr:not(:first)", table).remove();
if (frame) {
var currentFlightMode = frame[flightLog.getMainFieldIndexByName("flightModeFlags")];
if(hasTable) { // Only redraw the table if it is enabled
var
rows = [],
rowCount = Math.ceil(fieldNames.length / 2);
for (i = 0; i < rowCount; i++) {
var
row =
"<tr>" +
'<td>' + fieldPresenter.fieldNameToFriendly(fieldNames[i]) + '</td>' +
'<td class="raw-value">' + atMost2DecPlaces(frame[i]) + '</td>' +
'<td>' + fieldPresenter.decodeFieldToFriendly(flightLog, fieldNames[i], frame[i], currentFlightMode) + "</td>",
secondColumn = i + rowCount;
if (secondColumn < fieldNames.length) {
row +=
'<td>' + fieldPresenter.fieldNameToFriendly(fieldNames[secondColumn]) + '</td>' +
'<td>' + atMost2DecPlaces(frame[secondColumn]) + '</td>' +
'<td>' + fieldPresenter.decodeFieldToFriendly(flightLog, fieldNames[secondColumn], frame[secondColumn], currentFlightMode) + '</td>';
}
row += "</tr>";
rows.push(row);
}
table.append(rows.join(""));
}
// Update flight mode flags on status bar
$("#status-bar .flight-mode").text(
fieldPresenter.decodeFieldToFriendly(null, 'flightModeFlags', currentFlightMode, null)
);
// update time field on status bar
$(".graph-time").val(formatTime((currentBlackboxTime-flightLog.getMinTime())/1000, true));
if(hasMarker) {
$("#status-bar .marker-offset").text('Marker Offset ' + formatTime((currentBlackboxTime-markerTime)/1000, true) + 'ms');
}
// Update the Legend Values
if(graphLegend) graphLegend.updateValues(flightLog, frame);
}
}
updateValuesChartRateLimited = $.throttle(250, updateValuesChart);
function animationLoop() {
var
now = Date.now();
if (!graph) {
animationFrameIsQueued = false;
return;
}
if (hasVideo) {
currentBlackboxTime = blackboxTimeFromVideoTime();
} else if (graphState == GRAPH_STATE_PLAY) {
var
delta;
if (lastRenderTime === false) {
delta = 0;
} else {
delta = Math.floor((now - lastRenderTime) * 1000 * playbackRate / 100);
}
currentBlackboxTime += delta;
if (currentBlackboxTime > flightLog.getMaxTime()) {
currentBlackboxTime = flightLog.getMaxTime();
setGraphState(GRAPH_STATE_PAUSED);
}
}
graph.render(currentBlackboxTime);
graphRendersCount++;
seekBar.setCurrentTime(currentBlackboxTime);
updateValuesChartRateLimited();
if (graphState == GRAPH_STATE_PLAY) {
lastRenderTime = now;
seekBarRepaintRateLimited();
animationFrameIsQueued = true;
requestAnimationFrame(animationLoop);
} else {
seekBar.repaint();
animationFrameIsQueued = false;
}
}
function invalidateGraph() {
if (!animationFrameIsQueued) {
animationFrameIsQueued = true;
requestAnimationFrame(animationLoop);
}
}
function updateCanvasSize() {
var
width = $(canvas).width(),
height = $(canvas).height();
if (graph) {
graph.resize(width, height);
seekBar.resize(canvas.offsetWidth, 50);
invalidateGraph();
}
}
function renderLogFileInfo(file) {
$(".log-filename").text(file.name);
var
logIndexContainer = $(".log-index"),
logIndexPicker,
logCount = flightLog.getLogCount(),
index;
logIndexContainer.empty();
if (logCount > 1) {
logIndexPicker = $('<select class="log-index form-control">');
logIndexPicker.change(function() {
selectLog(parseInt($(this).val(), 10));
});
}
for (index = 0; index < logCount; index++) {
var
logLabel,
option, holder,
error;
error = flightLog.getLogError(index);
if (error) {
logLabel = "Error: " + error;
} else {
logLabel = formatTime(flightLog.getMinTime(index) / 1000, false)
+ " - " + formatTime(flightLog.getMaxTime(index) / 1000 , false)
+ " [" + formatTime(Math.ceil((flightLog.getMaxTime(index) - flightLog.getMinTime(index)) / 1000), false) + "]";
}
if (logCount > 1) {
option = $("<option></option>");
option.text((index + 1) + "/" + (flightLog.getLogCount()) + ": " + logLabel);
option.attr("value", index);
if (error)
option.attr("disabled", "disabled");
logIndexPicker.append(option);
} else {
holder = $('<div class="form-control-static"></div>');
holder.text(logLabel);
logIndexContainer.append(holder);
}
}
if (logCount > 1) {
logIndexPicker.val(0);
logIndexContainer.append(logIndexPicker);
}
}
/**
* Update the metadata displays to show information about the currently selected log index.
*/
function renderSelectedLogInfo() {
$(".log-index").val(flightLog.getLogIndex());
if (flightLog.getNumCellsEstimate()) {
$(".log-cells").text(flightLog.getNumCellsEstimate() + "S (" + Number(flightLog.getReferenceVoltageMillivolts() / 1000).toFixed(2) + "V)");
$(".log-cells-header,.log-cells").css('display', 'block');
} else {
$(".log-cells-header,.log-cells").css('display', 'none');
}
if (flightLog.getSysConfig().deviceUID != null) {
$(".log-device-uid").text(flightLog.getSysConfig().deviceUID);
$(".log-device-uid-header,.log-device-uid").css('display', 'block');
} else {
$(".log-device-uid-header,.log-device-uid").css('display', 'none');
}
// Add log version information to status bar
var sysConfig = flightLog.getSysConfig();
$('#status-bar .version').text( ((sysConfig['Firmware revision']!=null)?(sysConfig['Firmware revision']):''));
$('#status-bar .looptime').text( ((sysConfig['loopTime']!=null)?(sysConfig['loopTime'] +'us (' + (1000000/sysConfig['loopTime']).toFixed(0) + 'Hz)'):''));
$('#status-bar .lograte').text( ((sysConfig['frameIntervalPDenom']!=null && sysConfig['frameIntervalPNum']!=null)?( 'Logging Sample Rate : ' + sysConfig['frameIntervalPNum'] +'/' + sysConfig['frameIntervalPDenom']):''));
seekBar.setTimeRange(flightLog.getMinTime(), flightLog.getMaxTime(), currentBlackboxTime);
seekBar.setActivityRange(flightLog.getSysConfig().minthrottle, flightLog.getSysConfig().maxthrottle);
var
activity = flightLog.getActivitySummary();
seekBar.setActivity(activity.times, activity.avgThrottle, activity.hasEvent);
seekBar.repaint();
}
function setGraphState(newState) {
graphState = newState;
lastRenderTime = false;
switch (newState) {
case GRAPH_STATE_PLAY:
if (hasVideo) {
video.play();
}
$(".log-play-pause span").attr('class', 'glyphicon glyphicon-pause');
break;
case GRAPH_STATE_PAUSED:
if (hasVideo) {
video.pause();
}
$(".log-play-pause span").attr('class', 'glyphicon glyphicon-play');
break;
}
invalidateGraph();
}
function setCurrentBlackboxTime(newTime) {
if (hasVideo) {
video.currentTime = (newTime - flightLog.getMinTime()) / 1000000 + videoOffset;
syncLogToVideo();
} else {
currentBlackboxTime = newTime;
}
invalidateGraph();
}
function setVideoTime(newTime) {
video.currentTime = newTime;
syncLogToVideo();
}
function setVideoInTime(inTime) {
videoExportInTime = inTime;
if (seekBar) {
seekBar.setInTime(videoExportInTime);
}
if (graph) {
graph.setInTime(videoExportInTime);
invalidateGraph();
}
}
function setVideoOutTime(outTime) {
videoExportOutTime = outTime;
if (seekBar) {
seekBar.setOutTime(videoExportOutTime);
}
if (graph) {
graph.setOutTime(videoExportOutTime);
invalidateGraph();
}
}
function setPlaybackRate(rate) {
if (rate >= PLAYBACK_MIN_RATE && rate <= PLAYBACK_MAX_RATE) {
playbackRate = rate;
if (video) {
video.playbackRate = rate / 100;
}
}
}
function setGraphZoom(zoom) {
if (zoom >= GRAPH_MIN_ZOOM && zoom <= GRAPH_MAX_ZOOM) {
graphZoom = zoom;
if (graph) {
graph.setGraphZoom(zoom / 100);
invalidateGraph();
}
}
}
/**
* Set the index of the log from the log file that should be viewed. Pass "null" as the index to open the first
* available log.
*/
function selectLog(logIndex) {
var
success = false;
try {
if (logIndex === null) {
for (var i = 0; i < flightLog.getLogCount(); i++) {
if (flightLog.openLog(i)) {
success = true;
currentOffsetCache.index = i;
break;
}
}
if (!success) {
throw "No logs in this file could be parsed successfully";
}
} else {
flightLog.openLog(logIndex);
currentOffsetCache.index = logIndex;
}
} catch (e) {
alert("Error opening log: " + e);
currentOffsetCache.index = null;
return;
}
if (graph) {
graph.destroy();
}
var graphOptions = {
drawAnalyser:true, // add an analyser option
analyserSampleRate:2000/*Hz*/, // the loop time for the log
};
if((flightLog.getSysConfig().loopTime != null) &&
(flightLog.getSysConfig().frameIntervalPNum != null) &&
(flightLog.getSysConfig().frameIntervalPDenom != null) ) {
graphOptions.analyserSampleRate = 1000000 / (flightLog.getSysConfig().loopTime * flightLog.getSysConfig().frameIntervalPDenom / flightLog.getSysConfig().frameIntervalPNum);
}
graph = new FlightLogGrapher(flightLog, activeGraphConfig, canvas, craftCanvas, analyserCanvas, graphOptions);
setVideoInTime(false);
setVideoOutTime(false);
activeGraphConfig.adaptGraphs(flightLog, graphConfig);
graph.onSeek = function(offset) {
//Seek faster
offset *= 2;
if (hasVideo) {
setVideoTime(video.currentTime + offset / 1000000);
} else {
setCurrentBlackboxTime(currentBlackboxTime + offset);
}
invalidateGraph();
};
if (hasVideo) {
syncLogToVideo();
} else {
// Start at beginning:
currentBlackboxTime = flightLog.getMinTime();
}
renderSelectedLogInfo();
updateCanvasSize();
setGraphState(GRAPH_STATE_PAUSED);
setGraphZoom(graphZoom);
}
function loadLogFile(file) {
var reader = new FileReader();
reader.onload = function(e) {
var bytes = e.target.result;
flightLogDataArray = new Uint8Array(bytes);
try {
flightLog = new FlightLog(flightLogDataArray);
} catch (err) {
alert("Sorry, an error occured while trying to open this log:\n\n" + err);
return;
}
renderLogFileInfo(file);
currentOffsetCache.log = file.name; // store the name of the loaded log file
currentOffsetCache.index = null; // and clear the index
hasLog = true;
$("html").addClass("has-log");
(hasCraft)?$("html").addClass("has-craft"):$("html").removeClass("has-craft");
(hasTable)?$("html").addClass("has-table"):$("html").removeClass("has-table");
(hasSticks)?$("html").addClass("has-sticks"):$("html").removeClass("has-sticks");
selectLog(null);
};
reader.readAsArrayBuffer(file);
}
function loadVideo(file) {
currentOffsetCache.video = file.name; // store the name of the loaded video
if (videoURL) {
URL.revokeObjectURL(videoURL);
videoURL = false;
}
if (!URL.createObjectURL) {
alert("Sorry, your web browser doesn't support showing videos from your local computer. Try Google Chrome instead.");
currentOffsetCache.video = null; // clear the associated video name
return;
}
videoURL = URL.createObjectURL(file);
video.volume = 0.05;
video.src = videoURL;
// Reapply the last playbackRate to the new video
setPlaybackRate(playbackRate);
}
function videoLoaded(e) {
hasVideo = true;
$("html").addClass("has-video");
setGraphState(GRAPH_STATE_PAUSED);
}
function reportVideoError(e) {
alert("Your video could not be loaded, your browser might not support this kind of video. Try Google Chrome instead.");
}
function onLegendVisbilityChange(hidden) {
prefs.set('log-legend-hidden', hidden);
updateCanvasSize();
}
function onLegendSelectionChange() {
hasAnalyser = true;
graph.setDrawAnalyser(hasAnalyser);
(hasAnalyser)?$("html").addClass("has-analyser"):$("html").removeClass("has-analyser");
prefs.set('hasAnalyser', hasAnalyser);
invalidateGraph();
}
function setMarker(state) { // update marker field
hasMarker = state;
(state)?$("html").addClass("has-marker"):$("html").removeClass("has-marker");
}
function setFullscreen(state) { // update fullscreen status
isFullscreen = state;
(state)?$("html").addClass("is-fullscreen"):$("html").removeClass("is-fullscreen");
}
this.getMarker = function() { // get marker field
return {
state:hasMarker,
time:markerTime
};
}
this.getBookmarks = function() { // get bookmark events
var bookmarks = [];
try {
if(bookmarkTimes!=null) {
for(var i=0; i<=9; i++) {
if(bookmarkTimes[i]!=null) {
bookmarks[i] = {
state: (bookmarkTimes[i]!=0),
time: bookmarkTimes[i]
};
} else bookmarks[i] = null;
}
}
return bookmarks;
} catch(e) {
return null;
}
}
prefs.get('videoConfig', function(item) {
if (item) {
videoConfig = item;
} else {
videoConfig = {
width: 1280,
height: 720,
frameRate: 30,
videoDim: 0.4
};
}
});
prefs.get('graphConfig', function(item) {
graphConfig = GraphConfig.load(item);
if (!graphConfig) {
graphConfig = GraphConfig.getExampleGraphConfigs(flightLog, ["Motors", "Gyros"]);
}
});
// New workspaces feature; local storage of user configurations
prefs.get('workspaceGraphConfigs', function(item) {
if(item) {
workspaceGraphConfigs = item;
} else {
workspaceGraphConfigs = {graphConfig : [
null,null,null,null,null,null,null,null,null,null
]};
}
});
// Get the offsetCache buffer
prefs.get('offsetCache', function(item) {
if(item) {
offsetCache = item;
}
})
activeGraphConfig.addListener(function() {
invalidateGraph();
});
$(document).ready(function() {
graphLegend = new GraphLegend($(".log-graph-legend"), activeGraphConfig, onLegendVisbilityChange, onLegendSelectionChange);
prefs.get('log-legend-hidden', function(item) {
if (item) {
graphLegend.hide();
}
});
prefs.get('hasCraft', function(item) {
if (item) {
hasCraft = item;
(hasCraft)?$("html").addClass("has-craft"):$("html").removeClass("has-craft");
}
});
prefs.get('hasSticks', function(item) {
if (item) {
hasSticks = item;
(hasSticks)?$("html").addClass("has-sticks"):$("html").removeClass("has-sticks");
}
});
prefs.get('hasTable', function(item) {
if (item) {
hasTable = item;
(hasTable)?$("html").addClass("has-table"):$("html").removeClass("has-table");
}
});
prefs.get('hasAnalyser', function(item) {
if (item) {
hasAnalyser = item;
(hasAnalyser)?$("html").addClass("has-analyser"):$("html").removeClass("has-analyser");
}
});
$(".file-open").change(function(e) {
var
files = e.target.files,
i;
for (i = 0; i < files.length; i++) {
var
isLog = files[i].name.match(/\.(TXT|CFL|LOG)$/i),
isVideo = files[i].name.match(/\.(AVI|MOV|MP4|MPEG)$/i);
if (!isLog && !isVideo) {
if (files[i].size < 10 * 1024 * 1024)
isLog = true; //Assume small files are logs rather than videos
else
isVideo = true;
}
if (isLog) {
loadLogFile(files[i]);
} else if (isVideo) {
loadVideo(files[i]);
}
}
// finally, see if there is an offsetCache value already, and auto set the offset
for(i=0; i<offsetCache.length; i++) {
if(
(currentOffsetCache.log == offsetCache[i].log) &&
(currentOffsetCache.index == offsetCache[i].index) &&
(currentOffsetCache.video == offsetCache[i].video) ) {
setVideoOffset(offsetCache[i].offset, true);
}
}
});
// New View Controls
$(".view-video").click(function() {
viewVideo = !viewVideo;
(!viewVideo)?$("html").addClass("video-hidden"):$("html").removeClass("video-hidden");
});
$(".view-craft").click(function() {
hasCraft = !hasCraft;
(hasCraft)?$("html").addClass("has-craft"):$("html").removeClass("has-craft");
prefs.set('hasCraft', hasCraft);
});
$(".view-sticks").click(function() {
hasSticks = !hasSticks;
graph.setDrawSticks(hasSticks);
(hasSticks)?$("html").addClass("has-sticks"):$("html").removeClass("has-sticks");
prefs.set('hasSticks', hasSticks);
invalidateGraph();
});
$(".view-table").click(function() {
hasTable = !hasTable;
(hasTable)?$("html").addClass("has-table"):$("html").removeClass("has-table");
prefs.set('hasTable', hasTable);
});
$(".view-analyser-sticks").click(function() {
hasAnalyserSticks = !hasAnalyserSticks;
(hasAnalyserSticks)?$("html").addClass("has-analyser-sticks"):$("html").removeClass("has-analyser-sticks");
prefs.set('hasAnalyserSticks', hasAnalyserSticks);
});
$(".view-analyser").click(function() {
if(activeGraphConfig.selectedFieldName != null) {
hasAnalyser = !hasAnalyser;
} else hasAnalyser = false;
graph.setDrawAnalyser(hasAnalyser);
(hasAnalyser)?$("html").addClass("has-analyser"):$("html").removeClass("has-analyser");
prefs.set('hasAnalyser', hasAnalyser);
invalidateGraph();
});
$(".view-analyser-fullscreen").click(function() {
if(hasAnalyser) {
hasAnalyserFullscreen = !hasAnalyserFullscreen;
} else hasAnalyserFullscreen = false;
(hasAnalyserFullscreen)?$("html").addClass("has-analyser-fullscreen"):$("html").removeClass("has-analyser-fullscreen");
graph.setAnalyser(hasAnalyserFullscreen);
invalidateGraph();
});
var logJumpBack = function(fast) {
var scrollTime = SMALL_JUMP_TIME;
if(fast!=null) scrollTime = (fast!=0)?(graph.getWindowWidthTime() * fast):SMALL_JUMP_TIME;
if (hasVideo) {
setVideoTime(video.currentTime - scrollTime / 1000000);
} else {
setCurrentBlackboxTime(currentBlackboxTime - scrollTime);
}
setGraphState(GRAPH_STATE_PAUSED);
};
$(".log-jump-back").click(function() {logJumpBack(false);});
var logJumpForward = function(fast) {
var scrollTime = SMALL_JUMP_TIME;
if(fast!=null) scrollTime = (fast!=0)?(graph.getWindowWidthTime() * fast):SMALL_JUMP_TIME;
if (hasVideo) {
setVideoTime(video.currentTime + scrollTime / 1000000);
} else {
setCurrentBlackboxTime(currentBlackboxTime + scrollTime);
}
setGraphState(GRAPH_STATE_PAUSED);
};
$(".log-jump-forward").click(function() {logJumpForward(false);});
var logJumpStart = function() {
setCurrentBlackboxTime(flightLog.getMinTime());
setGraphState(GRAPH_STATE_PAUSED);
};
$(".log-jump-start").click(logJumpStart);
var logJumpEnd = function() {
setCurrentBlackboxTime(flightLog.getMaxTime());
setGraphState(GRAPH_STATE_PAUSED);
};
$(".log-jump-end").click(logJumpEnd);
var videoJumpStart = function() {
setVideoTime(0);
setGraphState(GRAPH_STATE_PAUSED);
};
$(".video-jump-start").click(videoJumpStart);
var videoJumpEnd = function() {
if (video.duration) {
setVideoTime(video.duration);
setGraphState(GRAPH_STATE_PAUSED);
}
};
$(".video-jump-end").click(videoJumpEnd);
var logPlayPause = function() {
if (graphState == GRAPH_STATE_PAUSED) {
setGraphState(GRAPH_STATE_PLAY);
} else {
setGraphState(GRAPH_STATE_PAUSED);
}
};
$(".log-play-pause").click(logPlayPause);
var logSyncHere = function() {
setVideoOffset(video.currentTime);
};
$(".log-sync-here").click(logSyncHere);
var logSyncBack = function() {
setVideoOffset(videoOffset - 1 / 15);
};
$(".log-sync-back").click(logSyncBack);
var logSyncForward = function() {
setVideoOffset(videoOffset + 1 / 15);
};
$(".log-sync-forward").click(logSyncForward);
$(".video-offset").change(function() {
var offset = parseFloat($(".video-offset").val());
if (!isNaN(offset)) {
videoOffset = offset;
// Store the video offset to the local cache
currentOffsetCache.offset = offset;
if(hasLog && hasVideo) {
if(offsetCache.length > 20) offsetCache.shift();
offsetCache.push(currentOffsetCache);
prefs.set('offsetCache', offsetCache);
}
invalidateGraph();
}
});
// Add user configurable start time
$(".graph-time").change(function() {
// the log is offset by the minTime
var newTime = stringTimetoMsec($(".graph-time").val());
if (!isNaN(newTime)) {
if (hasVideo) {
setVideoTime(newTime / 1000000 + videoOffset);
} else {
newTime += flightLog.getMinTime();
setCurrentBlackboxTime(newTime);
}
invalidateGraph();
}
});
var newGraphConfig = function(newConfig) {
lastGraphConfig = graphConfig; // Remember the last configuration.
graphConfig = newConfig;
activeGraphConfig.adaptGraphs(flightLog, graphConfig);
prefs.set('graphConfig', graphConfig);
}
var
graphConfigDialog = new GraphConfigurationDialog($("#dlgGraphConfiguration"), function(newConfig) {
newGraphConfig(newConfig);
}),
headerDialog = new HeaderDialog($("#dlgHeaderDialog"), function(newSysConfig) {
if(newSysConfig!=null) {
prefs.set('lastHeaderData', newSysConfig);
flightLog.setSysConfig(newSysConfig);
// Save Current Position then re-calculate all the log information
var activePosition = (hasVideo)?video.currentTime:currentBlackboxTime;
selectLog(null);
if (hasVideo) {
setVideoTime(activePosition);
} else {
setCurrentBlackboxTime(activePosition);
}
}
}),
keysDialog = new KeysDialog($("#dlgKeysDialog")),
exportDialog = new VideoExportDialog($("#dlgVideoExport"), function(newConfig) {
videoConfig = newConfig;
prefs.set('videoConfig', newConfig);
});
$(".open-graph-configuration-dialog").click(function(e) {
e.preventDefault();
graphConfigDialog.show(flightLog, graphConfig);
});
$(".open-header-dialog").click(function(e) {
e.preventDefault();
headerDialog.show(flightLog.getSysConfig());
});
$(".open-keys-dialog").click(function(e) {
e.preventDefault();
keysDialog.show();
});
$("#status-bar .marker-offset").click(function(e) {
setCurrentBlackboxTime(markerTime);
invalidateGraph();
});
$('#status-bar .bookmark-1').click(function(e) {
setCurrentBlackboxTime(bookmarkTimes[1]);
invalidateGraph();
});
$('#status-bar .bookmark-2').click(function(e) {
setCurrentBlackboxTime(bookmarkTimes[2]);
invalidateGraph();
});
$('#status-bar .bookmark-3').click(function(e) {
setCurrentBlackboxTime(bookmarkTimes[3]);
invalidateGraph();
});
$('#status-bar .bookmark-4').click(function(e) {
setCurrentBlackboxTime(bookmarkTimes[4]);
invalidateGraph();
});
$('#status-bar .bookmark-5').click(function(e) {
setCurrentBlackboxTime(bookmarkTimes[5]);
invalidateGraph();
});