-
Notifications
You must be signed in to change notification settings - Fork 9
/
process.ts
45 lines (35 loc) · 1.32 KB
/
process.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createNanoEvents } from "nanoevents";
import type { Emitter } from "nanoevents";
export type WebDFUProcessReadEvents = {
process: (done: number, total?: number) => void;
error: (error: any) => void;
end: (data: Blob) => void;
};
export type WebDFUProcessWriteEvents = {
"erase/start": () => void;
"erase/process": WebDFUProcessEraseEvents["process"];
"erase/end": WebDFUProcessEraseEvents["end"];
"write/start": () => void;
"write/process": (bytesSent: number, expectedSize: number) => void;
"write/end": (bytesSent: number) => void;
verify: (status: { status: number; pollTimeout: number; state: number }) => void;
error: (error: any) => void;
end: () => void;
};
export type WebDFUProcessEraseEvents = {
process: (bytesSent: number, expectedSize: number) => void;
error: (error: any) => void;
end: () => void;
};
export interface WebDFUProcess<T> {
events: Emitter<T>;
}
export class WebDFUProcessRead implements WebDFUProcess<WebDFUProcessReadEvents> {
events = createNanoEvents<WebDFUProcessReadEvents>();
}
export class WebDFUProcessWrite implements WebDFUProcess<WebDFUProcessWriteEvents> {
events = createNanoEvents<WebDFUProcessWriteEvents>();
}
export class WebDFUProcessErase implements WebDFUProcess<WebDFUProcessEraseEvents> {
events = createNanoEvents<WebDFUProcessEraseEvents>();
}