2016-03-30 00:44:37 +02:00
|
|
|
#ifdef CONFIG_ENABLE_BMP180
|
2016-03-26 15:27:23 +01:00
|
|
|
#include "BMP180.h"
|
2016-03-26 15:30:18 +01:00
|
|
|
int BMP180Setup(int sda, int scl) {
|
2016-04-07 13:37:55 +02:00
|
|
|
//Use BMP fork at https://github.com/mmaret/BMP180_Breakout_Arduino_Library/archive/master.zip
|
2016-03-26 15:30:18 +01:00
|
|
|
bmp180Connected = bmp180.begin(sda, scl);
|
2016-06-01 00:36:14 +02:00
|
|
|
if (!bmp180Connected){
|
|
|
|
SKETCH_DEBUG_PRINTLN("Cannot connect to BMP180");
|
|
|
|
}
|
2016-03-20 00:14:24 +01:00
|
|
|
return bmp180Connected;
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
bool BMP180IsConnected() {
|
2016-03-20 00:14:24 +01:00
|
|
|
return bmp180Connected != 0;
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
int BMP180GetTemperature(double &t) {
|
2016-03-11 00:43:24 +01:00
|
|
|
char status;
|
2016-06-01 00:36:14 +02:00
|
|
|
if(!BMP180IsConnected())
|
|
|
|
return -1;
|
2016-03-16 00:54:13 +01:00
|
|
|
status = bmp180.startTemperature();
|
2016-03-11 00:43:24 +01:00
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
// Wait for the measurement to complete:
|
|
|
|
delay(status);
|
2016-03-16 00:54:13 +01:00
|
|
|
status = bmp180.getTemperature(t);
|
2016-03-11 00:43:24 +01:00
|
|
|
if (status != 0)
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-16 00:54:13 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-24 14:54:55 +01:00
|
|
|
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);
|
2016-03-25 00:06:33 +01:00
|
|
|
if (status != 0){
|
|
|
|
p = bmp180.sealevel(p, ALTITUDE);
|
2016-03-16 00:54:13 +01:00
|
|
|
return 0;
|
2016-03-25 00:06:33 +01:00
|
|
|
}
|
2016-03-16 00:54:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2016-03-11 00:43:24 +01:00
|
|
|
}
|
2016-03-26 15:27:23 +01:00
|
|
|
#endif
|