CMPS03 Compass library with only PWM support. I2C support will be added shortly, while it will arrive, you may use MBED component library if you wish to use CMPS03 I2C interface

Dependents:   TestBoussole FRC_2018 0hackton_08_06_18 lib_FRC_2019 ... more

Revision:
3:3e9586433ce5
Parent:
2:e09ad9c1f751
Child:
4:ab9eadf7537a
--- a/CMPS03.h	Tue May 22 17:15:22 2018 +0000
+++ b/CMPS03.h	Thu May 31 17:26:29 2018 +0000
@@ -41,70 +41,50 @@
 #include "mbed.h"
 
 /**
- * Defines
- */
-#define CMPS03_DEFAULT_I2C_ADDRESS 0xC0
-
-//-----------
-// Registers
-//-----------
-#define SOFTWARE_REVISION_REG    0x0
-#define COMPASS_BEARING_WORD_REG 0x2
-
-/**
  * CMPS03 digital compass module.
  * more information : http://www.robot-electronics.co.uk/htm/cmps3tech.htm
  */
 class CMPS03 {
 
+private :
+
+    long    _startTime, _stopTime;
+    double  _pwmBearing;
+
 protected :
 
-    I2C* _i2c;
+    //I2C* _i2c;
     InterruptIn _boussole;
     Timer _tim;
 
     void rise();
     void fall();
 
-    int  _i2cAddress;
-    long _startTime, _stopTime, _pwmBearing;
+    //int  _i2cAddress;
 
 public :
 
     /**
      * Constructor of a CMPS03 Compass object.
-     * @note If not used, the two I2C pins should be pulled up.
      *
-     * @param pwm : mbed pin to use to get the bearing Pulse
-     * @param sda : mbed pin to use as the I2C serial data
-     * @param scl : mbed pin to use as the I2C serial clock
-     * @param address : I2C adress of the compass
+     * @param pwm (PinName) : mbed pin used to get the bearing Pulse
      */
-    CMPS03(PinName pwm, PinName sda, PinName scl, int address = 0xC0);
-
-    /**
-     * Reads the software revision register of the compass (I2C register 0).
-     *
-     * @return Software revision register (as a byte).
-     */
-    char readSoftwareRevision(void);
-
-    /**
-     * Reads the current bearing of the compass (I2C registers 2 and 3).
-     *
-     * @return Current bearing of the compass in degree (value between 0.0 and 359.9).
-     */
-    double readBearing(void);
+    CMPS03(PinName pwm);
 
     /**
      * Reads the last bearing of the compass from PWM signal (1 bearing each 100ms approx.).
      *
      * @return Current bearing of the compass in degree (0.00 and 359.99)
+     * @note The bearing is not quite accurate (only integer part is almost good) unless a full calibration is done (thus component is not configurated for calibration).
+     * @note Neither bearing goes from 0 to 359.99. You may considere bearing as something very relative.
      */
     double getBearing(void);
 
     /** 
      * A short hand for getBearing
+     * @return Current bearing of the compass in degree (0.00 and 359.99)
+     * @note The bearing is not quite accurate (only integer part is almost good) unless a full calibration is done (thus component is not configurated for calibration).
+     * @note Neither bearing goes from 0 to 359.99. You may considere bearing as something very relative.
      */
     operator double();