pxt-calliope/libs/microbit/control.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-04-06 01:54:09 +02:00
/**
* Runtime and event utilities.
*/
2016-03-26 05:13:09 +01:00
//% weight=1 color="#333333"
2016-03-10 23:01:04 +01:00
namespace control {
2016-03-30 02:11:17 +02:00
2016-03-10 23:01:04 +01:00
/**
2016-03-30 02:11:17 +02:00
* Returns the value of a C++ runtime constant
2016-03-10 23:01:04 +01:00
*/
2016-05-17 01:24:44 +02:00
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
export function eventSourceId(id: EventBusSource): number {
2016-03-30 02:11:17 +02:00
return id;
}
2016-03-28 09:23:00 +02:00
/**
2016-03-30 02:11:17 +02:00
* Returns the value of a C++ runtime constant
2016-03-28 09:23:00 +02:00
*/
2016-05-17 01:24:44 +02:00
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
export function eventValueId(id: EventBusValue): number {
2016-03-30 02:11:17 +02:00
return id;
}
2016-04-12 04:44:49 +02:00
/**
* Display specified error code and stop the program.
*/
2016-04-12 05:54:26 +02:00
//% shim=pxtrt::panic
2016-07-18 11:12:00 +02:00
export function panic(code: number) { }
2016-04-12 04:44:49 +02:00
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
2016-07-18 11:12:00 +02:00
export function assert(condition: boolean, msg ?: string) {
2016-04-12 04:44:49 +02:00
if (!condition) {
console.log("ASSERTION FAILED")
2016-07-18 11:12:00 +02:00
if (msg != null) {
2016-04-12 04:44:49 +02:00
console.log(msg)
2016-07-18 11:12:00 +02:00
}
2016-04-12 04:44:49 +02:00
panic(98)
}
}
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
2016-09-09 22:43:41 +02:00
export function runtimeWarning(message: string) { }
2016-03-10 23:01:04 +01:00
}