-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwasm.ts
More file actions
57 lines (47 loc) · 1.37 KB
/
wasm.ts
File metadata and controls
57 lines (47 loc) · 1.37 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
import { Board } from ".";
import * as conversions from "./conversions";
import { FileSystem } from "./fs";
export interface EmscriptenModule {
cwrap: any;
ExitStatus: Error;
// See EXPORTED_FUNCTIONS in the Makefile.
_mp_js_request_stop(): void;
_mp_js_force_stop(): void;
_microbit_hal_audio_raw_ready_callback(): void;
_microbit_hal_audio_speech_ready_callback(): void;
_microbit_hal_gesture_callback(gesture: number): void;
_microbit_hal_level_detector_callback(level: number): void;
_microbit_radio_rx_buffer(): number;
HEAPU8: Uint8Array;
HEAPU32: Uint32Array;
// Added by us at module creation time for jshal to access.
board: Board;
fs: FileSystem;
conversions: typeof conversions;
}
export class ModuleWrapper {
private main: () => Promise<void>;
constructor(private module: EmscriptenModule) {
const main = module.cwrap("mp_js_main", "null", ["number"], {
async: true,
});
this.main = () => main(64 * 1024);
}
/**
* Throws PanicError if MicroPython panics.
*/
async start(): Promise<void> {
return this.main!();
}
requestStop(): void {
this.module._mp_js_request_stop();
}
forceStop(): void {
this.module._mp_js_force_stop();
}
writeRadioRxBuffer(packet: Uint8Array) {
const buf = this.module._microbit_radio_rx_buffer!();
this.module.HEAPU8.set(packet, buf);
return buf;
}
}