-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sodaq_TPH.cpp
94 lines (86 loc) · 1.83 KB
/
Sodaq_TPH.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Sodaq_TPH.cpp
*
* This file is part of Sodaq_TPH.
*
* Sodaq_TPH is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or(at your option) any later version.
*
* Sodaq_TPH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sodaq_TPH. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include <Wire.h>
#include <Sodaq_BMP085.h>
#include <Sodaq_SHT2x.h>
#include "Sodaq_TPH.h"
TPH tph;
Sodaq_BMP085 bmp;
void TPH::begin()
{
Wire.begin();
bmp.begin();
}
/*
* Get the temperature in degrees Celsius (average of SHT2x and BMP085 sensors)
*/
float TPH::readTemperature()
{
float result = 0;
float temp;
uint8_t count = 0;
temp = readTemperatureBMP();
if (temp > -200) {
result += temp;
++count;
}
temp = SHT2x.GetTemperature();
if (temp > -200) {
result += temp;
++count;
}
if (count == 0) {
return -273;
}
return result / count;
}
/*
* Get the temperature in degrees Celsius from the BMP085 sensor
*/
float TPH::readTemperatureBMP()
{
float temp = bmp.readTemperature();
if (temp < -273) {
temp = -273;
}
return temp;
}
/*
* Get the air pressure in Pa
*/
int32_t TPH::readPressure()
{
return bmp.readPressure();
}
/*
* Get the temperature in degrees Celsius from the SHT2x sensor
*/
float TPH::readTemperatureSHT()
{
return SHT2x.GetTemperature();
}
/*
* Get the relative humidity in %RH
*/
float TPH::readHumidity()
{
return SHT2x.GetHumidity();
}