BLE HF2 log service (#1549)
* basic hf2 service * service to send hf2 log messages * use common console.log * updated shims * adding config * adding simulator * fix hf2 logging * hide console blocks
This commit is contained in:
@ -205,6 +205,12 @@
|
||||
"basic.showString": "Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.",
|
||||
"basic.showString|param|interval": "how fast to shift characters; eg: 150, 100, 200, -100",
|
||||
"basic.showString|param|text": "the text to scroll on the screen, eg: \"Hello!\"",
|
||||
"console": "Reading and writing data to the console output.",
|
||||
"console.addListener": "Adds a listener for the log messages",
|
||||
"console.log": "Write a line of text to the console output.",
|
||||
"console.logValue": "Write a name:value pair as a line of text to the console output.",
|
||||
"console.logValue|param|name": "name of the value stream, eg: \"x\"",
|
||||
"console.logValue|param|value": "to write",
|
||||
"control": "Runtime and event utilities.",
|
||||
"control.assert": "If the condition is false, display msg on serial console, and panic with code 098.",
|
||||
"control.createBuffer": "Create a new zero-initialized buffer.",
|
||||
|
@ -240,6 +240,7 @@
|
||||
"basic.showNumber|block": "show|number %number",
|
||||
"basic.showString|block": "show|string %text",
|
||||
"basic|block": "basic",
|
||||
"console|block": "console",
|
||||
"control.deviceName|block": "device name",
|
||||
"control.deviceSerialNumber|block": "device serial number",
|
||||
"control.eventSourceId|block": "%id",
|
||||
|
@ -228,8 +228,9 @@ void debuglog(const char *format, ...)
|
||||
va_end(arg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sendSerial(const char *data, int len) {
|
||||
logwriten(data, len);
|
||||
}
|
||||
|
||||
} // namespace pxt
|
||||
|
||||
|
53
libs/core/console.ts
Normal file
53
libs/core/console.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/**
|
||||
* Reading and writing data to the console output.
|
||||
*/
|
||||
//% weight=12 color=#002050 icon="\uf120"
|
||||
//% advanced=true
|
||||
namespace console {
|
||||
type Listener = (text: string) => void;
|
||||
|
||||
//% whenUsed
|
||||
let listeners: Listener[] = undefined;
|
||||
|
||||
/**
|
||||
* Write a line of text to the console output.
|
||||
* @param value to send
|
||||
*/
|
||||
//% weight=90
|
||||
//% help=console/log blockGap=8
|
||||
//% text.shadowOptions.toString=true
|
||||
export function log(text: string): void {
|
||||
// pad text on the 32byte boundar
|
||||
text += "\r\n";
|
||||
control.__log(text);
|
||||
// send to listeners
|
||||
if (listeners)
|
||||
for (let i = 0; i < listeners.length; ++i)
|
||||
listeners[i](text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a name:value pair as a line of text to the console output.
|
||||
* @param name name of the value stream, eg: "x"
|
||||
* @param value to write
|
||||
*/
|
||||
//% weight=88 blockGap=8
|
||||
//% help=console/log-value
|
||||
export function logValue(name: string, value: number): void {
|
||||
log(name ? `${name}: ${value}` : `${value}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for the log messages
|
||||
* @param listener
|
||||
*/
|
||||
//%
|
||||
export function addListener(listener: (text: string) => void) {
|
||||
if (!listener) return;
|
||||
if (!listener)
|
||||
listeners = [];
|
||||
listeners.push(listener);
|
||||
}
|
||||
}
|
@ -311,4 +311,13 @@ namespace control {
|
||||
void __midiSend(Buffer buffer) {
|
||||
// this is a stub to support the simulator
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
//%
|
||||
void __log(String text) {
|
||||
if (NULL == text) return;
|
||||
pxt::sendSerial(text->data, text->length);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,3 @@
|
||||
namespace console {
|
||||
export function log(msg: string) {
|
||||
serial.writeString(msg);
|
||||
serial.writeString("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
namespace Math {
|
||||
/**
|
||||
* Generates a `true` or `false` value randomly, just like flipping a coin.
|
||||
|
@ -29,6 +29,7 @@
|
||||
"gestures.jres",
|
||||
"control.ts",
|
||||
"control.cpp",
|
||||
"console.ts",
|
||||
"game.ts",
|
||||
"led.cpp",
|
||||
"led.ts",
|
||||
|
6
libs/core/shims.d.ts
vendored
6
libs/core/shims.d.ts
vendored
@ -440,6 +440,12 @@ declare namespace control {
|
||||
*/
|
||||
//% part=midioutput blockHidden=1 shim=control::__midiSend
|
||||
function __midiSend(buffer: Buffer): void;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
//% shim=control::__log
|
||||
function __log(text: string): void;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user