uart write sim support (#1933)

* pass data to uart without prefix

* added NEW_LINE support
This commit is contained in:
Peli de Halleux 2019-03-21 10:22:24 -07:00 committed by GitHub
parent 3840aee859
commit 3477d40ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -4,6 +4,8 @@
*/ */
//% color=#007EF4 weight=96 icon="\uf294" //% color=#007EF4 weight=96 icon="\uf294"
namespace bluetooth { namespace bluetooth {
export let NEW_LINE = "\r\n";
/** /**
* Internal use * Internal use
*/ */
@ -20,8 +22,7 @@ namespace bluetooth {
//% blockId=bluetooth_uart_write block="bluetooth uart|write string %data" blockGap=8 //% blockId=bluetooth_uart_write block="bluetooth uart|write string %data" blockGap=8
//% parts="bluetooth" shim=bluetooth::uartWriteString advanced=true //% parts="bluetooth" shim=bluetooth::uartWriteString advanced=true
export function uartWriteString(data: string): void { export function uartWriteString(data: string): void {
// dummy implementation for simulator console.log(data)
console.log("UART Write: " + data)
} }
/** /**
@ -31,7 +32,7 @@ namespace bluetooth {
//% blockId=bluetooth_uart_line block="bluetooth uart|write line %data" blockGap=8 //% blockId=bluetooth_uart_line block="bluetooth uart|write line %data" blockGap=8
//% parts="bluetooth" advanced=true //% parts="bluetooth" advanced=true
export function uartWriteLine(data: string): void { 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 //% help=bluetooth/uart-write-value advanced=true
//% blockId=bluetooth_uart_writevalue block="bluetooth uart|write value %name|= %value" //% blockId=bluetooth_uart_writevalue block="bluetooth uart|write value %name|= %value"
export function uartWriteValue(name: string, value: number): void { 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 //% parts="bluetooth" shim=bluetooth::uartReadUntil advanced=true
export function uartReadUntil(del: string): string { export function uartReadUntil(del: string): string {
// dummy implementation for simulator // dummy implementation for simulator
return "???" return ""
} }
/** /**

View File

@ -4,6 +4,11 @@
//% weight=2 color=#002050 icon="\uf287" //% weight=2 color=#002050 icon="\uf287"
//% advanced=true //% advanced=true
namespace serial { 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 * Print a line of text to the serial port
* @param value to send over serial * @param value to send over serial
@ -20,7 +25,7 @@ namespace serial {
serial.writeString(text); serial.writeString(text);
for (let i = 0; i < r; ++i) for (let i = 0; i < r; ++i)
serial.writeString(" "); serial.writeString(" ");
serial.writeString("\r\n"); serial.writeString(NEW_LINE);
} }
/** /**
@ -57,7 +62,7 @@ namespace serial {
//% help=serial/write-value //% help=serial/write-value
//% blockId=serial_writevalue block="serial|write value %name|= %value" //% blockId=serial_writevalue block="serial|write value %name|= %value"
export function writeValue(name: string, value: number): void { export function writeValue(name: string, value: number): void {
writeLine(name + ":" + value); writeLine((name ? name + ":" : "") + value);
} }
/** /**