API Reference
CRUMBS Class
Constructor
CRUMBS(bool isController = false, uint8_t address = 0);
isController:truefor controller,falsefor peripheraladdress: I2C address for peripheral mode (ignored for controller)
Methods
void begin(); // Initialize I2C
void sendMessage(const CRUMBSMessage &msg, uint8_t addr); // Send message
bool receiveMessage(CRUMBSMessage &msg); // Receive message (returns success)
void onReceive(void (*callback)(CRUMBSMessage &)); // Set receive callback
void onRequest(void (*callback)()); // Set request callback
uint8_t getAddress() const; // Get device address
// Encoding/Decoding
size_t encodeMessage(const CRUMBSMessage &msg, uint8_t *buffer, size_t size);
bool decodeMessage(const uint8_t *buffer, size_t size, CRUMBSMessage &msg);
CRUMBSMessage Structure
struct CRUMBSMessage {
uint8_t sliceAddress; // Target identifier (not serialized)
uint8_t typeID; // Module type (sensor=1, motor=2, etc.)
uint8_t commandType; // Command (read=0, set=1, etc.)
float data[CRUMBS_DATA_LENGTH]; // Payload data (7 floats = 28 bytes)
uint8_t crc8; // CRC-8 checksum over serialized payload
};
Serialized frame: 31 bytes (typeID + commandType + data + crc8)
Constants
#define CRUMBS_DATA_LENGTH 7 // Number of float data elements
#define CRUMBS_MESSAGE_SIZE 31 // Serialized frame size
#define TWI_CLOCK_FREQ 100000 // I2C clock frequency (100kHz)
Debug Macros
#define CRUMBS_DEBUG // Enable debug output
CRUMBS_DEBUG_PRINT(...) // Print with "CRUMBS: " prefix
CRUMBS_DEBUG_PRINTLN(...) // Print line with "CRUMBS: " prefix
Error Codes (sendMessage)
0: Success1: Data too long for transmit buffer2: NACK on address (device not found)3: NACK on data transmission4: Other I2C error