Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others
Diff: mx_circular_buffer.h
- Revision:
- 7:709130701ac7
- Parent:
- 4:43abdd8eda40
- Child:
- 17:86034c970ea0
--- a/mx_circular_buffer.h Mon Aug 31 10:29:58 2015 +1000 +++ b/mx_circular_buffer.h Thu Sep 10 20:09:01 2015 +1000 @@ -164,13 +164,20 @@ * @return Number of available bytes in buffer */ CounterType getAvailable() { - CounterType avail; - if (isEmpty()) { + if (_head != _tail) { + CounterType avail; + avail = _head - _tail; + avail %= BufferSize; + return avail; + } + + //Head=Tail. Can be full or empty + if (_full==false) { return 0; } - avail = _head - _tail; - avail %= BufferSize; - return avail; + else { + return BufferSize; + } }