@@ -39,6 +39,9 @@ function BlackboxLogViewer() {
3939 // JSON graph configuration:
4040 graphConfig = { } ,
4141
42+ offsetCache = [ ] , // Storage for the offset cache (last 20 files)
43+ currentOffsetCache = { log :null , index :null , video :null , offset :null } ,
44+
4245 // JSON array of graph configurations for New Workspaces feature
4346 lastGraphConfig = null , // Undo feature - go back to last configuration.
4447 workspaceGraphConfigs = { } , // Workspaces
@@ -100,7 +103,7 @@ function BlackboxLogViewer() {
100103 */
101104 $ ( ".video-offset" ) . val ( ( videoOffset >= 0 ? "+" : "" ) + ( videoOffset . toFixed ( 3 ) != videoOffset ? videoOffset . toFixed ( 3 ) : videoOffset ) ) ;
102105
103- if ( wihtoutRefresh ) invalidateGraph ( ) ;
106+ if ( withoutRefresh ) invalidateGraph ( ) ;
104107 }
105108
106109 function isInteger ( value ) {
@@ -434,6 +437,7 @@ function BlackboxLogViewer() {
434437 for ( var i = 0 ; i < flightLog . getLogCount ( ) ; i ++ ) {
435438 if ( flightLog . openLog ( i ) ) {
436439 success = true ;
440+ currentOffsetCache . index = i ;
437441 break ;
438442 }
439443 }
@@ -443,9 +447,11 @@ function BlackboxLogViewer() {
443447 }
444448 } else {
445449 flightLog . openLog ( logIndex ) ;
450+ currentOffsetCache . index = logIndex ;
446451 }
447452 } catch ( e ) {
448453 alert ( "Error opening log: " + e ) ;
454+ currentOffsetCache . index = null ;
449455 return ;
450456 }
451457
@@ -510,6 +516,8 @@ function BlackboxLogViewer() {
510516 }
511517
512518 renderLogFileInfo ( file ) ;
519+ currentOffsetCache . log = file . name ; // store the name of the loaded log file
520+ currentOffsetCache . index = null ; // and clear the index
513521
514522 hasLog = true ;
515523 $ ( "html" ) . addClass ( "has-log" ) ;
@@ -524,13 +532,15 @@ function BlackboxLogViewer() {
524532 }
525533
526534 function loadVideo ( file ) {
535+ currentOffsetCache . video = file . name ; // store the name of the loaded video
527536 if ( videoURL ) {
528537 URL . revokeObjectURL ( videoURL ) ;
529538 videoURL = false ;
530539 }
531540
532541 if ( ! URL . createObjectURL ) {
533542 alert ( "Sorry, your web browser doesn't support showing videos from your local computer. Try Google Chrome instead." ) ;
543+ currentOffsetCache . video = null ; // clear the associated video name
534544 return ;
535545 }
536546
@@ -634,6 +644,13 @@ function BlackboxLogViewer() {
634644 ] } ;
635645 }
636646 } ) ;
647+
648+ // Get the offsetCache buffer
649+ prefs . get ( 'offsetCache' , function ( item ) {
650+ if ( item ) {
651+ offsetCache = item ;
652+ }
653+ } )
637654
638655 activeGraphConfig . addListener ( function ( ) {
639656 invalidateGraph ( ) ;
@@ -677,12 +694,11 @@ function BlackboxLogViewer() {
677694 }
678695 } ) ;
679696
680-
681697 $ ( ".file-open" ) . change ( function ( e ) {
682698 var
683699 files = e . target . files ,
684700 i ;
685-
701+
686702 for ( i = 0 ; i < files . length ; i ++ ) {
687703 var
688704 isLog = files [ i ] . name . match ( / \. ( T X T | C F L | L O G ) $ / i) ,
@@ -701,8 +717,19 @@ function BlackboxLogViewer() {
701717 loadVideo ( files [ i ] ) ;
702718 }
703719 }
704- } ) ;
705720
721+ // finally, see if there is an offsetCache value already, and auto set the offset
722+ for ( i = 0 ; i < offsetCache . length ; i ++ ) {
723+ if (
724+ ( currentOffsetCache . log == offsetCache [ i ] . log ) &&
725+ ( currentOffsetCache . index == offsetCache [ i ] . index ) &&
726+ ( currentOffsetCache . video == offsetCache [ i ] . video ) ) {
727+ setVideoOffset ( offsetCache [ i ] . offset , true ) ;
728+ }
729+
730+ }
731+ } ) ;
732+
706733 // New View Controls
707734 $ ( ".view-craft" ) . click ( function ( ) {
708735 hasCraft = ! hasCraft ;
@@ -814,7 +841,14 @@ function BlackboxLogViewer() {
814841 var offset = parseFloat ( $ ( ".video-offset" ) . val ( ) ) ;
815842
816843 if ( ! isNaN ( offset ) ) {
817- videoOffset = offset ;
844+ videoOffset = offset ;
845+ // Store the video offset to the local cache
846+ currentOffsetCache . offset = offset ;
847+ if ( hasLog && hasVideo ) {
848+ if ( offsetCache . length > 20 ) offsetCache . shift ( ) ;
849+ offsetCache . push ( currentOffsetCache ) ;
850+ prefs . set ( 'offsetCache' , offsetCache ) ;
851+ }
818852 invalidateGraph ( ) ;
819853 }
820854 } ) ;
@@ -853,10 +887,11 @@ function BlackboxLogViewer() {
853887 headerDialog = new HeaderDialog ( $ ( "#dlgHeaderDialog" ) , function ( newSysConfig ) {
854888 if ( newSysConfig != null ) {
855889 prefs . set ( 'lastHeaderData' , newSysConfig ) ;
856- // flightLog.setSysConfig(newSysConfig);
890+ flightLog . setSysConfig ( newSysConfig ) ;
857891
858892 // Save Current Position then re-calculate all the log information
859893 var activePosition = ( hasVideo ) ?video . currentTime :currentBlackboxTime ;
894+
860895 selectLog ( null ) ;
861896 if ( hasVideo ) {
862897 setVideoTime ( activePosition ) ;
0 commit comments