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/

WiiClassicControllerWithCalibration.h

Committer:
RichardE
Date:
2013-06-30
Revision:
2:52c4a0b3a509
Child:
3:ecae3d286a99

File content as of revision 2:52c4a0b3a509:

/*
 * SOURCE FILE : WiiClassicControllerWithCalibration.h
 *
 * Definition of class WiiClassicControllerWithCalibration.
 *
 */

#ifndef WiiClassicControllerWithCalibrationDefined

    #define WiiClassicControllerWithCalibrationDefined

    #include "WiiClassicController.h"
    
    /// Derived from WiiClassicController but with calibrated analogue inputs.
    class WiiClassicControllerWithCalibration : public WiiClassicController {

    public :

        /// Enumeration of all the analogue inputs on the Wii classic controller.
        enum AnaIn {
            LeftJoyX,
            LeftJoyY,
            RightJoyX,
            RightJoyY,
            LeftTrigger,
            RightTrigger,
            AnaInCount          // MUST COME LAST!
        };
                
        /** Constructor
         * @param sda pin to use for SDA.
         * @param scl pin to use for SCL.
         */
        WiiClassicControllerWithCalibration( PinName sda, PinName scl );

        /** Destructor
         */
        virtual ~WiiClassicControllerWithCalibration();

        /** 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 calibrated left joystick X reading.
         * @returns a reading between -1 and +1.
         */
        float GetCalLJoyX( void ) const;
        
        /** Get calibrated left joystick Y reading.
         * @returns a reading between -1 and +1.
         */
        float GetCalLJoyY( void ) const;
        
        /** Get calibrated right joystick X reading.
         * @returns a reading between -1 and +1.
         */
        float GetCalRJoyX( void ) const;
        
        /** Get calibrated right joystick Y reading.
         * @returns a reading between -1 and +1.
         */
        float GetCalRJoyY( void ) const;

        /** Get calibrated left trigger reading.
         * @returns a reading between 0 and +1.
         */
        float GetCalLeftTrigger( void ) const;
        
        /** Get calibrated right trigger reading.
         * @returns a reading between 0 and +1.
         */
        float GetCalRightTrigger( void ) const;

    private :

        // Record for each analogue input.
        class AnaInRec {
        public :
            float Scale;
            float Offset;
        };
            
        // Records for all analogue inputs.
        AnaInRec records[ (int)AnaInCount ];
        
        /** Get scaled reading.
         * @param input analogue input to scale.
         * @param raw raw readings in counts.
         * @returns scaled reading.
         */
        float GetScaled( AnaIn input, UInt8 raw ) const;
        
    };

#endif

/* END of WiiClassicControllerWithCalibration.h */