pxt-calliope/libs/microbit/control.ts

42 lines
1.0 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-05-17 01:24:44 +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.
*/
export function assert(condition:boolean, msg?: string)
{
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null)
console.log(msg)
panic(98)
}
}
2016-03-10 23:01:04 +01:00
}