RoboidControl-cpp/NetworkSync.cpp
2024-01-11 14:51:07 +01:00

20 lines
611 B
C++

#include "NetworkSync.h"
void NetworkSync::SendVector3(unsigned char *data, int startIndex, Vector3 v) {
SendFloat100(data, startIndex, v.x);
SendFloat100(data, startIndex + 4, v.y);
SendFloat100(data, startIndex + 8, v.z);
}
void NetworkSync::SendFloat100(unsigned char *data, int startIndex,
float value) {
// Sends a float with truncated 2 decimal precision
#ifdef ARDUINO_AVR_UNO
long intValue = value * 100;
#else
int intValue = value * 100;
#endif
for (unsigned char ix = 0; ix < 4; ix++) {
data[startIndex + ix] = ((unsigned char *)&intValue)[ix];
}
}