55 */
66
77import { profile } from "./bluetooth-profile" ;
8- import { DeviceVersion } from "./device-version " ;
8+ import { BoardVersion } from "./device" ;
99import { Logging , NullLogging } from "./logging" ;
1010
1111const deviceIdToWrapper : Map < string , BluetoothDeviceWrapper > = new Map ( ) ;
@@ -38,7 +38,7 @@ export class BluetoothDeviceWrapper {
3838 //
3939 // On Windows it times out after 7s.
4040 // https://bugs.chromium.org/p/chromium/issues/detail?id=684073
41- private gattConnectPromise : Promise < DeviceVersion | undefined > | undefined ;
41+ private gattConnectPromise : Promise < BoardVersion | undefined > | undefined ;
4242 private disconnectPromise : Promise < unknown > | undefined ;
4343 private connecting = false ;
4444 private isReconnect = false ;
@@ -88,7 +88,7 @@ export class BluetoothDeviceWrapper {
8888 // We always do this even if we might immediately disconnect as disconnecting
8989 // without using services causes getPrimaryService calls to hang on subsequent
9090 // reconnect - probably a device-side issue.
91- const deviceVersion = await this . getDeviceVersion ( ) ;
91+ const boardVersion = await this . getBoardVersion ( ) ;
9292 // This connection could be arbitrarily later when our manual timeout may have passed.
9393 // Do we still want to be connected?
9494 if ( ! this . connecting ) {
@@ -104,7 +104,7 @@ export class BluetoothDeviceWrapper {
104104 "Bluetooth GATT server connected when connecting"
105105 ) ;
106106 }
107- return deviceVersion ;
107+ return boardVersion ;
108108 } )
109109 . catch ( ( e ) => {
110110 if ( this . connecting ) {
@@ -124,7 +124,7 @@ export class BluetoothDeviceWrapper {
124124 } ) ;
125125
126126 this . connecting = true ;
127- let deviceVersion : DeviceVersion | undefined ;
127+ let boardVersion : BoardVersion | undefined ;
128128 try {
129129 const gattConnectResult = await Promise . race ( [
130130 this . gattConnectPromise ,
@@ -136,7 +136,7 @@ export class BluetoothDeviceWrapper {
136136 this . logging . log ( "Bluetooth GATT server connect timeout" ) ;
137137 throw new Error ( "Bluetooth GATT server connect timeout" ) ;
138138 }
139- deviceVersion = gattConnectResult ;
139+ boardVersion = gattConnectResult ;
140140 } finally {
141141 this . connecting = false ;
142142 }
@@ -229,12 +229,8 @@ export class BluetoothDeviceWrapper {
229229 }
230230 return this . device . gatt ;
231231 }
232- /**
233- * Fetches the model number of the micro:bit.
234- * @param {BluetoothRemoteGATTServer } gattServer The GATT server to read from.
235- * @return {Promise<number> } The model number of the micro:bit. 1 for the original, 2 for the new.
236- */
237- private async getDeviceVersion ( ) : Promise < DeviceVersion > {
232+
233+ private async getBoardVersion ( ) : Promise < BoardVersion > {
238234 this . assertGattServer ( ) ;
239235 const serviceMeta = profile . deviceInformation ;
240236 try {
@@ -247,12 +243,12 @@ export class BluetoothDeviceWrapper {
247243 const modelNumberBytes = await characteristic . readValue ( ) ;
248244 const modelNumber = new TextDecoder ( ) . decode ( modelNumberBytes ) ;
249245 if ( modelNumber . toLowerCase ( ) === "BBC micro:bit" . toLowerCase ( ) ) {
250- return DeviceVersion . V1 ;
246+ return "V1" ;
251247 }
252248 if (
253249 modelNumber . toLowerCase ( ) . includes ( "BBC micro:bit v2" . toLowerCase ( ) )
254250 ) {
255- return DeviceVersion . V2 ;
251+ return "V2" ;
256252 }
257253 throw new Error ( `Unexpected model number ${ modelNumber } ` ) ;
258254 } catch ( e ) {
0 commit comments