Skip to content

Commit fec4273

Browse files
committed
Style and debugging updates.
1 parent 34226a6 commit fec4273

File tree

7 files changed

+60
-49
lines changed

7 files changed

+60
-49
lines changed

M4_Eyes/HeatSensor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void HeatSensor::setup()
2222

2323
// default settings
2424
status = amg.begin();
25-
if (!status) {
25+
if(!status) {
2626
Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
2727
while (1);
2828
}
@@ -77,7 +77,7 @@ void HeatSensor::find_focus()
7777
for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
7878
int val = min(5, round(max(0, pixels[i-1] - 20) / 2));
7979
Serial.print(charPixels[val]);
80-
if (i % 8 == 0)
80+
if(i % 8 == 0)
8181
Serial.println();
8282
}
8383
Serial.println();

M4_Eyes/M4_Eyes.ino

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,39 @@ uint32_t availableRAM(void) {
135135

136136
// USER CALLABLE FUNCTIONS
137137

138-
// set the booped flag
138+
// Set the booped flag.
139139
void eyesWide(bool t) {
140+
// Serial.println("eyesWide()");
140141
booped = t;
141142
}
142143

143-
// start a blink
144+
// Start a blink.
144145
void eyesBlink() {
145-
timeToNextBlink = 0;
146+
// Serial.println("eyesBlink()");
147+
timeToNextBlink = 0;
146148
}
147149

148-
// force the eyes to a position on the screen
150+
// Force the eyes to a position on the screen.
149151
void eyesToCorner(float x, float y, bool immediate) {
150152
moveEyesRandomly = false;
151153
eyeTargetX = x;
152154
eyeTargetY = y;
153-
if (immediate)
155+
if(immediate)
154156
eyeMoveDuration = 0;
155157
}
156158

157-
// return the eyes to normal random movement
159+
// Return the eyes to normal random movement.
158160
void eyesNormal() {
161+
// Serial.println("eyesNormal()");
159162
moveEyesRandomly = true;
160163
}
161164

162165

163166
// SETUP FUNCTION - CALLED ONCE AT PROGRAM START ---------------------------
164167

165168
void setup() {
169+
Serial.println("SETUP BEGINS");
170+
166171
if(!arcada.arcadaBegin()) fatal("Arcada init fail!", 100);
167172
#if defined(USE_TINYUSB)
168173
if(!arcada.filesysBeginMSD()) fatal("No filesystem found!", 250);
@@ -214,10 +219,10 @@ void setup() {
214219
#endif
215220

216221
yield();
217-
if (showSplashScreen) {
218-
if (arcada.drawBMP((char *)"/splash.bmp", 0, 0, (eye[0].display)) == IMAGE_SUCCESS) {
222+
if(showSplashScreen) {
223+
if(arcada.drawBMP((char *)"/splash.bmp", 0, 0, (eye[0].display)) == IMAGE_SUCCESS) {
219224
Serial.println("Splashing");
220-
if (NUM_EYES > 1) { // other eye
225+
if(NUM_EYES > 1) { // other eye
221226
yield();
222227
arcada.drawBMP((char *)"/splash.bmp", 0, 0, (eye[1].display));
223228
}
@@ -448,10 +453,11 @@ void setup() {
448453
}
449454

450455
lastLightReadTime = micros() + 2000000; // Delay initial light reading
456+
457+
Serial.println("END OF SETUP");
451458
}
452459

453460

454-
455461
// LOOP FUNCTION - CALLED REPEATEDLY UNTIL POWER-OFF -----------------------
456462

457463
/*
@@ -504,7 +510,7 @@ void loop() {
504510
if(eyeInMotion) { // Currently moving?
505511
if(dt >= eyeMoveDuration) { // Time up? Destination reached.
506512
eyeInMotion = false; // Stop moving
507-
if (moveEyesRandomly) {
513+
if(moveEyesRandomly) {
508514
eyeMoveDuration = random(10000, 3000000); // 0.01-3 sec stop
509515
eyeMoveStartTime = t; // Save initial time of stop
510516
}
@@ -524,7 +530,7 @@ void loop() {
524530
float r = (float)mapDiameter - (float)DISPLAY_SIZE * M_PI_2; // radius of motion
525531
r *= 0.6; // calibration constant
526532

527-
if (moveEyesRandomly) {
533+
if(moveEyesRandomly) {
528534
eyeNewX = random(-r, r);
529535
float h = sqrt(r * r - x * x);
530536
eyeNewY = random(-h, h);
@@ -629,13 +635,14 @@ void loop() {
629635
// of both screens is about 1/2 this.
630636
frames++;
631637
if(((t - lastFrameRateReportTime) >= 1000000) && t) { // Once per sec.
632-
Serial.println((frames * 1000) / (t / 1000));
638+
Serial.printf("Frame rate: %d\n", (frames * 1000) / (t / 1000));
633639
lastFrameRateReportTime = t;
634640
}
635641

636642
// Once per frame (of eye #0), reset boopSum...
637643
if((eyeNum == 0) && (boopPin >= 0)) {
638644
boopSumFiltered = ((boopSumFiltered * 3) + boopSum) / 4;
645+
// Serial.printf("boopSum: %d, boopSumFiltered: %d, boopThreshold: %d, booped: %s\n", boopSum, boopSumFiltered, boopThreshold, (booped ? "true" : "false"));
639646
if(boopSumFiltered > boopThreshold) {
640647
if(!booped) {
641648
Serial.println("BOOP!");

M4_Eyes/file.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void loadConfig(char *filename) {
9090
DeserializationError error = deserializeJson(doc, file);
9191
yield();
9292
if(error) {
93-
Serial.println("Config file error, using default settings");
93+
Serial.println("Config file error, using default settings.");
9494
Serial.println(error.c_str());
9595
} else {
9696
uint8_t e;
@@ -287,7 +287,7 @@ void loadConfig(char *filename) {
287287
file.close();
288288
user_setup(doc);
289289
} else {
290-
Serial.println("Can't open config file, using default settings");
290+
Serial.println("Can't open config file, using default settings.");
291291
}
292292

293293
// INITIALIZE DEFAULT VALUES if config file missing or in error ----------
@@ -331,7 +331,7 @@ ImageReturnCode loadEyelid(char *filename,
331331
Adafruit_ImageReader *reader;
332332

333333
reader = arcada.getImageReader();
334-
if (!reader) {
334+
if(!reader) {
335335
return IMAGE_ERR_FILE_NOT_FOUND;
336336
}
337337

@@ -341,7 +341,7 @@ ImageReturnCode loadEyelid(char *filename,
341341
// This is the "booster seat" described in m4eyes.ino
342342
if(reader->bmpDimensions(filename, &w, &h) == IMAGE_SUCCESS) {
343343
tempBytes = ((w + 7) / 8) * h; // Bitmap size in bytes
344-
if (maxRam > tempBytes) {
344+
if(maxRam > tempBytes) {
345345
if((tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) != NULL) {
346346
// Make SOME tempPtr reference, or optimizer removes the alloc!
347347
tempPtr[0] = 0;
@@ -417,14 +417,14 @@ ImageReturnCode loadTexture(char *filename, uint16_t **data,
417417
Adafruit_ImageReader *reader;
418418

419419
reader = arcada.getImageReader();
420-
if (!reader) {
420+
if(!reader) {
421421
return IMAGE_ERR_FILE_NOT_FOUND;
422422
}
423423

424424
// This is the "booster seat" described in m4eyes.ino
425425
if(reader->bmpDimensions(filename, &w, &h) == IMAGE_SUCCESS) {
426426
tempBytes = w * h * 2; // Image size in bytes (converted to 16bpp)
427-
if (maxRam > tempBytes) {
427+
if(maxRam > tempBytes) {
428428
if((tempPtr = (uint8_t *)malloc(maxRam - tempBytes)) != NULL) {
429429
// Make SOME tempPtr reference, or optimizer removes the alloc!
430430
tempPtr[0] = 0;

M4_Eyes/user.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
1+
#if 0 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
22

33
// This file provides a crude way to "drop in" user code to the eyes,
44
// allowing concurrent operations without having to maintain a bunch of

M4_Eyes/user_hid.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ void user_setup(StaticJsonDocument<2048> &doc) {
4747
}
4848

4949
void user_loop(void) {
50-
if ( !usb_hid.ready() ) {
50+
if( !usb_hid.ready() ) {
5151
Serial.println("not ready");
5252
return;
5353
}
5454

5555
uint8_t keycode[6] = { 0 };
5656

5757
uint32_t buttonState = arcada.readButtons();
58-
if (buttonState & ARCADA_BUTTONMASK_UP) {
58+
if(buttonState & ARCADA_BUTTONMASK_UP) {
5959
Serial.println("Up");
6060
keycode[0] = UP_BUTTON_KEYCODE_TO_SEND;
6161
}
62-
if (buttonState & ARCADA_BUTTONMASK_A) {
62+
if(buttonState & ARCADA_BUTTONMASK_A) {
6363
Serial.println("A");
6464
keycode[1] = A_BUTTON_KEYCODE_TO_SEND;
6565
}
66-
if (buttonState & ARCADA_BUTTONMASK_DOWN) {
66+
if(buttonState & ARCADA_BUTTONMASK_DOWN) {
6767
Serial.println("Down");
6868
keycode[2] = DOWN_BUTTON_KEYCODE_TO_SEND;
6969
}
7070

7171
uint8_t shake = arcada.accel.getClick();
72-
if (shake & 0x30) {
72+
if(shake & 0x30) {
7373
Serial.print("shake detected (0x"); Serial.print(shake, HEX); Serial.print("): ");
74-
if (shake & 0x10) Serial.println(" single shake");
74+
if(shake & 0x10) Serial.println(" single shake");
7575
keycode[3] = SHAKE_KEYCODE_TO_SEND;
7676
}
7777

@@ -86,12 +86,12 @@ void user_loop(void) {
8686

8787
bool anypressed = false;
8888
for (int k=0; k<sizeof(keycode); k++) {
89-
if (keycode[k] != 0) {
89+
if(keycode[k] != 0) {
9090
anypressed = true;
9191
break;
9292
}
9393
}
94-
if (anypressed) {
94+
if(anypressed) {
9595
digitalWrite(LED_BUILTIN, HIGH);
9696
usb_hid.keyboardReport(0, 0, keycode);
9797
} else {

M4_Eyes/user_touchneopixels.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void user_loop(void) {
260260
uint8_t pressed_buttons = arcada.readButtons();
261261
uint8_t justpressed_buttons = arcada.justPressedButtons();
262262

263-
if (justpressed_buttons & ARCADA_BUTTONMASK_UP){
263+
if(justpressed_buttons & ARCADA_BUTTONMASK_UP){
264264
changeBehavior(0, elapsedSince);
265265
}
266266
else if(justpressed_buttons & ARCADA_BUTTONMASK_DOWN) {
@@ -274,7 +274,7 @@ void user_loop(void) {
274274
}
275275
}
276276

277-
if (elapsedSince - lastWave > SAMPLE_TIME) {
277+
if(elapsedSince - lastWave > SAMPLE_TIME) {
278278
lastWave = elapsedSince;
279279
switch (currentBehavior) {
280280
case 0:
@@ -295,7 +295,7 @@ void user_loop(void) {
295295
break;
296296
}
297297

298-
if ((elapsedSince - lastBehaviorChange) > (SAMPLE_TIME * 1000)) {
298+
if((elapsedSince - lastBehaviorChange) > (SAMPLE_TIME * 1000)) {
299299
lastBehaviorChange = elapsedSince;
300300
currentBehavior++;
301301
currentBehavior %= 4;

M4_Eyes/user_wiichuck.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if 0 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
1+
#if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
22

33
// This user loop is designed to be used with a WiiChuck for command inputs and
44
// connects to a NeoPixel strip for additional output. It was used with a unicorn
@@ -63,7 +63,7 @@ const int red = Adafruit_NeoPixel::Color(127,0,0);
6363
void user_setup(void) {
6464
// follow the WiiAccessory.ino example:
6565
nunchuck1.begin();
66-
if (nunchuck1.type == Unknown) {
66+
if(nunchuck1.type == Unknown) {
6767
/** If the device isn't auto-detected, set the type explicatly
6868
* NUNCHUCK,
6969
WIICLASSIC,
@@ -90,10 +90,10 @@ void user_setup(StaticJsonDocument<2048> &doc) {
9090
int32_t neomax = getDocInt(doc, "wiichuck","neopixel","max",-1);
9191
Serial.println("neopin=" + String(neomax));
9292

93-
if (neopin && neomax > -1) {
94-
if ((strcmp(neopin, "d2") == 0) || (strcmp(neopin, "D2") == 0))
93+
if(neopin && neomax > -1) {
94+
if((strcmp(neopin, "d2") == 0) || (strcmp(neopin, "D2") == 0))
9595
neoPixelPin = 2;
96-
else if ((strcmp(neopin, "d3") == 0) || (strcmp(neopin, "D3") == 0))
96+
else if((strcmp(neopin, "d3") == 0) || (strcmp(neopin, "D3") == 0))
9797
neoPixelPin = 3;
9898
neoPixelMax = neomax;
9999

@@ -189,23 +189,23 @@ void user_loop(void) {
189189
int cornerY = (joyY - low) / divFactor;
190190
int chaseColor = 0;
191191
// Serial.println("cornerXY=" + String(cornerX) + "," + String(cornerY));
192-
if (cornerX == 1 && cornerY == 1) { // return to normal when the joystick is in the middle
192+
if(cornerX == 1 && cornerY == 1) { // return to normal when the joystick is in the middle
193193
// Serial.println("eyesNormal()");
194194
eyesNormal();
195195
neoPixelState = LUMINESCENT;
196196
} else {
197197
// Serial.println("eyesToCorner(" + String(x) + "," + String(-y) + ")");
198198
eyesToCorner(x, -y, true);
199-
if (cornerX < 1) {
199+
if(cornerX < 1) {
200200
chaseColor = green;
201201
neoPixelState = CHASE_LEFT;
202-
} else if (cornerX > 1) {
202+
} else if(cornerX > 1) {
203203
chaseColor = blue;
204204
neoPixelState = CHASE_RIGHT;
205-
} else if (cornerY > 1) {
205+
} else if(cornerY > 1) {
206206
neoPixelState = CHASE_UP;
207207
chaseColor = green;
208-
} else if (cornerY < 1) {
208+
} else if(cornerY < 1) {
209209
neoPixelState = CHASE_DOWN;
210210
chaseColor = blue;
211211
}
@@ -214,18 +214,22 @@ void user_loop(void) {
214214
bool buttonC = nunchuck1.getButtonC();
215215
eyesWide(buttonC);
216216
bool buttonZ = nunchuck1.getButtonZ();
217-
if (buttonZ)
217+
if(buttonZ) {
218+
Serial.println("buttonZ");
218219
eyesBlink();
220+
}
219221

220-
if (buttonC && buttonZ) {
222+
if(buttonC && buttonZ) {
223+
Serial.println("buttonC & buttonZ");
221224
chaseColor = red;
222-
if (neoPixelState == LUMINESCENT) neoPixelState = CHASE_UP;
223-
} else if (buttonC) {
225+
if(neoPixelState == LUMINESCENT) neoPixelState = CHASE_UP;
226+
} else if(buttonC) {
227+
Serial.println("buttonC");
224228
neoPixelState = SPARKLE;
225229
}
226-
// Serial.println("neo state=" + String(neoPixelState));
227230

228-
if (strip.numPixels() > 0) {
231+
if(strip.numPixels() > 0) {
232+
// Serial.println("neo state=" + String(neoPixelState));
229233
switch (neoPixelState) {
230234
case LUMINESCENT: neoShine(); break;
231235
case CHASE_RIGHT: neoChase(4, 3, chaseColor); break;

0 commit comments

Comments
 (0)