aboutsummaryrefslogtreecommitdiff
path: root/libraries/WiiChuck/WiiChuck.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/WiiChuck/WiiChuck.h')
-rwxr-xr-xlibraries/WiiChuck/WiiChuck.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/libraries/WiiChuck/WiiChuck.h b/libraries/WiiChuck/WiiChuck.h
new file mode 100755
index 0000000..1489d61
--- /dev/null
+++ b/libraries/WiiChuck/WiiChuck.h
@@ -0,0 +1,69 @@
+/*
+ * WiiChuck
+ * Flamingo EDA http://www.flamingoeda.com
+ *
+ */
+
+#ifndef WII_CHUCK_H
+#define WII_CHUCK_H
+
+#include <WProgram.h>
+#include <Wire.h>
+
+
+#define WII_I2C_ADDR 0x52
+#define PACKAGE_LENGTH 6
+
+extern TwoWire Wire;
+
+class WiiChuck {
+
+ public:
+ /**
+ * Initialize and join the I2C bus.
+ */
+ void init();
+
+ /**
+ * Initialize and join I2C bus with default power pins.
+ * POWER: PC3 (Analog 3 pin in Arduino)
+ * GND: PC2 (Analog 2 pin in Arduino)
+ */
+ void initWithPower();
+
+ /**
+ * Initialize and join I2C bus with specified power pins.
+ */
+ void initWithPowerPins(byte powerPin, byte gndPin);
+
+ /**
+ * Read data from nunchuck.
+ */
+ boolean read();
+
+ int getJoyAxisX();
+ int getJoyAxisY();
+ int getAccelAxisX();
+ int getAccelAxisY();
+ int getAccelAxisZ();
+ int getButtonZ();
+ int getButtonC();
+
+ private:
+ byte decodeByte(byte x);
+ void sendNullRequest();
+
+ private:
+ uint8_t buffer[PACKAGE_LENGTH];
+ int joyAxisX;
+ int joyAxisY;
+ int accelAxisX;
+ int accelAxisY;
+ int accelAxisZ;
+ int buttonZ;
+ int buttonC;
+};
+
+
+#endif
+