@@ -40,6 +40,12 @@ export interface MicrobitWebUSBConnectionOptions {
40
40
logging : Logging ;
41
41
}
42
42
43
+ export interface FlashOptions {
44
+ partial : boolean ;
45
+ progress : ( percentage : number | undefined ) => void ;
46
+ minimumProgressIncrement ?: number ;
47
+ }
48
+
43
49
/**
44
50
* A WebUSB connection to a micro:bit device.
45
51
*/
@@ -201,11 +207,7 @@ export class MicrobitWebUSBConnection
201
207
202
208
async flash (
203
209
dataSource : FlashDataSource ,
204
- options : {
205
- partial : boolean ;
206
- progress : ( percentage : number | undefined ) => void ;
207
- miniumProgressIncrement : number ;
208
- } ,
210
+ options : FlashOptions ,
209
211
) : Promise < void > {
210
212
this . flashing = true ;
211
213
try {
@@ -230,11 +232,7 @@ export class MicrobitWebUSBConnection
230
232
231
233
private async flashInternal (
232
234
dataSource : FlashDataSource ,
233
- options : {
234
- partial : boolean ;
235
- progress : ( percentage : number | undefined , partial : boolean ) => void ;
236
- miniumProgressIncrement : number ;
237
- } ,
235
+ options : FlashOptions ,
238
236
) : Promise < void > {
239
237
this . log ( "Stopping serial before flash" ) ;
240
238
await this . stopSerialInternal ( ) ;
@@ -246,7 +244,7 @@ export class MicrobitWebUSBConnection
246
244
247
245
const partial = options . partial ;
248
246
const progress = rateLimitProgress (
249
- options . miniumProgressIncrement ?? 0.0025 ,
247
+ options . minimumProgressIncrement ?? 0.0025 ,
250
248
options . progress || ( ( ) => { } ) ,
251
249
) ;
252
250
@@ -523,7 +521,7 @@ const enrichedError = (err: any): DeviceError => {
523
521
} ;
524
522
525
523
const rateLimitProgress = (
526
- miniumProgressIncrement : number ,
524
+ minimumProgressIncrement : number ,
527
525
callback : ( value : number | undefined , partial : boolean ) => void ,
528
526
) => {
529
527
let lastCallValue = - 1 ;
@@ -532,7 +530,7 @@ const rateLimitProgress = (
532
530
value === undefined ||
533
531
value === 0 ||
534
532
value === 1 ||
535
- value >= lastCallValue + miniumProgressIncrement
533
+ value >= lastCallValue + minimumProgressIncrement
536
534
) {
537
535
lastCallValue = value ?? - 1 ;
538
536
callback ( value , partial ) ;
0 commit comments