Skip to content

Commit

Permalink
Use SYNC_SPIN_WAIT for serial write and explicitely set SYNC_SLEEP fo…
Browse files Browse the repository at this point in the history
…r read

Fix microsoft#1157
  • Loading branch information
philipphenkel committed Oct 3, 2018
1 parent 583bdff commit b72ad9a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libs/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b72ad9a

Please sign in to comment.