projet capteur connecté ST/SE

Dependencies:   HP206C mbed HMC5883L DHT DS1820

Files at this revision

API Documentation at this revision

Comitter:
SBACCARI
Date:
Tue Oct 09 14:43:03 2018 +0000
Parent:
65:3f898ad77cb5
Child:
67:3ccbc6a532eb
Commit message:
function pression to get pressure value

Changed in this revision

altitude.cpp Show annotated file Show diff for this revision Revisions of this file
altitude.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/altitude.cpp	Tue Oct 09 12:36:37 2018 +0000
+++ b/altitude.cpp	Tue Oct 09 14:43:03 2018 +0000
@@ -1,22 +1,15 @@
-#include "mbed.h"
+#include "altitude.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;
-}
+long pression(HP20x_dev barometre)
+{
+    long P = 0;
+    barometre.reset();
+    //pc.printf("SB : available? => %d \r\n", barometre.isAvailable() ); // DEBUG : show sensor status
+    wait(2);
+    P = barometre.ReadPressure();
+    //pc.printf("P = %ul \r\n", P); // DEBUG : print pressure value
+    wait(3);
 
-unsigned long readAltitude(I2C *hp20x) {
-    char cmd = 0x31;
-    hp20x->write(HP20X_I2C_DEV_ID, &cmd, 1);
-    unsigned long altitude = ReadData3byte(hp20x);
-    return altitude;
+    return P;
 }
\ No newline at end of file
--- a/altitude.h	Tue Oct 09 12:36:37 2018 +0000
+++ b/altitude.h	Tue Oct 09 14:43:03 2018 +0000
@@ -1,7 +1,10 @@
 #ifndef __ALTITUDE__
 #define __ALTITUDE__
 
-unsigned long readAltitude(I2C *hp20x);
-unsigned long ReadData3byte(I2C *hp20x);
+#include "mbed.h"
+#include "HP20x_dev.h"
+#include "config.h"
+
+long pression(HP20x_dev barometre);
 
 #endif
\ No newline at end of file
--- a/main.cpp	Tue Oct 09 12:36:37 2018 +0000
+++ b/main.cpp	Tue Oct 09 14:43:03 2018 +0000
@@ -9,7 +9,7 @@
 Serial wisol(SERIAL_PORT);
 Serial pc(USBTX, USBRX);
 DHT sensor(PIN_NAME, DHTtype);
-//HP20x_dev hp206c(HP20X_I2C_PORT);
+HP20x_dev barometre(HP20X_I2C_PORT);
 HMC5883L hmc5883(HMC5883_I2C_PORT);
 
 int main() {
@@ -18,6 +18,7 @@
         char *message;
         int16_t magXYZ[3];
         unsigned long alt;
+        long P = 0;
         /*
         read T&H air
         read T sol
@@ -38,6 +39,7 @@
         //alt = readAltitude(&hp206c);
         hmc5883.getXYZ(magXYZ);
         get_T_H_air(&airT, &airH, sensor); // takes 2s to execute
+        P = pression(barometre);
         
         // Display
         pc.printf("\n=====| Data |=====\n");