-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMPProvider.ino
62 lines (51 loc) · 1.16 KB
/
BMPProvider.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "BMPProvider.h"
SFE_BMP180 bmp180;
void BMPProvider::init()
{
bmp180.begin();
}
/**
* Get temperature measure in C
*/
double BMPProvider::getTemperature(int precision)
{
char status;
double temperature = 0;
long double readings = 0;
for (int i = 0; i < precision; i++) {
status = bmp180.startTemperature();
if (status != 0)
{
delay(status);
status = bmp180.getTemperature(temperature);
}
readings += temperature;
}
return readings / precision;
}
/**
* Get pressure measure in hPa
*/
double BMPProvider::getPressure(double temperature, int precision)
{
char status;
double pressure = 0;
long double readings = 0;
for (int i = 0; i < precision; i++) {
status = bmp180.startPressure(3);
if (status != 0)
{
delay(status);
status = bmp180.getPressure(pressure, temperature);
}
readings += pressure;
}
return readings / precision;
}
/**
* Get sealevel pressure mesure in hPa
*/
double BMPProvider::getSeaLevelPressure(double pressure)
{
return bmp180.sealevel(pressure, ALTITUDE);
}