From e4f7bf513d366d4e47fe969057ab6ae72aca8168 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry <s.mistry@arduino.cc> Date: Tue, 23 Feb 2016 09:36:34 -0500 Subject: [PATCH] Add private availableForStore method, and use in Serial_::accept --- cores/arduino/USB/CDC.cpp | 11 +++++++++++ cores/arduino/USB/USBAPI.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp index 9c38debb..adb3ab07 100644 --- a/cores/arduino/USB/CDC.cpp +++ b/cores/arduino/USB/CDC.cpp @@ -351,6 +351,17 @@ bool Serial_::rts() { return _usbLineInfo.lineState & 0x2; } +int Serial_::availableForStore(void) { + ring_buffer *buffer = &cdc_rx_buffer; + + if (buffer->full) + return 0; + else if (buffer->head >= buffer->tail) + return CDC_SERIAL_BUFFER_SIZE - 1 - buffer->head + buffer->tail; + else + return buffer->tail - buffer->head - 1; +} + Serial_ SerialUSB(USBDevice); #endif diff --git a/cores/arduino/USB/USBAPI.h b/cores/arduino/USB/USBAPI.h index 716edbfd..8573248d 100644 --- a/cores/arduino/USB/USBAPI.h +++ b/cores/arduino/USB/USBAPI.h @@ -168,6 +168,8 @@ public: }; private: + int availableForStore(void); + USBDeviceClass &usb; RingBuffer *_cdc_rx_buffer; }; -- GitLab