Revision:
1:bdf678f27614
Parent:
0:5b09476278da
Child:
2:2645c4d75671
--- a/HMC6343.h	Fri Apr 29 22:10:27 2011 +0000
+++ b/HMC6343.h	Sun May 01 13:51:14 2011 +0000
@@ -1,7 +1,7 @@
 /**
+ * @author Serge Sozonoff 
  * @author Aaron Berk
- * @author Serge Sozonoff 
- * Based on the work of Aaron Berk for the HMC6352
+ * Partially based on the work of Aaron Berk for the HMC6352
  *
  * @section LICENSE
  *
@@ -95,27 +95,27 @@
 
 // Operation mode bit masks
 // LSB
-#define HMC6343_COMP    0x128
-#define HMC6343_CAL     0x64
-#define HMC6343_FILTER  0x32
-#define HMC6343_RUN     0x16
+#define HMC6343_COMP    0x80
+#define HMC6343_CAL     0x40
+#define HMC6343_FILTER  0x20
+#define HMC6343_RUN     0x10
 #define HMC6343_STDBY   0x08
 #define HMC6343_UF      0x04
 #define HMC6343_UE      0x02
 #define HMC6343_LEVEL   0x01
 
-// MSB
-#define HMC6343_MR1 0x256
-#define HMC6343_MR2 0x512
-
 
 //Operational mode register masks.
 #define HMC6343_CM_MR_1HZ    0x00
-#define HMC6343_CM_MR_5HZ    0x20
-#define HMC6343_CM_MR_10HZ   0x40
-#define HMC6343_CM_MR_NA   0x60
+#define HMC6343_CM_MR_5HZ    0x100
+#define HMC6343_CM_MR_10HZ   0x200
+
 
-#define HMC6343_PERIODIC_SR  0x10
+struct Heading {
+    double heading;
+    double pitch;
+    double roll;
+};
 
 /**
  * Honeywell HMC6343 digital compass.
@@ -131,6 +131,8 @@
      * @param scl mbed pin to use for SCL line of I2C interface.
      */
     HMC6343(PinName sda, PinName scl);
+    
+    HMC6343(I2C& p_itc);
 
     /**
      * Sample the device and return the result.
@@ -146,7 +148,7 @@
      *         In magnetometer Y mode, the corrected output of the Y-axis
      *         magnetometer.
      */
-    double sampleHeading(void);
+    void sampleHeading(Heading* p_heading);
 
     /**
      * Update bridge offsets.
@@ -205,39 +207,22 @@
     /**
      * Set the operation mode.
      *
-     * @param mode 0x00 -> Standby mode
-     *             0x01 -> Query mode
-     *             0x02 -> Continuous mode
      * @param periodicSetReset 0x00 -> No periodic set/reset
      *                         0x01 -> Periodic set/reset
-     * @measurementRate Measurement rate in Hz for continuous rate.
-     *                  Possible rates: {1, 5, 10, 20}Hz.
      */
-    void setOpMode(int mode, int periodicSetReset, int measurementRate = 0);
-
-    /**
-     * Get the current output mode of the device.
-     *
-     * @return The current output mode.
-     */
-    int getOutputMode(void);
-
-    /**
-     * Set the output mode of the device.
-     *
-     * @param mode 0x00 -> Heading mode
-     *             0x01 -> Raw magnetometer X mode
-     *             0x02 -> Raw magnetometer Y mode
-     *             0x03 -> Magnetometer X mode
-     *             0x04 -> Magnetometer Y mode
-     */
-    void setOutputMode(int mode);
+    void setOpMode(int opMode);
 
 
     void setMagneticVariation(float var);
     float getMagneticVariation();
     void setMagneticDeviation(float data);
     float getMagneticDeviation();
+    bool isOpModeFlagSet(int flag);
+    void setIIRFilter(short data);
+    short getIIRFilter();      
+    void setMagOffset(int axis, int offset);
+    int getMagOffset(int axis);  
+    char getMeasurementRate();
 
 private:
 
@@ -250,7 +235,7 @@
      * @param address Address to write to.
      * @param data Data to write.
      */
-    void write(int address, int data);
+    void writeEeprom(int address, int data);
 
     /**
      * Read EEPROM on the device.
@@ -258,11 +243,10 @@
      * @param address Address to read from.
      * @return The contents of the memory address.
      */
-    int read(int address);
+    int readEeprom(int address);
 
-    void writeFloat(int lsb_address, float data);
-    float readFloat(int lsb_eprom_address);
-
+    void writeShort(int lsb_address, short data);
+    short readShort(int lsb_eprom_address);    
 };
 
 #endif /* HMC6343_H */