From b06501baeeb2049ea64d43c4f1c95027705682a2 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 10 Oct 2016 12:43:14 +0200 Subject: [PATCH] Fix regression: SerialUSB.available() do not return correct values Fix #172 --- cores/arduino/USB/SAMD21_USBDevice.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USB/SAMD21_USBDevice.h b/cores/arduino/USB/SAMD21_USBDevice.h index 7d4c7b81c..738e73413 100644 --- a/cores/arduino/USB/SAMD21_USBDevice.h +++ b/cores/arduino/USB/SAMD21_USBDevice.h @@ -350,7 +350,19 @@ class DoubleBufferedEPOutHandler : public EPHandler { // Returns how many bytes are stored in the buffers virtual uint32_t available() const { - return (last0 - first0) + (last1 - first1); + if (current == 0) { + bool ready = false; + synchronized { + ready = ready0; + } + return ready ? (last0 - first0) : 0; + } else { + bool ready = false; + synchronized { + ready = ready1; + } + return ready ? (last1 - first1) : 0; + } } void release() {