Simple library for MAG3110 magenetometer as built into Avnet Wi-Go module
Fork of MAG3110 by
Diff: MAG3110.h
- Revision:
- 1:5a0e7a58d980
- Parent:
- 0:63a8594a3866
- Child:
- 2:fb8024297377
--- a/MAG3110.h Sun May 19 20:34:27 2013 +0000 +++ b/MAG3110.h Fri May 24 20:04:48 2013 +0000 @@ -1,5 +1,5 @@ -/* - * MAG3110 Sensor Library for mbed +/* + * MAG3110 Sensor Library for mbed * TODO: Add proper header */ @@ -75,22 +75,66 @@ class MAG3110 { - private: - short _i2c_address; - I2C *_i2c; - Serial *_pc; - bool _debug; - int _avgX, _avgY; //, _newX, _tempXmin, _tempXmax, _newY, _tempYmin, _tempYmax; +private: + int _i2c_address; + I2C _i2c; + Serial *_pc; + bool _debug; + int _avgX, _avgY; - public: - MAG3110(I2C *i2c); - MAG3110(I2C *i2c, Serial *pc); //pass serial for debug - void begin(); - int readReg(char regAddr); - int readVal(char regAddr); - float getHeading(); - void getValues(int *xVal, int *yVal, int *zVal); - void setCalibration(int minX, int maxX, int minY, int maxY); +public: + /** + * MAG3110 constructor + * @param sda SDA pin + * @param sdl SCL pin + * @param addr addr of the I2C peripheral + */ + MAG3110(PinName sda, PinName scl); + /** + * MAG3110 constructor + * @param sda SDA pin + * @param sdl SCL pin + * @param addr addr of the I2C peripheral + * @param pc serial port object to output debug messages + */ + MAG3110(PinName sda, PinName scl, Serial *pc); //pass serial for debug + /** + * Setup the Magnetometer + * + */ + void begin(); + /** + * Read a register, return its value as int + * @param regAddr The address to read + * @return value in register + */ + int readReg(char regAddr); + /** + * Read a value from a pair of registers, return as int + * @param regAddr The address to read + * @return Value from 2 consecutive registers + */ + int readVal(char regAddr); + /** + * Calculate the heading + * @return heading in degrees + */ + float getHeading(); + /** + * Perform a read on the X, Y and Z values. + * @param xVal Pointer to X value + * @param yVal Pointer to Y value + * @param zVal Pointer to Z value + */ + void getValues(int *xVal, int *yVal, int *zVal); + /** + * Set the calibration parameters if required. + * @param minX Minimum value for X range + * @param maxX Maximum value for X range + * @param minY Minimum value for Y range + * @param maxY maximum value for Y range + */ + void setCalibration(int minX, int maxX, int minY, int maxY); }; -#endif \ No newline at end of file +#endif