aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/usb_serial.cpp
diff options
context:
space:
mode:
authorAJM <poslathian@poslathian.(none)>2010-12-13 22:09:12 -0500
committerAJM <poslathian@poslathian.(none)>2010-12-13 22:09:12 -0500
commita2ee93f95a128ede3a83c442eee6f6afe5c92c1e (patch)
treee7f3e32346c0cd5a536bb2005d6fc63a541b6412 /wirish/usb_serial.cpp
parent873356a31fae8cf4e8b6a5ab609125a5a501d1c4 (diff)
downloadlibrambutan-a2ee93f95a128ede3a83c442eee6f6afe5c92c1e.tar.gz
librambutan-a2ee93f95a128ede3a83c442eee6f6afe5c92c1e.zip
made SerialUSB.read blocking
it should have been blocking before but wasnt. see bug #49
Diffstat (limited to 'wirish/usb_serial.cpp')
-rw-r--r--wirish/usb_serial.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp
index 5c8a65f..d4a8148 100644
--- a/wirish/usb_serial.cpp
+++ b/wirish/usb_serial.cpp
@@ -101,17 +101,27 @@ uint32 USBSerial::available(void) {
return usbBytesAvailable();
}
+/* blocks forever until len_bytes is received */
uint32 USBSerial::read(void *buf, uint32 len) {
if (!buf) {
return 0;
}
- return usbReceiveBytes((uint8*)buf, len);
+ uint32 bytes_in = 0;
+ while (len > 0) {
+ uint32 new_bytes = usbReceiveBytes(&(uint8)buf[new_bytes], len);
+ len -= newBytes;
+ bytes_in += new_bytes;
+ }
+
+ return len;
}
+/* blocks forever until 1 byte is received */
uint8 USBSerial::read(void) {
uint8 ch;
- usbReceiveBytes(&ch, 1);
+
+ while (usbReceiveBytes(&ch, 1) == 0);
return ch;
}