2016-08-30 20:51:32 +02:00
|
|
|
namespace pxsim {
|
|
|
|
/**
|
|
|
|
* Error codes used in the micro:bit runtime.
|
|
|
|
*/
|
|
|
|
export enum PanicCode {
|
|
|
|
// PANIC Codes. These are not return codes, but are terminal conditions.
|
|
|
|
// These induce a panic operation, where all code stops executing, and a panic state is
|
|
|
|
// entered where the panic code is diplayed.
|
|
|
|
|
|
|
|
// Out out memory error. Heap storage was requested, but is not available.
|
|
|
|
MICROBIT_OOM = 20,
|
|
|
|
|
|
|
|
// Corruption detected in the micro:bit heap space
|
|
|
|
MICROBIT_HEAP_ERROR = 30,
|
|
|
|
|
|
|
|
// Dereference of a NULL pointer through the ManagedType class,
|
|
|
|
MICROBIT_NULL_DEREFERENCE = 40,
|
|
|
|
};
|
|
|
|
|
|
|
|
export function panic(code: number) {
|
|
|
|
console.log("PANIC:", code)
|
|
|
|
throw new Error("PANIC " + code)
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RuntimeOptions {
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace pxsim.basic {
|
|
|
|
export var pause = thread.pause;
|
|
|
|
export var forever = thread.forever;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace pxsim.control {
|
|
|
|
export var inBackground = thread.runInBackground;
|
|
|
|
|
|
|
|
export function reset() {
|
|
|
|
U.userError("reset not implemented in simulator yet")
|
|
|
|
}
|
|
|
|
|
|
|
|
export function waitMicros(micros: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deviceName(): string {
|
|
|
|
let b = board();
|
|
|
|
return b && b.id
|
|
|
|
? b.id.slice(0, 4)
|
|
|
|
: "abcd";
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deviceSerialNumber(): number {
|
|
|
|
let b = board();
|
|
|
|
return parseInt(b && b.id
|
|
|
|
? b.id.slice(1)
|
|
|
|
: "42");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function onEvent(id: number, evid: number, handler: RefAction) {
|
2016-09-01 14:06:03 +02:00
|
|
|
pxtcore.registerWithDal(id, evid, handler)
|
2016-08-30 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function raiseEvent(id: number, evid: number, mode: number) {
|
|
|
|
// TODO mode?
|
|
|
|
board().bus.queue(id, evid)
|
|
|
|
}
|
2017-08-01 18:58:16 +02:00
|
|
|
|
2018-06-18 20:42:35 +02:00
|
|
|
export function eventTimestamp() {
|
|
|
|
return board().bus.getLastEventTime()
|
|
|
|
}
|
|
|
|
|
|
|
|
export function eventValue() {
|
|
|
|
return board().bus.getLastEventValue()
|
|
|
|
}
|
2016-08-30 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
2016-09-01 14:06:03 +02:00
|
|
|
namespace pxsim.pxtcore {
|
2016-08-30 20:51:32 +02:00
|
|
|
export function registerWithDal(id: number, evid: number, handler: RefAction) {
|
|
|
|
board().bus.listen(id, evid, handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace pxsim.input {
|
|
|
|
export function runningTime(): number {
|
|
|
|
return runtime.runningTime();
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:42:35 +02:00
|
|
|
export function runningTimeMicros(): number {
|
|
|
|
return runtime.runningTimeUs();
|
|
|
|
}
|
2017-10-11 20:31:07 +02:00
|
|
|
|
2017-04-25 19:46:25 +02:00
|
|
|
export function calibrateCompass() {
|
|
|
|
// device calibrates...
|
2016-08-30 20:51:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace pxsim.pins {
|
|
|
|
export function onPulsed(name: number, pulse: number, body: RefAction) {
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pulseDuration(): number {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createBuffer(sz: number) {
|
|
|
|
return pxsim.BufferMethods.createBuffer(sz)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function pulseIn(name: number, value: number, maxDuration: number): number {
|
|
|
|
let pin = getPin(name);
|
|
|
|
if (!pin) return 0;
|
|
|
|
|
|
|
|
return 5000;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function spiWrite(value: number): number {
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-26 02:19:25 +02:00
|
|
|
export function spiFrequency(f: number): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
export function spiFormat(bits: number, mode: number): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
export function spiPins(mosi: number, miso: number, sck: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2016-08-30 20:51:32 +02:00
|
|
|
export function i2cReadBuffer(address: number, size: number, repeat?: boolean): RefBuffer {
|
|
|
|
// fake reading zeros
|
|
|
|
return createBuffer(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function i2cWriteBuffer(address: number, buf: RefBuffer, repeat?: boolean): void {
|
|
|
|
// fake - noop
|
|
|
|
}
|
2016-09-29 11:47:50 +02:00
|
|
|
|
|
|
|
// this likely shouldn't be called
|
|
|
|
export function getPinAddress(name: number) {
|
|
|
|
return getPin(name)
|
|
|
|
}
|
2017-01-30 20:19:54 +01:00
|
|
|
|
|
|
|
export function setEvents(name: number, event: number) {
|
|
|
|
}
|
2016-08-30 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
2016-09-19 18:49:58 +02:00
|
|
|
namespace pxsim.devices {
|
|
|
|
export function tellCameraTo(action: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function tellRemoteControlTo(action: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function raiseAlertTo(action: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function onSignalStrengthChanged(action: number) {
|
|
|
|
// TODO
|
|
|
|
}
|
2016-11-30 13:27:08 +01:00
|
|
|
export function signalStrength(): number {
|
2016-09-19 18:49:58 +02:00
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
export function onGamepadButton(button: number, body: RefAction) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 20:51:32 +02:00
|
|
|
namespace pxsim.bluetooth {
|
|
|
|
export function startIOPinService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function startLEDService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function startTemperatureService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function startMagnetometerService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function startAccelerometerService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
export function startButtonService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
2016-09-15 18:40:58 +02:00
|
|
|
export function startUartService(): void {
|
|
|
|
// TODO
|
|
|
|
}
|
2017-10-11 22:37:34 +02:00
|
|
|
export function uartWriteString(s: string): void {
|
2016-11-30 13:27:08 +01:00
|
|
|
serial.writeString(s)
|
2016-09-15 18:40:58 +02:00
|
|
|
}
|
2016-10-19 06:36:42 +02:00
|
|
|
export function uartReadUntil(del: string): string {
|
2016-11-30 13:27:08 +01:00
|
|
|
return serial.readUntil(del);
|
2016-09-15 18:40:58 +02:00
|
|
|
}
|
2017-10-11 22:37:34 +02:00
|
|
|
export function onUartDataReceived(delimiters: string, handler: RefAction) {
|
2017-04-28 10:05:04 +02:00
|
|
|
let b = board();
|
|
|
|
b.bus.listen(DAL.MICROBIT_ID_BLE_UART, DAL.MICROBIT_UART_S_EVT_DELIM_MATCH, handler);
|
|
|
|
}
|
2016-11-30 13:27:08 +01:00
|
|
|
export function onBluetoothConnected(a: RefAction) {
|
2016-09-15 18:40:58 +02:00
|
|
|
// TODO
|
|
|
|
}
|
2016-11-30 13:27:08 +01:00
|
|
|
export function onBluetoothDisconnected(a: RefAction) {
|
2016-09-15 18:40:58 +02:00
|
|
|
// TODO
|
|
|
|
}
|
2016-12-07 18:05:03 +01:00
|
|
|
export function advertiseUrl(url: string, power: number, connectable: boolean) { }
|
2017-05-12 13:49:41 +02:00
|
|
|
export function advertiseUidBuffer(nsAndInstance: RefBuffer, power: number, connectable: boolean) { }
|
2016-11-30 13:27:08 +01:00
|
|
|
export function stopAdvertising() { }
|
2017-05-26 02:19:25 +02:00
|
|
|
export function setTransmitPower(power: number) { }
|
2016-08-30 20:51:32 +02:00
|
|
|
}
|
|
|
|
|