Skip to content

Commit adf0c90

Browse files
Fix option type, extract and reuse (#31)
Not exported for the moment
1 parent 4de7ea8 commit adf0c90

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/usb.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export interface MicrobitWebUSBConnectionOptions {
4040
logging: Logging;
4141
}
4242

43+
export interface FlashOptions {
44+
partial: boolean;
45+
progress: (percentage: number | undefined) => void;
46+
minimumProgressIncrement?: number;
47+
}
48+
4349
/**
4450
* A WebUSB connection to a micro:bit device.
4551
*/
@@ -201,11 +207,7 @@ export class MicrobitWebUSBConnection
201207

202208
async flash(
203209
dataSource: FlashDataSource,
204-
options: {
205-
partial: boolean;
206-
progress: (percentage: number | undefined) => void;
207-
miniumProgressIncrement: number;
208-
},
210+
options: FlashOptions,
209211
): Promise<void> {
210212
this.flashing = true;
211213
try {
@@ -230,11 +232,7 @@ export class MicrobitWebUSBConnection
230232

231233
private async flashInternal(
232234
dataSource: FlashDataSource,
233-
options: {
234-
partial: boolean;
235-
progress: (percentage: number | undefined, partial: boolean) => void;
236-
miniumProgressIncrement: number;
237-
},
235+
options: FlashOptions,
238236
): Promise<void> {
239237
this.log("Stopping serial before flash");
240238
await this.stopSerialInternal();
@@ -246,7 +244,7 @@ export class MicrobitWebUSBConnection
246244

247245
const partial = options.partial;
248246
const progress = rateLimitProgress(
249-
options.miniumProgressIncrement ?? 0.0025,
247+
options.minimumProgressIncrement ?? 0.0025,
250248
options.progress || (() => {}),
251249
);
252250

@@ -523,7 +521,7 @@ const enrichedError = (err: any): DeviceError => {
523521
};
524522

525523
const rateLimitProgress = (
526-
miniumProgressIncrement: number,
524+
minimumProgressIncrement: number,
527525
callback: (value: number | undefined, partial: boolean) => void,
528526
) => {
529527
let lastCallValue = -1;
@@ -532,7 +530,7 @@ const rateLimitProgress = (
532530
value === undefined ||
533531
value === 0 ||
534532
value === 1 ||
535-
value >= lastCallValue + miniumProgressIncrement
533+
value >= lastCallValue + minimumProgressIncrement
536534
) {
537535
lastCallValue = value ?? -1;
538536
callback(value, partial);

0 commit comments

Comments
 (0)