Forked from Jose R. Padron and Aaron Berk's library, customized for my specific application using 9DoF-Stick by Sparkfun.

Fork of HMC5843 by Jose R Padron

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が日本語をサポートするまでは英語でコメントを書いていきますが、サポートした後もきっと英語で書いていくでしょう。

Files at this revision

API Documentation at this revision

Comitter:
gltest26
Date:
Sat Sep 29 14:18:48 2012 +0000
Parent:
5:a83508250db7
Commit message:
Added a new constructor to accept an external I2C interface object.

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
diff -r a83508250db7 -r 05aa3555fce6 HMC5843.cpp
--- a/HMC5843.cpp	Wed Sep 12 22:53:13 2012 +0000
+++ b/HMC5843.cpp	Sat Sep 29 14:18:48 2012 +0000
@@ -36,7 +36,7 @@
 
 #include "HMC5843.h"
 
-HMC5843::HMC5843(PinName sda, PinName scl) : i2c_(sda, scl){
+HMC5843::HMC5843(PinName sda, PinName scl) : i2c_(*(new I2C(sda, scl))), myI2c(&i2c_){
 
     //100KHz, as specified by the datasheet.
     i2c_.frequency(100000);
diff -r a83508250db7 -r 05aa3555fce6 HMC5843.h
--- a/HMC5843.h	Wed Sep 12 22:53:13 2012 +0000
+++ b/HMC5843.h	Sat Sep 29 14:18:48 2012 +0000
@@ -128,6 +128,20 @@
      * @param scl mbed pin to use for SCL line of I2C interface.
      */
     HMC5843(PinName sda, PinName scl);
+    
+    /**
+     * Constructor that accepts external i2c interface object.
+     *
+     * @param i2c The I2C interface object to use.
+     */
+    HMC5843(I2C &i2c) : i2c_(i2c), myI2c(NULL){}
+    
+    /**
+     * Destructor that frees self-allocated I2C object.
+     */
+    ~HMC5843(){
+        delete myI2c;
+    }
 
         
      /**
@@ -237,7 +251,9 @@
      * There's no point dynamically allocating an I2C object in this class,
      * at least you should write destructor to release it!
      */
-    I2C i2c_;
+    I2C &i2c_;
+    
+    I2C *myI2c;
 
     /**
      * Converts big-endian 2's complement byte pair to native byte order of