HMC58X3 Library

Fork of HMC58X3 by Yifei Teng

Revision:
4:8eb12adc8368
Parent:
3:1e0e0c47287a
--- a/HMC58X3.h	Tue Nov 05 11:30:31 2013 +0000
+++ b/HMC58X3.h	Sat Nov 09 08:51:00 2013 +0000
@@ -34,6 +34,11 @@
 #ifndef HMC58X3_h
 #define HMC58X3_h
 
+#ifndef I2C_SDA
+    #define I2C_SDA p28
+    #define I2C_SCL p27
+#endif
+
 #define HMC58X3_ADDR 0x1E // 7 bit address of the HMC58X3 used with the Wire library
 #define HMC_POS_BIAS 1
 #define HMC_NEG_BIAS 2
@@ -75,7 +80,7 @@
 #endif
 
 #define HMC58X3_R_STATUS 9
-#define HMC58X3_R_IDA 10
+//#define HMC58X3_R_IDA 10
 #define HMC58X3_R_IDB 11
 #define HMC58X3_R_IDC 12
 
@@ -84,7 +89,7 @@
 
 
 public:
-    HMC58X3(I2C i2c_);
+    HMC58X3();
     void init(bool setmode);
     void init(int address, bool setmode);
     void getValues(int16_t *x,int16_t *y,int16_t *z);
@@ -98,11 +103,23 @@
     void setDOR(unsigned char DOR);
     void setGain(unsigned char gain);
     void getID(char id[3]);
+    
+    int16_t cache_x, cache_y, cache_z;
+    
+    static void samplingthread_stub(void const *p);
+    
+    void samplingthread();
+    void start_sampling();
 
     static const int I2C_ADDRESS = 0x3D;
+    char HMC58X3_R_IDA;
+    MODI2C i2c;
+    
+    Thread _thread;
+    
+    Semaphore sem;
 
 private:
-    I2C i2c;
     void writeReg(unsigned char reg, unsigned char val);
     float x_scale,y_scale,z_scale,x_max,y_max,z_max;
     int min(int a, int b);