Skip to content

Commit

Permalink
Move option to the interface (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon authored Oct 17, 2024
1 parent adf0c90 commit 8e7ec97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
37 changes: 20 additions & 17 deletions lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ export enum ConnectionStatus {
RECONNECTING = "RECONNECTING",
}

export interface FlashOptions {
/**
* True to use a partial flash where possible, false to force a full flash.
*/
partial: boolean;
/**
* A progress callback. Called with undefined when the process is complete or has failed.
*
* Requesting a partial flash doesn't guarantee one is performed. Partial flashes are avoided
* if too many blocks have changed and failed partial flashes are retried as full flashes.
* The partial parameter reports the flash type currently in progress.
*/
progress: (percentage: number | undefined, partial: boolean) => void;
/**
* Smallest possible progress increment to limit callback rate.
*/
minimumProgressIncrement?: number;
}

export class FlashDataError extends Error {}

export type FlashDataSource = (
Expand Down Expand Up @@ -201,23 +220,7 @@ export interface DeviceConnection
* @param dataSource The data to use.
* @param options Flash options and progress callback.
*/
flash?(
dataSource: FlashDataSource,
options: {
/**
* True to use a partial flash where possible, false to force a full flash.
*/
partial: boolean;
/**
* A progress callback. Called with undefined when the process is complete or has failed.
*
* Requesting a partial flash doesn't guarantee one is performed. Partial flashes are avoided
* if too many blocks have changed and failed partial flashes are retried as full flashes.
* The partial parameter reports the flash type currently in progress.
*/
progress: (percentage: number | undefined, partial: boolean) => void;
},
): Promise<void>;
flash?(dataSource: FlashDataSource, options: {}): Promise<void>;

/**
* Disconnect from the device.
Expand Down
1 change: 1 addition & 0 deletions lib/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FlashDataError,
FlashDataSource,
FlashEvent,
FlashOptions,

Check failure on line 19 in lib/usb.ts

View workflow job for this annotation

GitHub Actions / build

Import declaration conflicts with local declaration of 'FlashOptions'.

Check failure on line 19 in lib/usb.ts

View workflow job for this annotation

GitHub Actions / build

Import declaration conflicts with local declaration of 'FlashOptions'.
SerialDataEvent,
SerialErrorEvent,
SerialResetEvent,
Expand Down

0 comments on commit 8e7ec97

Please sign in to comment.