MIDI Control Surface library for Arduino
|
Go to the documentation of this file.
9 #include <AH/Error/Error.hpp>
33 bool get(uint8_t bitIndex)
const {
34 return buffer[getBufferIndex(bitIndex)] & getBufferMask(bitIndex);
43 void set(uint8_t bitIndex) {
44 buffer[getBufferIndex(bitIndex)] |= getBufferMask(bitIndex);
54 buffer[getBufferIndex(bitIndex)] &= ~getBufferMask(bitIndex);
65 void set(uint8_t bitIndex,
bool state) {
66 state ? set(bitIndex) : clear(bitIndex);
78 if (byteIndex >= getBufferLength()) {
79 ERROR(
F(
"Error: index out of bounds (")
80 << byteIndex <<
F(
", length is ") << getBufferLength()
83 return getBufferLength() - 1;
99 uint8_t
getByte(uint8_t byteIndex)
const {
100 return buffer[byteIndex];
111 return safeIndex(bitIndex / 8);
115 return 1 << getBufferBit(bitIndex);
118 constexpr
static uint8_t bufferLength = (uint8_t)((N + 7) / 8);
119 uint8_t buffer[bufferLength] = {};
#define AH_DIAGNOSTIC_POP()
void set(uint8_t bitIndex)
Set the value of the given bit to 1.
bool get(uint8_t bitIndex) const
Get the value of the given bit.
uint8_t getBufferMask(uint8_t bitIndex) const
uint8_t safeIndex(uint8_t byteIndex) const
Check the given byte index, and return it if it is within the bounds of the array,...
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
uint8_t getBufferLength() const
Get the buffer length in bytes.
uint8_t getBufferBit(uint8_t bitIndex) const
void set(uint8_t bitIndex, bool state)
Set the value of the given bit to the given state.
uint8_t getByte(uint8_t byteIndex) const
Get the byte at the given index.
#define AH_DIAGNOSTIC_WERROR()
#define BEGIN_AH_NAMESPACE
void clear(uint8_t bitIndex)
Clear the value of the given bit to 0.
A class for arrays of bits.
uint8_t getBufferIndex(uint8_t bitIndex) const