2016-04-05 16:54:09 -07:00
|
|
|
/**
|
|
|
|
* Runtime and event utilities.
|
|
|
|
*/
|
2017-01-05 07:01:50 -08:00
|
|
|
//% weight=1 color="#333333" icon="\uf233"
|
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
|
2017-01-31 08:29:25 -08:00
|
|
|
//% shim=TD_ID advanced=true
|
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"
|
2017-01-31 08:29:25 -08:00
|
|
|
//% shim=TD_ID advanced=true
|
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-12-19 14:09:35 -08: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
|
|
|
|
2018-10-25 09:19:49 -07:00
|
|
|
export function fail(message: string) {
|
|
|
|
console.log("Fatal failure: ")
|
|
|
|
console.log(message)
|
|
|
|
panic(108)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2019-04-04 13:41:51 -07:00
|
|
|
|
|
|
|
/**
|
2019-04-08 10:34:09 -07:00
|
|
|
* Convert any value to text
|
|
|
|
* @param value value to be converted to text
|
2019-04-04 13:41:51 -07:00
|
|
|
*/
|
2019-04-08 10:34:09 -07:00
|
|
|
//% help=text/convert-to-text weight=1
|
|
|
|
//% block="convert $value=math_number to text"
|
|
|
|
//% blockId=variable_to_text blockNamespace="text"
|
|
|
|
function convertToText(value: any): string {
|
2019-04-04 13:41:51 -07:00
|
|
|
return "" + value;
|
|
|
|
}
|