Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AvailableMemory mbed-rtos mbed
RingBuffer.cpp
00001 #include "RingBuffer.h" 00002 00003 void RingBuffer::insert(int sample){ 00004 if((end+1)%bufSize==start){ 00005 start=(start+1)%bufSize; 00006 cur=start; 00007 count--; 00008 } 00009 buf[end]=sample; 00010 end=(end+1)%bufSize; 00011 count++; 00012 } 00013 00014 int RingBuffer::next(){ 00015 int ret=buf[cur]; 00016 cur=(cur+1)%bufSize; 00017 if ((cur >= end) && (count < bufSize)) cur = start; 00018 return ret; 00019 } 00020 00021 void RingBuffer::dump(FILE *fp)const{ 00022 if(!fp){ 00023 int i=start; 00024 while(i!=end){ 00025 printf("%d\r\n", buf[i]); 00026 i=(i+1)%bufSize; 00027 } 00028 }else{ 00029 int i=start; 00030 while(i!=end){ 00031 fprintf(fp, "%d\r\n", buf[i]); 00032 i=(i+1)%bufSize; 00033 } 00034 } 00035 }
Generated on Tue Jul 12 2022 18:43:44 by
1.7.2