Skip to content

Commit

Permalink
re-adding calibration on startup
Browse files Browse the repository at this point in the history
re-added the older calibrate-on-startup code

also cleaned up some debugging statements in Chuck.h leftover from a
previous refactor
  • Loading branch information
jaustindavid committed May 10, 2014
1 parent 80d34b9 commit 2be97f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions Wiiceiver/Chuck.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Chuck {
lastActivity = activity;
}

#ifdef DEBUGGING_CHUCK
#ifdef DEBUGGING_CHUCK_ACTIVITY
Serial.print("CHUCK: ");
for (int i = 0; i < 5; i++) {
Serial.print(status[i], DEC);
Expand All @@ -150,20 +150,20 @@ class Chuck {
byte storedY;

storedY = EEPROM.read(0);
#ifdef DEBUGGING
#ifdef DEBUGGING_CHUCK
Serial.print(F("Reading stored value: Y="));
Serial.println(storedY);
#endif

// sanity check: they shouldn't differ by more than 25 units (~10%)
if (abs(storedY - DEFAULT_Y_ZERO) <= 25) {
Y0 = storedY;
#ifdef DEBUGGING
#ifdef DEBUGGING_CHUCK
Serial.println("Using stored value");
#endif
}
else {
#ifdef DEBUGGING
#ifdef DEBUGGING_CHUCK
Serial.println("Ingoring stored value");
#endif
}
Expand All @@ -172,7 +172,7 @@ class Chuck {

void writeEEPROM() {
EEPROM.write(0, Y0);
#ifdef DEBUGGING
#ifdef DEBUGGING_CHUCK
Serial.print("Storing value: Y=");
Serial.println(Y0);
#endif
Expand Down Expand Up @@ -224,7 +224,7 @@ class Chuck {
}

_computeStatus();
#ifdef DEBUGGING_CHUCK
#ifdef DEBUGGING_CHUCK_ACTIVITY
Serial.print("Active? ");
Serial.println(isActive() ? "yes" : "no");
#endif
Expand Down
7 changes: 5 additions & 2 deletions Wiiceiver/Wiiceiver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include <EEPROM.h>


// #define DEBUGGING
#define DEBUGGING

#include "Blinker.h"

// #define DEBUGGING_SMOOTHER
#include "Smoother.h"

// #define DEBUGGING_CHUCK
#define DEBUGGING_CHUCK
// #define DEBUGGING_CHUCK_ACTIVITY
#define WII_ACTIVITY_COUNTER 100 // once per 20ms; 50 per second
#include "Chuck.h"
Expand Down Expand Up @@ -199,6 +199,7 @@ bool startChuck() {
Serial.println("(Re)starting the nunchuck");
#endif
chuck.setup();
chuck.readEEPROM();
tries ++;
if (chuck.isActive()) {
return true;
Expand Down Expand Up @@ -311,6 +312,8 @@ void setup() {
red.high();
if (! startChuck()) {
handleInactivity();
} else {
maybeCalibrate();
}
#ifdef DEBUGGING
Serial.println("Nunchuck is active!");
Expand Down

0 comments on commit 2be97f7

Please sign in to comment.