29 lines
No EOL
691 B
C++
29 lines
No EOL
691 B
C++
#include <I2CCommunicator.h>
|
|
#include <Wire.h>
|
|
|
|
I2CCommunicator::I2CCommunicator(int slaveAddr, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize)
|
|
{
|
|
Wire.begin(slaveAddr);
|
|
}
|
|
|
|
void I2CCommunicator::sendMessage(int *values, int numberOfValues)
|
|
{
|
|
char message[calculateMessageOutSize(numberOfValues)];
|
|
parseIDs(values, numberOfValues, message);
|
|
Serial.println(message);
|
|
}
|
|
|
|
void I2CCommunicator::sendMessage(char *message)
|
|
{
|
|
Wire.println(message);
|
|
}
|
|
|
|
char *I2CCommunicator::receiveMessage()
|
|
{
|
|
if (Wire.available())
|
|
{
|
|
memset(getBuffer(), '\0', getBufferSize());
|
|
Wire.readBytesUntil('\n', getBuffer(), getBufferSize());
|
|
}
|
|
return getBuffer();
|
|
} |