Skip to content

Commit

Permalink
Fixed a name conflict between RingBuffer template and a RingBuffer cl…
Browse files Browse the repository at this point in the history
…ass used in ARM Arduino core. Changer RingBuffer to RingBuf. Version 1.0.2
  • Loading branch information
Koryphon committed Nov 29, 2018
1 parent 58bc55b commit 8b5eaa5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A simple and easy to use ring buffer library for Arduino. Interrupt safe functions are provided too.

## Changelog

- 1.0.2 Changed the name of the template from RingBuffer to RingBuf in order to avoid a name conflict with and internal RingBuffer class used in the ARM version of the Arduino core.
- 1.0.1 Fix a mistake in pop documentation
- 1.0 Initial release.

## Limitation

The size of the ring buffer is limited to 255 elements. The compiler will not prevent you from declaring a buffer size 0 but a size 0 is not supported (and otherwise silly). Among the quirks with a size of 0 is the fact that the buffer is both empty and full.
Expand All @@ -11,19 +17,19 @@ The size of the ring buffer is limited to 255 elements. The compiler will not pr
First include the header in your sketch

```
#include <RingBuffer.h>
#include <RingBuf.h>
```

Instantiate a ring buffer by using the following syntax:

```
RingBuffer<type, size> myRingBuffer;
RingBuf<type, size> myRingBuffer;
```

```type``` is the type name of each element of the ring buffer. ```size``` is the size, from 1 to 255, of the ring buffer. For instance the declaration shown below instantiate a ring buffer where each element is a ```byte``` with a size of 20.

```
RingBuffer<byte, 20> aBuffer;
RingBuf<byte, 20> aBuffer;
```

## Functions
Expand Down
5 changes: 0 additions & 5 deletions changelog.txt

This file was deleted.

10 changes: 5 additions & 5 deletions examples/BufferInterrupt/BufferInterrupt.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* Communication between the interrupt handler and the main program
*
*
* The interrupt handler is executed when a falling edge appear on pin 2
* It pushes the current date in microseconds.
*
*
* Use it with a push button to see the bounces
*/
#include <RingBuffer.h>
RingBuffer<uint32_t, 10> comBuffer;
#include <RingBuf.h>

RingBuf<uint32_t, 10> comBuffer;

void externalInterruptHandler()
{
Expand Down
4 changes: 2 additions & 2 deletions examples/PushAndPop/PushAndPop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
*/

#include <RingBuffer.h>
#include <RingBuf.h>

RingBuffer<uint8_t, 10> myBuffer;
RingBuf<uint8_t, 10> myBuffer;

void setup()
{
Expand Down
2 changes: 1 addition & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Datatypes (KEYWORD1)
#######################################

RingBuffer KEYWORD1
RingBuf KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=RingBuffer
version=1.0.1
version=1.0.2
author=Jean-Luc - Locoduino
maintainer=Jean-Luc - Locoduino
sentence=This library allows to use ring buffer with and without interrupts.
paragraph=RingBuffer is a library for ring buffers. Elements can be of arbitrate type.
category=Data Storage
includes=RingBuffer.h
includes=RingBuf.h
url=https://github.com/Locoduino/RingBuffer
architectures=*
28 changes: 14 additions & 14 deletions src/RingBuffer.h → src/RingBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
* subject to such reorganizations.
*/

#ifndef __RINGBUFFER_H__
#define __RINGBUFFER_H__
#ifndef __RINGBUF_H__
#define __RINGBUF_H__

#include <Arduino.h>

template <typename rg_element_t, uint8_t __maxSize__>
class RingBuffer
class RingBuf
{
private:
rg_element_t mBuffer[__maxSize__];
Expand All @@ -59,7 +59,7 @@ class RingBuffer

public:
/* Constructor. Init mReadIndex to 0 and mSize to 0 */
RingBuffer();
RingBuf();
/* Push a data at the end of the buffer */
bool push(const rg_element_t inElement) __attribute__ ((noinline));
/* Push a data at the end of the buffer. Copy it from its pointer */
Expand Down Expand Up @@ -87,22 +87,22 @@ class RingBuffer
};

template <typename rg_element_t, uint8_t __maxSize__>
uint8_t RingBuffer<rg_element_t, __maxSize__>::writeIndex()
uint8_t RingBuf<rg_element_t, __maxSize__>::writeIndex()
{
uint16_t wi = (uint16_t)mReadIndex + (uint16_t)mSize;
if (wi >= (uint16_t)__maxSize__) wi -= (uint16_t)__maxSize__;
return (uint8_t)wi;
}

template <typename rg_element_t, uint8_t __maxSize__>
RingBuffer<rg_element_t, __maxSize__>::RingBuffer() :
RingBuf<rg_element_t, __maxSize__>::RingBuf() :
mReadIndex(0),
mSize(0)
{
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::push(const rg_element_t inElement)
bool RingBuf<rg_element_t, __maxSize__>::push(const rg_element_t inElement)
{
if (isFull()) return false;
mBuffer[writeIndex()] = inElement;
Expand All @@ -111,7 +111,7 @@ bool RingBuffer<rg_element_t, __maxSize__>::push(const rg_element_t inElement)
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::push(const rg_element_t * const inElement)
bool RingBuf<rg_element_t, __maxSize__>::push(const rg_element_t * const inElement)
{
if (isFull()) return false;
mBuffer[writeIndex()] = *inElement;
Expand All @@ -120,7 +120,7 @@ bool RingBuffer<rg_element_t, __maxSize__>::push(const rg_element_t * const inEl
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::lockedPush(const rg_element_t inElement)
bool RingBuf<rg_element_t, __maxSize__>::lockedPush(const rg_element_t inElement)
{
noInterrupts();
bool result = push(inElement);
Expand All @@ -129,7 +129,7 @@ bool RingBuffer<rg_element_t, __maxSize__>::lockedPush(const rg_element_t inElem
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::lockedPush(const rg_element_t * const inElement)
bool RingBuf<rg_element_t, __maxSize__>::lockedPush(const rg_element_t * const inElement)
{
noInterrupts();
bool result = push(inElement);
Expand All @@ -138,7 +138,7 @@ bool RingBuffer<rg_element_t, __maxSize__>::lockedPush(const rg_element_t * cons
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::pop(rg_element_t &outElement)
bool RingBuf<rg_element_t, __maxSize__>::pop(rg_element_t &outElement)
{
if (isEmpty()) return false;
outElement = mBuffer[mReadIndex];
Expand All @@ -149,7 +149,7 @@ bool RingBuffer<rg_element_t, __maxSize__>::pop(rg_element_t &outElement)
}

template <typename rg_element_t, uint8_t __maxSize__>
bool RingBuffer<rg_element_t, __maxSize__>::lockedPop(rg_element_t &outElement)
bool RingBuf<rg_element_t, __maxSize__>::lockedPop(rg_element_t &outElement)
{
noInterrupts();
bool result = pop(outElement);
Expand All @@ -158,12 +158,12 @@ bool RingBuffer<rg_element_t, __maxSize__>::lockedPop(rg_element_t &outElement)
}

template <typename rg_element_t, uint8_t __maxSize__>
rg_element_t &RingBuffer<rg_element_t, __maxSize__>::operator[](uint8_t inIndex)
rg_element_t &RingBuf<rg_element_t, __maxSize__>::operator[](uint8_t inIndex)
{
if (inIndex >= mSize) return mBuffer[0];
uint16_t index = (uint16_t)mReadIndex + (uint16_t)inIndex;
if (index >= (uint16_t)__maxSize__) index -= (uint16_t)__maxSize__;
return mBuffer[(uint8_t)index];
}

#endif /* __RINGBUFFER_H__ */
#endif /* __RINGBUF_H__ */

0 comments on commit 8b5eaa5

Please sign in to comment.