@@ -176,6 +176,7 @@ function OpenBCIFactory() {
176176 this . _lowerChannelsSampleObject = null ;
177177 this . sync = {
178178 curSyncObj : null ,
179+ eventEmitter : null ,
179180 objArray : [ ] ,
180181 sntpActive : false ,
181182 timeOffsetMaster : 0 ,
@@ -1327,7 +1328,6 @@ function OpenBCIFactory() {
13271328 if ( this . options . verbose ) console . log ( 'pInput: ' + pInput + ' nInput: ' + nInput ) ;
13281329 // Get impedance settings to send the board
13291330 k . getImpedanceSetter ( channelNumber , pInput , nInput ) . then ( ( commandsArray ) => {
1330- console . log ( commandsArray ) ;
13311331 this . write ( commandsArray ) ;
13321332 //delayInMS += commandsArray.length * k.OBCIWriteIntervalDelayMSLong;
13331333 delayInMS += this . commandsToWrite * k . OBCIWriteIntervalDelayMSShort ; // Account for commands waiting to be sent in the write buffer
@@ -1564,10 +1564,11 @@ function OpenBCIFactory() {
15641564 if ( ! this . usingVersionTwoFirmware ( ) ) reject ( 'Time sync not implemented on v1 firmware, please update to v2' ) ;
15651565 setTimeout ( ( ) => {
15661566 return reject ( 'syncClocksFull timeout after 500ms with no sync' ) ;
1567- } , 1000 ) ; // Should not take more than 1s to sync up
1568- this . once ( 'synced' , syncObj => {
1567+ } , 500 ) ; // Should not take more than 1s to sync up
1568+ this . sync . eventEmitter = syncObj => {
15691569 return resolve ( syncObj ) ;
1570- } ) ;
1570+ } ;
1571+ this . once ( 'synced' , this . sync . eventEmitter ) ;
15711572 this . sync . curSyncObj = openBCISample . newSyncObject ( ) ;
15721573 this . sync . curSyncObj . timeSyncSent = this . time ( ) ;
15731574 this . curParsingMode = k . OBCIParsingTimeSyncSent ;
@@ -1853,7 +1854,9 @@ function OpenBCIFactory() {
18531854 // Fix the curParsingMode back to normal
18541855 this . curParsingMode = k . OBCIParsingNormal ;
18551856 // Emit the bad sync object for fun
1856- this . emit ( 'synced' , openBCISample . newSyncObject ( ) ) ;
1857+ var badObject = openBCISample . newSyncObject ( ) ;
1858+ badObject . timeOffsetMaster = this . sync . timeOffsetMaster ;
1859+ this . emit ( 'synced' , badObject ) ;
18571860 // Set back to null
18581861 this . sync . curSyncObj = null ;
18591862 // Return will exit this method with the err
@@ -1951,6 +1954,12 @@ function OpenBCIFactory() {
19511954 return resolve ( rawPacket ) ;
19521955 } )
19531956 . catch ( err => {
1957+ // Emit the bad sync object for fun
1958+ var badObject = openBCISample . newSyncObject ( ) ;
1959+ badObject . timeOffsetMaster = this . sync . timeOffsetMaster ;
1960+ this . emit ( 'synced' , badObject ) ;
1961+ // Set back to null
1962+ this . sync . curSyncObj = null ;
19541963 console . log ( 'Error in _processPacketTimeSyncSet' , err )
19551964 return reject ( err ) ;
19561965 } ) ;
0 commit comments