Forked from Jose R. Padron and Aaron Berk's library, customized for my specific application using 9DoF-Stick by Sparkfun.
Fork of HMC5843 by
HMC5843 is triple axis, digital interface compass (geomagnetic sensor).
This library is forked from Jose R. Padron and Aaron Berk's work.
This library is for specific application using 9DoF-Stick.
Datasheet:
http://www.sparkfun.com/datasheets/Sensors/Magneto/HMC5843.pdf
HMC5843 は3軸のデジタルインターフェースを備えたコンパス(地磁気センサ)です。
このライブラリは 9DoF-Stick を使用した特定の企画のために保守しています。
mbed IDEが日本語をサポートするまでは英語でコメントを書いていきますが、サポートした後もきっと英語で書いていくでしょう。
Revision 2:fdab96fc6fff, committed 2010-11-09
- Comitter:
- elrafapadron
- Date:
- Tue Nov 09 23:18:46 2010 +0000
- Parent:
- 1:65e41eb3c291
- Child:
- 3:69f24a492b69
- Commit message:
- Add functions to get Mx, My and Mz.
Correct function declaration; readData function wasn\t visible
Changed in this revision
HMC5843.cpp | Show annotated file Show diff for this revision Revisions of this file |
HMC5843.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HMC5843.cpp Sat Oct 23 23:39:03 2010 +0000 +++ b/HMC5843.cpp Tue Nov 09 23:18:46 2010 +0000 @@ -1,6 +1,6 @@ /** * @author Jose R. Padron - *@author Used HMCHMC6352 library developed by Aaron Berk as template + * @author Used HMC6352 library developed by Aaron Berk as template * @section LICENSE * * Copyright (c) 2010 ARM Limited @@ -74,12 +74,6 @@ wait_ms(100); } -//void HMC5843::SelfTest() { - - //Future - -//} - void HMC5843::getAddress(char *buffer) { @@ -137,5 +131,46 @@ i2c_->read(HMC5843_I2C_READ,rx,2); readings[2]= (int)rx[0]<<8|(int)rx[1]; +} + +int HMC5843::getMx() { + + char tx[1]; + char rx[2]; + + + tx[0]=HMC5843_X_MSB; + i2c_->write(HMC5843_I2C_READ,tx,1); + i2c_->read(HMC5843_I2C_READ,rx,2); + return ((int)rx[0]<<8|(int)rx[1]); } + +int HMC5843::getMy() { + + char tx[1]; + char rx[2]; + + + tx[0]=HMC5843_Y_MSB; + i2c_->write(HMC5843_I2C_READ,tx,1); + i2c_->read(HMC5843_I2C_READ,rx,2); + return ((int)rx[0]<<8|(int)rx[1]); + +} + + +int HMC5843::getMz(){ + + char tx[1]; + char rx[2]; + + + tx[0]=HMC5843_Z_MSB; + i2c_->write(HMC5843_I2C_READ,tx,1); + i2c_->read(HMC5843_I2C_READ,rx,2); + return ((int)rx[0]<<8|(int)rx[1]); + +} + +
--- a/HMC5843.h Sat Oct 23 23:39:03 2010 +0000 +++ b/HMC5843.h Tue Nov 09 23:18:46 2010 +0000 @@ -1,6 +1,6 @@ /** * @author Jose R. Padron - *@author Used HMC5843 library developed by Aaron Berk as template + * @author Used HMC5843 library developed by Aaron Berk as template * @section LICENSE * * Copyright (c) 2010 ARM Limited @@ -139,15 +139,7 @@ */ void setDefault(); - - - /** - * Perform Self Test. - * - */ - // void SelfTest(); - - + /** * Read the memory location on the device which contains the address. * @@ -172,21 +164,46 @@ /** * Write to on the device. * - * @param address Address to write to. + * @param address Address to write to. * @param data Data to write. */ + void write(int address, int data); - /* Get the output of all three axes. + /** + * Get the output of all three axes. * * @param Pointer to a buffer to hold the magnetics value for the * x-axis, y-axis and z-axis [in that order]. */ void readData(int* readings); - /* Get the current operation mode. + /** + * Get the output of X axis. + * + * @return x-axis magnetic value + */ + int getMx(); + + /** + * Get the output of Y axis. * - * @return Staus register values + * @return y-axis magnetic value + */ + int getMy(); + + /** + * Get the output of Z axis. + * + * @return z-axis magnetic value + */ + int getMz(); + + + /** + * Get the current operation mode. + * + * @return Status register values */ int getStatus(void);