Generalized adaptation of the WiiChuk_compat library.

Fork of WiiChuk_compat by Greg Brush

Revision:
5:be9ce129de7c
Parent:
3:fcc2f24d0644
--- a/WiiChuck.cpp	Sun Dec 21 18:24:50 2014 +0000
+++ b/WiiChuck.cpp	Mon Dec 22 03:32:51 2014 +0000
@@ -53,6 +53,25 @@
      _callback = NULL;
 }
 
+bool WiiChuck::calibrateJoystickNeutralPosition(uint8_t* centerX, uint8_t* centerY) {
+    if (!_initialized) return false;
+    
+    nunchuck_data_t data;
+    uint16_t tempX = 0, tempY = 0;
+    
+    for (size_t i = 0; i < 8; i++) {
+        if (!this->read(&data)) return false;
+        
+        tempX += data.joyX;
+        tempY += data.joyY;
+    }
+    
+    // take the average of the readings ( >> 3 == / 8)
+    *centerX = tempX >> 3;
+    *centerY = tempY >> 3;
+    return true;
+}
+
 void WiiChuck::getValues() {
     bool hasData = read(&_data);