From 3477d40ce07eb67eb163eac788f3b4d1c66d2f29 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 21 Mar 2019 10:22:24 -0700 Subject: [PATCH] uart write sim support (#1933) * pass data to uart without prefix * added NEW_LINE support --- libs/bluetooth/bluetooth.ts | 11 ++++++----- libs/core/serial.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index 482f92cb..b3fc0c1e 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -4,6 +4,8 @@ */ //% color=#007EF4 weight=96 icon="\uf294" namespace bluetooth { + export let NEW_LINE = "\r\n"; + /** * Internal use */ @@ -20,8 +22,7 @@ namespace bluetooth { //% blockId=bluetooth_uart_write block="bluetooth uart|write string %data" blockGap=8 //% parts="bluetooth" shim=bluetooth::uartWriteString advanced=true export function uartWriteString(data: string): void { - // dummy implementation for simulator - console.log("UART Write: " + data) + console.log(data) } /** @@ -31,7 +32,7 @@ namespace bluetooth { //% blockId=bluetooth_uart_line block="bluetooth uart|write line %data" blockGap=8 //% parts="bluetooth" advanced=true export function uartWriteLine(data: string): void { - uartWriteString(data + "\r\n"); + uartWriteString(data + serial.NEW_LINE); } /** @@ -53,7 +54,7 @@ namespace bluetooth { //% help=bluetooth/uart-write-value advanced=true //% blockId=bluetooth_uart_writevalue block="bluetooth uart|write value %name|= %value" export function uartWriteValue(name: string, value: number): void { - uartWriteString(name + ":" + value + "\r\n"); + uartWriteString((name ? name + ":" : "") + value + NEW_LINE); } /** @@ -64,7 +65,7 @@ namespace bluetooth { //% parts="bluetooth" shim=bluetooth::uartReadUntil advanced=true export function uartReadUntil(del: string): string { // dummy implementation for simulator - return "???" + return "" } /** diff --git a/libs/core/serial.ts b/libs/core/serial.ts index 60e7fd78..ed6a45cc 100644 --- a/libs/core/serial.ts +++ b/libs/core/serial.ts @@ -4,6 +4,11 @@ //% weight=2 color=#002050 icon="\uf287" //% advanced=true namespace serial { + /** + * The string used to mark a new line, default is \r\n + */ + export let NEW_LINE = "\r\n"; + /** * Print a line of text to the serial port * @param value to send over serial @@ -20,7 +25,7 @@ namespace serial { serial.writeString(text); for (let i = 0; i < r; ++i) serial.writeString(" "); - serial.writeString("\r\n"); + serial.writeString(NEW_LINE); } /** @@ -57,7 +62,7 @@ namespace serial { //% help=serial/write-value //% blockId=serial_writevalue block="serial|write value %name|= %value" export function writeValue(name: string, value: number): void { - writeLine(name + ":" + value); + writeLine((name ? name + ":" : "") + value); } /**