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.
Diff: ImgBuffer.h
- Revision:
- 0:27e403b8981e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ImgBuffer.h Sat Apr 28 21:09:44 2012 +0000 @@ -0,0 +1,54 @@ +#ifndef IMGBUFFER_H +#define IMGBUFFER_H + +#define MAX_IMG_BUF 1024 + +class ImgBuffer { +public: + ImgBuffer() { + write = 0; + read = 0; + size = MAX_IMG_BUF + 1; + }; + + bool isFull() { + return ((write + 1) % size == read); + }; + + bool isEmpty() { + return (read == write); + }; + + void queue(uint8_t k) { + if (isFull()) { + read++; + read %= size; + } + buf[write++] = k; + write %= size; + } + + uint16_t available() { + return (write >= read) ? write - read : size - read + write; + }; + + bool dequeue(uint8_t * c) { + if (!isEmpty()) { + *c = buf[read++]; + read %= size; + } + return(!isEmpty()); + }; + + void clear() { + read = write; + }; + +private: + volatile uint16_t write; + volatile uint16_t read; + uint16_t size; + uint8_t buf[MAX_IMG_BUF + 1]; +}; + +#endif \ No newline at end of file