[gnoduino: 95/237] on a CDC or HID write() error, call setWriteError(). better handling of USB_Send errors in CDC.



commit 96c314d2819bb4ce5f8c1257630ae334bfc00f7a
Author: Zach Eveland <zeveland blacklabel-development com>
Date:   Tue Aug 30 17:25:35 2011 -0400

    on a CDC or HID write() error, call setWriteError().  better handling of USB_Send errors in CDC.

 arduino/cores/arduino/CDC.cpp |   10 ++++++++--
 arduino/cores/arduino/HID.cpp |    8 ++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/arduino/cores/arduino/CDC.cpp b/arduino/cores/arduino/CDC.cpp
index b229cb5..0d04b9c 100644
--- a/arduino/cores/arduino/CDC.cpp
+++ b/arduino/cores/arduino/CDC.cpp
@@ -166,9 +166,15 @@ size_t Serial_::write(uint8_t c)
 	// open connection isn't broken cleanly (cable is yanked out, host dies
 	// or locks up, or host virtual serial port hangs)
 	if (_usbLineInfo.lineState > 0)	{
-		USB_Send(CDC_TX,&c,1);
-		return 1;
+		int r = USB_Send(CDC_TX,&c,1);
+		if (r > 0) {
+			return r;
+		} else {
+			setWriteError();
+			return 0;
+		}
 	}
+	setWriteError();
 	return 0;
 }
 
diff --git a/arduino/cores/arduino/HID.cpp b/arduino/cores/arduino/HID.cpp
index cea90fc..e3aadb5 100644
--- a/arduino/cores/arduino/HID.cpp
+++ b/arduino/cores/arduino/HID.cpp
@@ -398,11 +398,15 @@ size_t Keyboard_::write(uint8_t c)
 			_keyMap->charToKey(c,&keys);
 		else
 		{
-			if (c >= 128)
+			if (c >= 128) {
+				setWriteError();
 				return 0;
+			}
 			c = pgm_read_byte(_asciimap + c);
-			if (!c)
+			if (!c) {
+				setWriteError();
 				return 0;
+			}
 			if (c & 0x80)
 			{
 				keys.modifiers |= KEY_MODIFIER_LEFT_SHIFT;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]