Library for communicating with a Wii classic controller using the I2C bus.

Dependents:   WiiClassicControllerTest

Note that you will also need the CommonTypes library to use this.

Get it here:http://mbed.org/users/RichardE/code/CommonTypes/

Revision:
3:ecae3d286a99
Parent:
2:52c4a0b3a509
Child:
4:79d04d737f02
--- a/WiiClassicControllerWithCalibration.h	Sun Jun 30 12:05:27 2013 +0000
+++ b/WiiClassicControllerWithCalibration.h	Sun Jun 30 16:37:49 2013 +0000
@@ -37,12 +37,26 @@
          */
         virtual ~WiiClassicControllerWithCalibration();
 
+        /** Read from the controller.
+         * This override will also update calibration information
+         * when calibration is in progress.
+         * @returns true on success, false on failure.
+         */
+        virtual bool Read( void );
+
         /** Set scaling for a particular analogue input.
          * @param m scale (multiplier) for this analogue input.
          * @param c offset for this analogue input.
          */
          void SetScaling( AnaIn input, float m, float c );
          
+        /** Get scaling for a particular analogue input.
+         * @param input channel to read.
+         * @param m scale (multiplier) for this analogue input return here.
+         * @param c offset for this analogue input returned here.
+         */
+         void GetScaling( AnaIn input, float *m, float *c ) const;
+
         /** Get calibrated left joystick X reading.
          * @returns a reading between -1 and +1.
          */
@@ -73,13 +87,50 @@
          */
         float GetCalRightTrigger( void ) const;
 
+        /** Get indication that calibration is in progress.
+         * @returns true if calibration is in progress.
+         */
+        bool IsCalibrating( void ) const {
+            return calibrating;
+        }
+        
+        /** Start calibrating.
+         * Every call to Read method updates calibration until StopCalibrating is called.
+         */
+        void StartCalibrating( void );
+        
+        /** Stop calibrating.
+         */
+        void StopCalibrating( void );
+        
     private :
 
+        // Indicates calibration is in progress.
+        bool calibrating;
+        
         // Record for each analogue input.
         class AnaInRec {
+        
         public :
+        
             float Scale;
             float Offset;
+            UInt8 MaxCount;
+            UInt8 MinCount;
+            UInt8 ZeroCount;
+            
+            /** Calculate scale and offset for a bipolar reading.
+             * @param minValue minimum value to read.
+             * @param maxValue maximum value to read.
+             */
+             void CalculateScaleAndOffsetBiPolar( float minValue, float maxValue );
+             
+            /** Calculate scale and offset for a unipolar reading.
+             * Minimum value is assumed to be zero.
+             * @param maxValue maximum value to read.
+             */
+             void CalculateScaleAndOffsetUniPolar( float maxValue );
+             
         };
             
         // Records for all analogue inputs.
@@ -88,10 +139,22 @@
         /** Get scaled reading.
          * @param input analogue input to scale.
          * @param raw raw readings in counts.
+         * @param min minimum permitted value.
+         * @param max maximum permited value.
          * @returns scaled reading.
          */
-        float GetScaled( AnaIn input, UInt8 raw ) const;
+        float GetScaled( AnaIn input, UInt8 raw, float min, float max ) const;
+        
+        /** Update calibration information.
+         */
+        void UpdateCalibration( void );
         
+        /** Get the raw counts for one of the analogue inputs.
+         * @param input analogue input to read.
+         * @returns raw counts for input.
+         */
+        UInt8 GetAnaIn( AnaIn input ) const;
+
     };
 
 #endif