@@ -15,7 +15,7 @@ const bleNusCharTXUUID = 'adaf0003-4369-7263-7569-74507974686e';
15
15
16
16
const BYTES_PER_WRITE = 20 ;
17
17
18
- let btnRequestBluetoothDevice , btnBond , btnReconnect ;
18
+ let btnRequestBluetoothDevice , btnReconnect ;
19
19
20
20
class BLEWorkflow extends Workflow {
21
21
constructor ( ) {
@@ -31,10 +31,9 @@ class BLEWorkflow extends Workflow {
31
31
this . partialWrites = true ;
32
32
this . type = CONNTYPE . Ble ;
33
33
this . buttonStates = [
34
- { reconnect : false , request : false , bond : false } ,
35
- { reconnect : false , request : true , bond : false } ,
36
- { reconnect : true , request : true , bond : false } ,
37
- { reconnect : false , request : false , bond : true } ,
34
+ { reconnect : false , request : false } ,
35
+ { reconnect : false , request : true } ,
36
+ { reconnect : true , request : true } ,
38
37
] ;
39
38
}
40
39
@@ -54,18 +53,15 @@ class BLEWorkflow extends Workflow {
54
53
let p = this . connectDialog . open ( ) ;
55
54
let modal = this . connectDialog . getModal ( ) ;
56
55
btnRequestBluetoothDevice = modal . querySelector ( '#requestBluetoothDevice' ) ;
57
- btnBond = modal . querySelector ( '#promptBond' ) ;
58
56
btnReconnect = modal . querySelector ( '#bleReconnect' ) ;
59
57
60
58
// Map the button states to the buttons
61
59
this . connectButtons = {
62
60
reconnect : btnReconnect ,
63
- request : btnRequestBluetoothDevice ,
64
- bond : btnBond
61
+ request : btnRequestBluetoothDevice
65
62
} ;
66
63
67
64
btnRequestBluetoothDevice . addEventListener ( 'click' , this . onRequestBluetoothDeviceButtonClick . bind ( this ) ) ;
68
- btnBond . addEventListener ( 'click' , this . onBond . bind ( this ) ) ;
69
65
btnReconnect . addEventListener ( 'click' , this . reconnectButtonHandler . bind ( this ) ) ;
70
66
71
67
// Check if Web Bluetooth is available
@@ -154,11 +150,11 @@ class BLEWorkflow extends Workflow {
154
150
abortController . abort ( ) ;
155
151
console . log ( 'Connecting to GATT Server from "' + device . name + '"...' ) ;
156
152
try {
157
- await device . gatt . connect ( ) ;
153
+ this . bleServer = await device . gatt . connect ( ) ;
158
154
} catch ( error ) {
159
155
await this . _showMessage ( "Failed to connect to device. Try forgetting device from OS bluetooth devices and try again." ) ;
160
156
}
161
- if ( device . gatt . connected ) {
157
+ if ( this . bleServer && this . bleServer . connected ) {
162
158
console . log ( '> Bluetooth device "' + device . name + ' connected.' ) ;
163
159
await this . switchToDevice ( device ) ;
164
160
} else {
@@ -188,9 +184,7 @@ class BLEWorkflow extends Workflow {
188
184
let device = await this . requestDevice ( ) ;
189
185
190
186
console . log ( '> Requested ' + device . name ) ;
191
- await device . gatt . connect ( ) ;
192
-
193
- await this . switchToDevice ( device ) ;
187
+ await this . connectToBluetoothDevice ( device ) ;
194
188
/*}
195
189
catch (error) {
196
190
console.error(error);
@@ -204,7 +198,7 @@ class BLEWorkflow extends Workflow {
204
198
this . bleDevice = device ;
205
199
this . bleDevice . removeEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
206
200
this . bleDevice . addEventListener ( "gattserverdisconnected" , this . onDisconnected . bind ( this ) ) ;
207
- this . bleServer = this . bleDevice . gatt ;
201
+ // this.bleServer = this.bleDevice.gatt;
208
202
console . log ( "connected" , this . bleServer ) ;
209
203
let services ;
210
204
@@ -221,26 +215,11 @@ class BLEWorkflow extends Workflow {
221
215
await this . fileHelper . bond ( ) ;
222
216
await this . connectToSerial ( ) ;
223
217
224
- // Enable/Disable UI buttons
225
- this . connectionStep ( 3 ) ;
226
-
227
218
await this . onConnected ( ) ;
228
219
this . connectDialog . close ( ) ;
229
220
await this . loadEditor ( ) ;
230
221
}
231
222
232
- // Bond
233
- async onBond ( e ) {
234
- try {
235
- console . log ( "bond" ) ;
236
- await this . fileHelper . bond ( ) ;
237
- console . log ( "bond done" ) ;
238
- } catch ( e ) {
239
- console . log ( e , e . stack ) ;
240
- }
241
- await this . loadEditor ( ) ;
242
- }
243
-
244
223
async serialTransmit ( msg ) {
245
224
if ( this . rxCharacteristic ) {
246
225
let encoder = new TextEncoder ( ) ;
@@ -278,12 +257,6 @@ class BLEWorkflow extends Workflow {
278
257
await this . connectToBluetoothDevice ( device ) ;
279
258
}
280
259
}
281
-
282
- // Do we have a connection now but still need to connect serial?
283
- if ( this . bleDevice && ! this . bleServer ) {
284
- await this . showBusy ( this . bleDevice . gatt . connect ( ) ) ;
285
- this . switchToDevice ( this . bleDevice ) ;
286
- }
287
260
}
288
261
289
262
updateConnected ( connectionState ) {
0 commit comments