modified version of MAG3110, include getX();getY();and getZ()
Fork of MAG3110 by
Revision 6:8f4028440d15, committed 2014-02-13
- Comitter:
- allonq
- Date:
- Thu Feb 13 01:58:54 2014 +0000
- Parent:
- 5:888035fbef65
- Commit message:
- create three functions:; float MAG3110::getX();; float MAG3110::getY();; float MAG3110::getZ();; This three functions make the code works more direct
Changed in this revision
MAG3110.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAG3110.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAG3110.cpp Fri Feb 07 00:33:01 2014 +0000 +++ b/MAG3110.cpp Thu Feb 13 01:58:54 2014 +0000 @@ -50,7 +50,7 @@ // read a register per, pass first reg value, reading 2 bytes increments register // Reads MSB first then LSB -int MAG3110::readVal(char regAddr) +float MAG3110::readVal(char regAddr) { char cmd[2]; @@ -60,24 +60,35 @@ cmd[0] = 0x00; cmd[1] = 0x00; _i2c.read(_i2c_address, cmd, 2); - return (int)( (cmd[1]|(cmd[0] << 8))); //concatenate the MSB and LSB + return (float)( (cmd[1]|(cmd[0] << 8))); //concatenate the MSB and LSB } float MAG3110::getHeading() { - int xVal = readVal(MAG_OUT_X_MSB); - int yVal = readVal(MAG_OUT_Y_MSB); + float xVal = readVal(MAG_OUT_X_MSB); + float yVal = readVal(MAG_OUT_Y_MSB); return (atan2((double)(yVal - _avgY),(double)(xVal - _avgX)))*180/PI; } -void MAG3110::getValues(int *xVal, int *yVal, int *zVal) +void MAG3110::getValues(float *xVal, float *yVal, float *zVal) { *xVal = readVal(MAG_OUT_X_MSB); *yVal = readVal(MAG_OUT_Y_MSB); *zVal = readVal(MAG_OUT_Z_MSB); } - +float MAG3110::getX() +{ + return readVal(MAG_OUT_X_MSB); +} +float MAG3110::getY() +{ + return readVal(MAG_OUT_Y_MSB); +} +float MAG3110::getZ() +{ + return readVal(MAG_OUT_Z_MSB); +} void MAG3110::setCalibration(int minX, int maxX, int minY, int maxY ) {
--- a/MAG3110.h Fri Feb 07 00:33:01 2014 +0000 +++ b/MAG3110.h Thu Feb 13 01:58:54 2014 +0000 @@ -111,7 +111,7 @@ * @param regAddr The address to read * @return Value from 2 consecutive registers */ - int readVal(char regAddr); + float readVal(char regAddr); /** * Calculate the heading * @return heading in degrees @@ -123,7 +123,7 @@ * @param yVal Pointer to Y value * @param zVal Pointer to Z value */ - void getValues(int *xVal, int *yVal, int *zVal); + void getValues(float *xVal, float *yVal, float *zVal); /** * Set the calibration parameters if required. * @param minX Minimum value for X range @@ -132,6 +132,9 @@ * @param maxY maximum value for Y range */ void setCalibration(int minX, int maxX, int minY, int maxY); + float getX(); + float getY(); + float getZ(); private: I2C _i2c;