Control Surface new-input
MIDI Control Surface library for Arduino
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 
12  receiving = false;
13 }
14 
15 void SysExBuffer::add(uint8_t data) {
16  buffer[length] = data;
17  ++length;
18 }
19 
20 void SysExBuffer::add(const uint8_t *data, uint8_t len) {
21  memcpy(buffer + length, data, len);
22  length += len;
23 }
24 
25 bool SysExBuffer::hasSpaceLeft(uint8_t amount) const {
26  bool avail = length <= SYSEX_BUFFER_SIZE - amount;
27  if (!avail)
28  DEBUG(F("SysEx: Buffer full (") << amount << ')');
29  return avail;
30 }
31 
32 bool SysExBuffer::isReceiving() const { return receiving; }
33 
34 const uint8_t *SysExBuffer::getBuffer() const { return buffer; }
35 
36 uint16_t SysExBuffer::getLength() const { return length; }
37 
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr size_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.
Definition: SysExBuffer.cpp:34
uint16_t length
Definition: SysExBuffer.hpp:16
uint8_t buffer[SYSEX_BUFFER_SIZE]
Definition: SysExBuffer.hpp:15
bool hasSpaceLeft(uint8_t amount=1) const
Check if the buffer has at least amount bytes of free space available.
Definition: SysExBuffer.cpp:25
void start()
Start a new SysEx message.
Definition: SysExBuffer.cpp:6
void add(uint8_t data)
Add a byte to the current SysEx message.
Definition: SysExBuffer.cpp:15
void end()
Finish the current SysEx message.
Definition: SysExBuffer.cpp:11
uint16_t getLength() const
Get the length of the SysEx message in the buffer.
Definition: SysExBuffer.cpp:36
bool isReceiving() const
Check if the buffer is receiving a SysEx message.
Definition: SysExBuffer.cpp:32
#define DEBUG(x)
Print an expression to the debug output if debugging is enabled.
Definition: Debug.hpp:98