Add auto toString for various APIs (#1033)

This commit is contained in:
Guillaume Jenkins 2018-08-02 16:30:02 -04:00 committed by GitHub
parent 27024baa51
commit 2700a77cae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 8 deletions

View File

@ -33,6 +33,7 @@ namespace basic {
//% async //% async
//% blockId=device_print_message //% blockId=device_print_message
//% parts="ledmatrix" //% parts="ledmatrix"
//% text.shadowOptions.toString=true
void showString(String text, int interval = 150) { void showString(String text, int interval = 150) {
if (interval <= 0) if (interval <= 0)
interval = 1; interval = 1;

View File

@ -103,6 +103,7 @@ namespace serial {
//% help=serial/write-string //% help=serial/write-string
//% weight=87 blockGap=8 //% weight=87 blockGap=8
//% blockId=serial_writestring block="serial|write string %text" //% blockId=serial_writestring block="serial|write string %text"
//% text.shadowOptions.toString=true
void writeString(String text) { void writeString(String text) {
if (!text) return; if (!text) return;
@ -129,7 +130,7 @@ namespace serial {
Buffer readBuffer(int length) { Buffer readBuffer(int length) {
if (length <= 0) if (length <= 0)
length = MICROBIT_SERIAL_READ_BUFFER_LENGTH; length = MICROBIT_SERIAL_READ_BUFFER_LENGTH;
auto buf = mkBuffer(NULL, length); auto buf = mkBuffer(NULL, length);
int read = uBit.serial.read(buf->data, buf->length); int read = uBit.serial.read(buf->data, buf->length);
if (read != length) { if (read != length) {
@ -168,7 +169,7 @@ namespace serial {
* Direct the serial input and output to use the USB connection. * Direct the serial input and output to use the USB connection.
*/ */
//% weight=9 help=serial/redirect-to-usb //% 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() { void redirectToUSB() {
uBit.serial.redirect(USBTX, USBRX); uBit.serial.redirect(USBTX, USBRX);
uBit.serial.baud(115200); uBit.serial.baud(115200);

View File

@ -5,12 +5,13 @@
//% advanced=true //% advanced=true
namespace serial { 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 * @param value to send over serial
*/ */
//% weight=90 //% weight=90
//% help=serial/write-line blockGap=8 //% help=serial/write-line blockGap=8
//% blockId=serial_writeline block="serial|write line %text" //% blockId=serial_writeline block="serial|write line %text"
//% text.shadowOptions.toString=true
export function writeLine(text: string): void { export function writeLine(text: string): void {
if (!text) text = ""; if (!text) text = "";
// pad data to the 32 byte boundary // pad data to the 32 byte boundary
@ -77,7 +78,7 @@ namespace serial {
export function delimiters(del: Delimiters): string { export function delimiters(del: Delimiters): string {
// even though it might not look like, this is more // even though it might not look like, this is more
// (memory) efficient than the C++ implementation, because the // (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) { switch (del) {
case Delimiters.NewLine: return "\n" case Delimiters.NewLine: return "\n"
case Delimiters.Comma: return "," case Delimiters.Comma: return ","

View File

@ -153,7 +153,8 @@ declare namespace basic {
//% block="show|string %text" //% block="show|string %text"
//% async //% async
//% blockId=device_print_message //% 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; function showString(text: string, interval?: int32): void;
/** /**
@ -791,7 +792,8 @@ declare namespace serial {
*/ */
//% help=serial/write-string //% help=serial/write-string
//% weight=87 blockGap=8 //% 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; function writeString(text: string): void;
/** /**

View File

@ -105,7 +105,7 @@ namespace radio {
memcpy(buf + 1, data->data, len); memcpy(buf + 1, data->data, len);
} }
return len + 1; return len + 1;
} }
Buffer getBufferValue(uint8_t* buf, uint8_t maxLength) { Buffer getBufferValue(uint8_t* buf, uint8_t maxLength) {
// First byte is the buffer length // First byte is the buffer length
@ -244,6 +244,7 @@ namespace radio {
//% help=radio/send-string //% help=radio/send-string
//% weight=58 //% weight=58
//% blockId=radio_datagram_send_string block="radio send string %msg" //% blockId=radio_datagram_send_string block="radio send string %msg"
//% msg.shadowOptions.toString=true
void sendString(String msg) { void sendString(String msg) {
if (radioEnable() != MICROBIT_OK || NULL == msg) return; if (radioEnable() != MICROBIT_OK || NULL == msg) return;

View File

@ -30,7 +30,8 @@ declare namespace radio {
*/ */
//% help=radio/send-string //% help=radio/send-string
//% weight=58 //% 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; function sendString(msg: string): void;
/** /**