AccelStepperI2C
v 0.1
I2C wrapper (and a bit more) for the AccelStepper Arduino library
|
Go to the documentation of this file.
16 #ifndef SimpleBuffer_h
17 #define SimpleBuffer_h
24 #define log(...) Serial.print(__VA_ARGS__)
38 void init(uint8_t buflen);
45 template <
typename T>
void write(
const T& value);
54 template <
typename T>
void read(T& value);
99 uint8_t calculateCRC8 ();
106 memcpy(&
buffer[
idx], &value,
sizeof (value));
107 idx +=
sizeof (value);
115 memcpy(&value, &
buffer[
idx],
sizeof (value));
116 idx +=
sizeof (value);
void setCRC8()
Calculate CRC8 checksum for the currently used buffer ([1]...[idx-1]) and store it in the first byte ...
bool checkCRC8()
Check for correct CRC8 checksum. First byte [0] holds the checksum, rest of the currently used buffer...
void read(T &value)
Read any basic data type from the buffer from the current position and increment the position pointer...
uint8_t idx
The position pointer. Remember, [0] holds the CRC8 checksum, so for an empty buffer,...
void init(uint8_t buflen)
Allocate and reset buffer.
void reset()
Reset the position pointer to the start of the buffer (which is[1] as [0] is the CRC8 chcksum) withou...
uint8_t maxLen
Maximum length of buffer in bytes. Read and write operations use this to check for sufficient space (...
uint8_t * buffer
The allocated buffer.
void write(const T &value)
Write any basic data type to the buffer at the current position and increment the position pointer ac...