Mathieu Moneyron / Mbed 2 deprecated projetS1

Dependencies:   HP206C mbed HMC5883L DHT DS1820

Revision:
49:b1ac7ebb715f
Parent:
15:591f765c620d
Child:
66:cbfcea17a3c5
diff -r 824fda6804f1 -r b1ac7ebb715f altitude.cpp
--- a/altitude.cpp	Tue Oct 02 13:51:25 2018 +0000
+++ b/altitude.cpp	Mon Oct 08 08:44:16 2018 +0000
@@ -1,2 +1,22 @@
 #include "mbed.h"
+#include "config.h"
 
+unsigned long ReadData3byte(I2C *hp20x) {   
+    unsigned long TempData = 0;
+    char tmpArray[3];
+    hp20x->read(HP20X_I2C_DEV_ID, tmpArray, 3);
+    /* MSB */
+    TempData = tmpArray[0]<<16 | tmpArray[1]<<8 | tmpArray[2];
+    if(TempData&0x800000)
+    {
+        TempData|=0xff000000;
+    }
+    return TempData;
+}
+
+unsigned long readAltitude(I2C *hp20x) {
+    char cmd = 0x31;
+    hp20x->write(HP20X_I2C_DEV_ID, &cmd, 1);
+    unsigned long altitude = ReadData3byte(hp20x);
+    return altitude;
+}
\ No newline at end of file