Generalized adaptation of the WiiChuk_compat library.

Fork of WiiChuk_compat by Greg Brush

Revision:
2:9c4ac1a64c30
Parent:
1:a5dbc8a15c83
Child:
3:fcc2f24d0644
--- a/WiiChuck.h	Fri Dec 19 18:10:44 2014 +0000
+++ b/WiiChuck.h	Sat Dec 20 01:22:58 2014 +0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2011 Greg Brush
+ * Portions copyright (C) 2014 Clark Scheff
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -37,12 +38,12 @@
 #define I2C_ACK 0
 #define I2C_READ_DELAY  0.0001
 
-#define Joy_X   0
-#define Joy_Y   1
-#define Acc_X   2
-#define Acc_Y   3
-#define Acc_Z   4
-#define Button  5
+#define JOY_X_IDX   0
+#define JOY_Y_IDX   1
+#define ACC_X_IDX   2
+#define ACC_Y_IDX   3
+#define ACC_Z_IDX   4
+#define BUTTON_IDX  5
 
 // ----------------------------------------------------------------------------
 //   Control values
@@ -65,23 +66,36 @@
     bool        buttonZ;
 } nunchuck_data_t;
 
-typedef void(*pt2Func)(int);
+typedef void(*pt2Func)(nunchuck_data_t*);
 
+/**
+ * Class for interfacing with a Wii Nunchuck (including knock offs)
+ */
 class WiiChuck {
 public:
-    bool Error;
+    /**
+     * @param data I2C data pin
+     * @param clk I2C clock pin
+     */
     WiiChuck(PinName data, PinName clk);
+    
+    /**
+     * Reads a packet of data from the nunchuck and fills in the supplied data structure.
+     *
+     * @param data Pointer to the data that will be filled in.
+     */
     bool read(nunchuck_data_t* data);
-    void start();
-    void stop();
-    void attach(pt2Func function);
+    void attach(pt2Func, float t);
+    void detach();
+
+    bool Error;
+
 private: 
     I2C _i2c;
-    pt2Func _callback_input;
+    pt2Func _callback;
     Ticker _getValues; 
     void getValues();
-    bool _oldC;
-    bool _oldZ;
+    nunchuck_data_t _data;
 };
 
 #endif
\ No newline at end of file