Awesome, it's great that somebody is using this code- I never finished my project (that seems to be my problem, I never finish any projects).
To only output values when they change you need to keep a copy of the previous packet and compare these values. First write a function to compare two previous packets. You have to do this member-by-member in C I think.
bool packetsEqual(packet_t * p1, packet_t * p2) {
return (p1->x == p2->x &&
p1->y == p2->y &&
p1->z == p2->z &&
p1->w == p2->w
);
}
You should add your new button variables to the above function.
Then, in loop(), you need to add storage for the old packet, then add the check for differences, then copy the current packet so that it is stored for comparison the next time around.
void loop()
{
static packet_t oldPacket;
packet_t * packet;
packet = t.getNewPacket();
if(!packetsEqual(&oldPacket, packet)) {
DUMP(packet->x);
DUMP(packet->y);
DUMP(packet->z);
DUMP(packet->w);
Serial.print("\n");
#if ANSI_TERMINAL
Serial.print(0x1B,BYTE);
Serial.print("[H");
#endif
Serial.print("\n");
// copy the current packet
oldPacket = *packet;
}
}
There you go! I haven't run any of this code so there may be errors in it, but hopefully you can see the gist. If you're wondering, the static keyword means the variable is not destroyed when the loop() function exits, and the * and & characters are pointer dereference and address operators. If you're new to C and C++, you might need to do a little reading to understand what this means.
Joe