@@ -24,6 +24,8 @@ class ReplJS{
2424 this . BLE_DATA = null ;
2525 this . BLE_DATA_RESOLVE = null ;
2626 this . BLE_STOP_MSG = "##XRPSTOP##"
27+ this . disconnectHappened = false ;
28+
2729
2830
2931 // UUIDs for standard NORDIC UART service and characteristics
@@ -35,7 +37,7 @@ class ReplJS{
3537 this . XRP_SEND_BLOCK_SIZE = 250 ; // wired can handle 255 bytes, but BLE 5.0 is only 250
3638
3739 // Set true so most terminal output gets passed to javascript terminal
38- this . DEBUG_CONSOLE_ON = false ;
40+ this . DEBUG_CONSOLE_ON = true ;
3941
4042 this . COLLECT_RAW_DATA = false ;
4143 this . COLLECTED_RAW_DATA = [ ] ;
@@ -421,6 +423,7 @@ class ReplJS{
421423
422424 bleDisconnect ( ) {
423425 if ( REPL . DEBUG_CONSOLE_ON ) console . log ( "BLE Disconnected" ) ;
426+ REPL . disconnectHappened = true ;
424427 REPL . BLE_DISCONNECT_TIME = Date . now ( ) ;
425428 REPL . WRITEBLE = undefined ;
426429 REPL . READBLE = undefined ;
@@ -529,7 +532,11 @@ class ReplJS{
529532 console . error ( 'ble stop write failed:' , error ) ;
530533 //do nothing we expected an error
531534 }
532- this . BLE_DEVICE . gatt . disconnect ( ) ;
535+ this . disconnectHappened = false ;
536+ await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
537+ if ( ! this . disconnectHappened ) {
538+ this . BLE_DEVICE . gatt . disconnect ( ) ; //the disconnect didn't happen so create a disconnect
539+ }
533540 }
534541
535542 async softReset ( ) {
0 commit comments