Domotique/WifiControlSensor/BMP180.ino

46 lines
905 B
Arduino
Raw Normal View History

// Get Current altitude with http://fr.mygeoposition.com/
#define ALTITUDE 130
2016-03-20 00:14:24 +01:00
SFE_BMP180 bmp180;
int bmp180Connected = 0;
int BMP180Setup() {
2016-03-20 00:14:24 +01:00
bmp180Connected = bmp180.begin(SDA, SCL);
return bmp180Connected;
}
bool BMP180IsConnected() {
2016-03-20 00:14:24 +01:00
return bmp180Connected != 0;
}
int BMP180GetTemperature(double &t) {
char status;
2016-03-16 00:54:13 +01:00
status = bmp180.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
2016-03-16 00:54:13 +01:00
status = bmp180.getTemperature(t);
if (status != 0)
return 0;
}
2016-03-16 00:54:13 +01:00
return -1;
}
int BMP180GetTempAndPressure(double &t, double &p) {
if (BMP180GetTemperature(t) == 0) {
2016-03-16 00:54:13 +01:00
char status;
status = bmp180.startPressure(3);
if (status != 0)
{
delay(status);
status = bmp180.getPressure(p, t);
if (status != 0){
p = bmp180.sealevel(p, ALTITUDE);
2016-03-16 00:54:13 +01:00
return 0;
}
2016-03-16 00:54:13 +01:00
}
}
return -1;
}