Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created April 19, 2019 01:04
Show Gist options
  • Save jbobrow/40d0d04c96b2063bb590bfb8f3b0aa74 to your computer and use it in GitHub Desktop.
Save jbobrow/40d0d04c96b2063bb590bfb8f3b0aa74 to your computer and use it in GitHub Desktop.
A sort of Blinks stethoscope
/*
Serial Reporter
---------------
A utility app designed to make debugging of games
that are buggy in transmitting game state. Essentially,
this blink is a stethoscope for Blinks.
The Serial Reporter will:
1. Look for values received on all faces
2. Print values when received on faces
3. Will place a '*' next to each present face
4. Will print packet data when packet data is received on a face
Note: One really helpful aspect of this tool is that it shows
you how expired values still remain as the last value
received on a face.
by Jonathan Bobrow, Move38
04.18.2019
*/
#include "Serial.h"
ServicePortSerial serial;
byte neighbors[6];
bool neighborsPresent[6];
bool newData = false;
char *buttonExclamations[] = {"boop!","blip!","blop!"};
Timer activityTimer;
void setup() {
serial.begin();
}
void loop() {
if(buttonPressed()) {
serial.println(buttonExclamations[random(2)]);
}
newData = false;
/*
BROADCAST DATA REPORTING
------------------------
1. look for broadcast data i.e. setValueSentOnFace()
2. look for present neighbors
*/
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {
if (!neighborsPresent[f]) {
newData = true;
neighborsPresent[f] = true;
}
byte data = getLastValueReceivedOnFace(f);
if (neighbors[f] != data) {
newData = true;
neighbors[f] = data;
}
}
else {
// nothing on this face.. this can be new too
if (neighborsPresent[f]) {
newData = true;
neighborsPresent[f] = false;
}
}
}
/*
BROADCAST DATA PRINTING
-----------------------
Print our findings of broadcast data
*/
if (newData) {
serial.println("");
serial.println("-------------------");
FOREACH_FACE(f) {
serial.print("face ");
serial.print(f);
serial.print(": ");
serial.print(neighbors[f] >> 5 & 1); //00100000 binary representation
serial.print(neighbors[f] >> 4 & 1); //00010000 binary representation
serial.print(neighbors[f] >> 3 & 1); //00001000 binary representation
serial.print(neighbors[f] >> 2 & 1); //00000100 binary representation
serial.print(neighbors[f] >> 1 & 1); //00000010 binary representation
serial.print(neighbors[f] & 1); //00000001 binary representation
serial.print(" - ");
serial.print(neighbors[f]);
if (neighborsPresent[f]) {
serial.print(" *");
}
serial.println("");
}
serial.println("-------------------");
}
/*
PACKET REPORTING + PRINTING
---------------------------
1. look for packets on each face
2. print the packet if we find a packet
*/
FOREACH_FACE(f) {
if (isPacketReadyOnFace(f)) {
serial.println("");
serial.println("------PACKET-------");
serial.println("");
byte *data = (byte *) getPacketDataOnFace(f);
byte len = getPacketLengthOnFace(f);
serial.print("packet on face ");
serial.print(f);
serial.print(" of length ");
serial.println(len);
serial.println("");
serial.print("data: ");
for (byte i = 0; i < len; i++) {
serial.print(data[f]);
}
serial.println("");
serial.println("-------------------");
setColorOnFace(GREEN, f); // Packets are green :)
}
}
/*
DISPLAY ACTIVITY ON CONNECTED FACES
-----------------------------------
*/
setColor(OFF);
if (!isAlone() && activityTimer.isExpired()) {
serial.print(">");
activityTimer.set(500);
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {
setColorOnFace(WHITE, f);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment