From b72ad9a860825939fad75ae3764f24a9d68fdae8 Mon Sep 17 00:00:00 2001 From: Philipp Henkel Date: Wed, 3 Oct 2018 16:51:02 +0200 Subject: [PATCH] Use SYNC_SPIN_WAIT for serial write and explicitely set SYNC_SLEEP for read Fix #1157 --- libs/core/serial.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index ddb0ed6dcd0..be7a727afd8 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -69,7 +69,7 @@ namespace serial { //% blockId=serial_read_until block="serial|read until %delimiter=serial_delimiter_conv" //% weight=19 StringData* readUntil(StringData* delimiter) { - return uBit.serial.readUntil(ManagedString(delimiter)).leakData(); + return uBit.serial.readUntil(ManagedString(delimiter), MicroBitSerialMode::SYNC_SLEEP).leakData(); } /** @@ -106,7 +106,7 @@ namespace serial { void writeString(StringData *text) { if (!text) return; - uBit.serial.send(ManagedString(text)); + uBit.serial.send(ManagedString(text), MicroBitSerialMode::SYNC_SPINWAIT); } /** @@ -118,7 +118,7 @@ namespace serial { if (!buffer) return; ManagedBuffer buf(buffer); - uBit.serial.send(buf.getBytes(), buf.length()); + uBit.serial.send(buf.getBytes(), buf.length(), MicroBitSerialMode::SYNC_SPINWAIT); } /** @@ -130,9 +130,9 @@ namespace serial { Buffer readBuffer(int length) { if (length <= 0) length = MICROBIT_SERIAL_READ_BUFFER_LENGTH; - + ManagedBuffer buf(length); - int read = uBit.serial.read(buf.getBytes(), buf.length()); + int read = uBit.serial.read(buf.getBytes(), buf.length(), MicroBitSerialMode::SYNC_SLEEP); if (read != buf.length()) buf = buf.slice(read); @@ -166,7 +166,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);