Line data Source code
1 : #include "SysExBuffer.hpp" 2 : #include <string.h> 3 : 4 : BEGIN_CS_NAMESPACE 5 : 6 48 : void SysExBuffer::start() { 7 48 : length = 0; // if the previous message wasn't finished, overwrite it 8 48 : receiving = true; 9 48 : } 10 : 11 42 : void SysExBuffer::end() { 12 42 : receiving = false; 13 42 : } 14 : 15 768 : void SysExBuffer::add(uint8_t data) { 16 768 : buffer[length] = data; 17 768 : ++length; 18 768 : } 19 : 20 108 : void SysExBuffer::add(const uint8_t *data, uint8_t len) { 21 108 : memcpy(buffer + length, data, len); 22 108 : length += len; 23 108 : } 24 : 25 852 : bool SysExBuffer::hasSpaceLeft(uint8_t amount) const { 26 852 : bool avail = length <= SYSEX_BUFFER_SIZE - amount; 27 852 : if (!avail) 28 : DEBUG(F("SysEx: Buffer full (") << amount << ')'); 29 852 : return avail; 30 : } 31 : 32 108 : bool SysExBuffer::isReceiving() const { return receiving; } 33 : 34 73 : const uint8_t *SysExBuffer::getBuffer() const { return buffer; } 35 : 36 73 : uint16_t SysExBuffer::getLength() const { return length; } 37 : 38 : END_CS_NAMESPACE