Versión de Firmware con funciones de RAM incorporadas.
Dependencies: mbed
Fork of VmRecorderV1dot1 by
RingBuffer/Buffering.cpp
- Committer:
- JuanManuelAmador
- Date:
- 2015-07-14
- Revision:
- 2:e818c80e6d5c
- Parent:
- 0:3d456b8ce449
File content as of revision 2:e818c80e6d5c:
#include "Buffering.h" Buffering::Buffering() { for(int i = 0; i < BUFFERSIZE; i++){ data[i] = 0; } windex = 0; rindex = 0; full = false; empty = true; bufSize = BUFFERSIZE; } void Buffering::put(int16_t val) { if(!full) { data[windex] = val; windex++; empty = false; if(windex >= bufSize) { windex = 0; } if(getDif() >= bufSize - 1){ full = true; } /*if(windex >= rindex) { full = true; }*/ } } int16_t Buffering::get() { int16_t temp = 0; if(!empty) { temp = data[rindex]; data[rindex] = 0; full = false; rindex++; if(rindex >= bufSize) { rindex = 0; } if(getDif() == 0){ empty = true; } /*if(rindex >= windex) { empty = true; }*/ } return temp; } bool Buffering::isFull() { return full; } bool Buffering::isEmpty() { return empty; } int Buffering::getSize() { return bufSize; } unsigned int Buffering::getWritingIndex() { return windex; } unsigned int Buffering::getReadingIndex() { return rindex; } unsigned int Buffering::getDif() { unsigned int dif = 0; if((int)(windex-rindex)>=0) { dif = windex-rindex; } else { dif = bufSize+windex-rindex; } return dif; }