![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
skeleton for lab1
Dependencies: AvailableMemory mbed-rtos mbed
Fork of helloaabbc by
RingBuffer.cpp
- Committer:
- mbed36372
- Date:
- 2014-04-04
- Revision:
- 1:55e99f6e2aa5
- Parent:
- 0:1c8f2727e9f5
File content as of revision 1:55e99f6e2aa5:
#include "RingBuffer.h" void RingBuffer::insert(int sample){ if((end+1)%bufSize==start){ start=(start+1)%bufSize; cur=start; count--; } buf[end]=sample; end=(end+1)%bufSize; count++; } int RingBuffer::next(){ int ret=buf[cur]; cur=(cur+1)%bufSize; if ((cur >= end) && (count < bufSize)) cur = start; return ret; } void RingBuffer::dump(FILE *fp)const{ if(!fp){ int i=start; while(i!=end){ printf("%d\r\n", buf[i]); i=(i+1)%bufSize; } }else{ int i=start; while(i!=end){ fprintf(fp, "%d\r\n", buf[i]); i=(i+1)%bufSize; } } }