Add auto toString for various APIs (#1033)
This commit is contained in:
parent
27024baa51
commit
2700a77cae
@ -33,6 +33,7 @@ namespace basic {
|
||||
//% async
|
||||
//% blockId=device_print_message
|
||||
//% parts="ledmatrix"
|
||||
//% text.shadowOptions.toString=true
|
||||
void showString(String text, int interval = 150) {
|
||||
if (interval <= 0)
|
||||
interval = 1;
|
||||
|
@ -103,6 +103,7 @@ namespace serial {
|
||||
//% help=serial/write-string
|
||||
//% weight=87 blockGap=8
|
||||
//% blockId=serial_writestring block="serial|write string %text"
|
||||
//% text.shadowOptions.toString=true
|
||||
void writeString(String text) {
|
||||
if (!text) return;
|
||||
|
||||
@ -129,7 +130,7 @@ namespace serial {
|
||||
Buffer readBuffer(int length) {
|
||||
if (length <= 0)
|
||||
length = MICROBIT_SERIAL_READ_BUFFER_LENGTH;
|
||||
|
||||
|
||||
auto buf = mkBuffer(NULL, length);
|
||||
int read = uBit.serial.read(buf->data, buf->length);
|
||||
if (read != length) {
|
||||
@ -168,7 +169,7 @@ namespace serial {
|
||||
* Direct the serial input and output to use the USB connection.
|
||||
*/
|
||||
//% weight=9 help=serial/redirect-to-usb
|
||||
//% blockId=serial_redirect_to_usb block="serial|redirect to USB"
|
||||
//% blockId=serial_redirect_to_usb block="serial|redirect to USB"
|
||||
void redirectToUSB() {
|
||||
uBit.serial.redirect(USBTX, USBRX);
|
||||
uBit.serial.baud(115200);
|
||||
|
@ -5,12 +5,13 @@
|
||||
//% advanced=true
|
||||
namespace serial {
|
||||
/**
|
||||
* Print a line of text to the serial port
|
||||
* Print a line of text to the serial port
|
||||
* @param value to send over serial
|
||||
*/
|
||||
//% weight=90
|
||||
//% help=serial/write-line blockGap=8
|
||||
//% blockId=serial_writeline block="serial|write line %text"
|
||||
//% text.shadowOptions.toString=true
|
||||
export function writeLine(text: string): void {
|
||||
if (!text) text = "";
|
||||
// pad data to the 32 byte boundary
|
||||
@ -77,7 +78,7 @@ namespace serial {
|
||||
export function delimiters(del: Delimiters): string {
|
||||
// even though it might not look like, this is more
|
||||
// (memory) efficient than the C++ implementation, because the
|
||||
// strings are statically allocated and take no RAM
|
||||
// strings are statically allocated and take no RAM
|
||||
switch (del) {
|
||||
case Delimiters.NewLine: return "\n"
|
||||
case Delimiters.Comma: return ","
|
||||
|
6
libs/core/shims.d.ts
vendored
6
libs/core/shims.d.ts
vendored
@ -153,7 +153,8 @@ declare namespace basic {
|
||||
//% block="show|string %text"
|
||||
//% async
|
||||
//% blockId=device_print_message
|
||||
//% parts="ledmatrix" interval.defl=150 shim=basic::showString
|
||||
//% parts="ledmatrix"
|
||||
//% text.shadowOptions.toString=true interval.defl=150 shim=basic::showString
|
||||
function showString(text: string, interval?: int32): void;
|
||||
|
||||
/**
|
||||
@ -791,7 +792,8 @@ declare namespace serial {
|
||||
*/
|
||||
//% help=serial/write-string
|
||||
//% weight=87 blockGap=8
|
||||
//% blockId=serial_writestring block="serial|write string %text" shim=serial::writeString
|
||||
//% blockId=serial_writestring block="serial|write string %text"
|
||||
//% text.shadowOptions.toString=true shim=serial::writeString
|
||||
function writeString(text: string): void;
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ namespace radio {
|
||||
memcpy(buf + 1, data->data, len);
|
||||
}
|
||||
return len + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Buffer getBufferValue(uint8_t* buf, uint8_t maxLength) {
|
||||
// First byte is the buffer length
|
||||
@ -244,6 +244,7 @@ namespace radio {
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="radio send string %msg"
|
||||
//% msg.shadowOptions.toString=true
|
||||
void sendString(String msg) {
|
||||
if (radioEnable() != MICROBIT_OK || NULL == msg) return;
|
||||
|
||||
|
3
libs/radio/shims.d.ts
vendored
3
libs/radio/shims.d.ts
vendored
@ -30,7 +30,8 @@ declare namespace radio {
|
||||
*/
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="radio send string %msg" shim=radio::sendString
|
||||
//% blockId=radio_datagram_send_string block="radio send string %msg"
|
||||
//% msg.shadowOptions.toString=true shim=radio::sendString
|
||||
function sendString(msg: string): void;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user