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