pxt-calliope/libs/core/control.ts

50 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2016-04-06 01:54:09 +02:00
/**
* Runtime and event utilities.
*/
2017-01-20 05:55:31 +01:00
//% weight=1 color="#42495F" icon="\uf233"
//% advanced=true
2016-03-10 23:01:04 +01:00
namespace control {
/**
* Returns the value of a C++ runtime constant
*/
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% shim=TD_ID advanced=true
export function eventSourceId(id: EventBusSource): number {
return id;
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID advanced=true
export function eventValueId(id: EventBusValue): number {
return id;
}
/**
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code: number) { }
/**
* 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-07-18 11:12:00 +02:00
}
2016-04-12 04:44:49 +02:00
}
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
export function runtimeWarning(message: string) { }
2016-04-12 04:44:49 +02:00
}