Buffer.cpp 511 B

123456789101112131415161718192021222324252627282930
  1. #include "Buffer.h"
  2. #include "Arduino.h"
  3. Buffer::Buffer() {
  4. }
  5. Buffer::Buffer(uint8_t* buf, size_t size) {
  6. this->add(buf,size);
  7. }
  8. bool Buffer::available() {
  9. return this->pos < this->length;
  10. }
  11. uint8_t Buffer::next() {
  12. if (this->available()) {
  13. return this->buffer[this->pos++];
  14. }
  15. return 0;
  16. }
  17. void Buffer::reset() {
  18. this->pos = 0;
  19. }
  20. void Buffer::add(uint8_t* buf, size_t size) {
  21. uint16_t i = 0;
  22. for (;i<size;i++) {
  23. this->buffer[this->length++] = buf[i];
  24. }
  25. }