Igor Skochinsky / Mbed 2 deprecated DCSS504

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MMCx12xM.h Source File

MMCx12xM.h

00001 #include <mbed.h>
00002 #ifndef __MMCx12xM__
00003 #define __MMCx12xM__
00004 
00005 // possible I2C addresses, depending on the chip number
00006 enum
00007 {
00008   MMCx120M = 0x60,
00009   MMCx121M = 0x64,
00010   MMCx122M = 0x68,
00011   MMCx123M = 0x6C,
00012 };
00013 
00014 /* Class: MMCx12xM
00015  *  Control a Memsic MMC212xM magnetometer over I2C
00016  *
00017  * Example:
00018  * > // MMC2120M at address 0x60
00019  * >
00020  * > #include "mbed.h"
00021  * >
00022  * > I2C i2c(p28, p27);
00023  * > MMC212xM memsic1(i2c);
00024  * >
00025  * > int main() {
00026  * >     int data[2];
00027  * >     memsic1.read_raw_values(data, 2);
00028  * > }
00029  */
00030 
00031 class MMCx12xM : public Base
00032 {
00033 public:
00034     // constructor in case you already have an I2C bus instance
00035     MMCx12xM(I2C &i2c, int address = MMCx120M, const char *name = NULL);
00036     // use this constructor if the sensor is the only device on the bus 
00037     MMCx12xM(PinName sda, PinName scl, int address = MMCx120M, const char *name = NULL);
00038     // send a SET coil command
00039     bool coil_set();
00040     // send a RESET coil command
00041     bool coil_reset();
00042     // read raw (12-bit) axis values
00043     bool read_raw_values(int *values, int count = 2);
00044     // start calibration
00045     void calibrate_begin();
00046     // take a single measurement for calibration
00047     void calibrate_step(int count = 2);
00048     // finish calibration and calculate offset and sensitivity values
00049     void calibrate_end();
00050     // read calibrated (-1.0 .. +1.0) axis values
00051     bool read_values(float *values, int count = 2);
00052     virtual ~MMCx12xM();
00053   
00054 private:
00055     bool _send_command(int command);
00056     bool _wait_ready(int command);
00057     bool _read_axis(int *value, int index = -1);
00058 
00059     // reference to the I2C bus
00060     I2C *_I2C;
00061     // sensor slave address
00062     int _addr;
00063     // did we create the bus instance? (i.e. we should delete it on destruct)
00064     bool _own_i2c;
00065     // calibration values
00066     int _sensitivity[3];
00067     int _offset[3];
00068     // temporaries for calibration
00069     int _maxvals[3];
00070     int _minvals[3];
00071 };
00072 
00073 #endif