Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
SysExBuffer.cpp
Go to the documentation of this file.
1#include "SysExBuffer.hpp"
2#include <string.h>
3
5
7 length = 0; // if the previous message wasn't finished, overwrite it
8 receiving = true;
9}
10
11void SysExBuffer::end() { receiving = false; }
12
13void SysExBuffer::add(uint8_t data) {
14 buffer[length] = data;
15 ++length;
16}
17
18void SysExBuffer::add(const uint8_t *data, uint8_t len) {
19 memcpy(buffer + length, data, len);
20 length += len;
21}
22
23bool SysExBuffer::hasSpaceLeft(uint8_t amount) const {
24 bool avail = length <= SYSEX_BUFFER_SIZE - amount;
25 if (!avail)
26 DEBUG(F("SysEx: Buffer full (") << amount << ')');
27 return avail;
28}
29
30bool SysExBuffer::isReceiving() const { return receiving; }
31
32const uint8_t *SysExBuffer::getBuffer() const { return buffer; }
33
34uint16_t SysExBuffer::getLength() const { return length; }
35
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr uint16_t SYSEX_BUFFER_SIZE
The length of the maximum System Exclusive message that can be received.
const uint8_t * getBuffer() const
Get a pointer to the buffer.
uint16_t length
uint8_t buffer[SYSEX_BUFFER_SIZE]
bool hasSpaceLeft(uint8_t amount=1) const
Check if the buffer has at least amount bytes of free space available.
void start()
Start a new SysEx message.
void add(uint8_t data)
Add a byte to the current SysEx message.
void end()
Finish the current SysEx message.
uint16_t getLength() const
Get the length of the SysEx message in the buffer.
bool isReceiving() const
Check if the buffer is receiving a SysEx message.
#define DEBUG(x)
Print an expression to the debug output if debugging is enabled.
Definition Debug.hpp:95