projet capteur connecté ST/SE

Dependencies:   HP206C mbed HMC5883L DHT DS1820

altitude.cpp

Committer:
MathieuM
Date:
2018-10-08
Revision:
49:b1ac7ebb715f
Parent:
15:591f765c620d
Child:
66:cbfcea17a3c5

File content as of revision 49:b1ac7ebb715f:

#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;
}