uart write sim support (#1933)
* pass data to uart without prefix * added NEW_LINE support
This commit is contained in:
		@@ -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 ""
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user