supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
BMP180.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O., malarz
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_SENSOR_BMP180_H_
20
#define SRC_SUPLA_SENSOR_BMP180_H_
21
22
// Dependency: Adafruid BMP085 library - use library manager to install it
23
// BMP180 is upgraded version of BMP085
24
#include <Adafruit_BMP085.h>
25
26
#include "therm_press_meter.h"
27
28
namespace
Supla {
29
namespace
Sensor {
30
class
BMP180 :
public
ThermPressMeter {
31
public
:
32
explicit
BMP180(int8_t address = 0x77)
33
: address(address), sensorStatus(
false
) {
34
}
35
36
double
getTemp() {
37
float
value = TEMPERATURE_NOT_AVAILABLE;
38
bool
retryDone =
false
;
39
do
{
40
if
(!sensorStatus || isnan(value)) {
41
sensorStatus = bmp.begin(address);
42
retryDone =
true
;
43
}
44
value = TEMPERATURE_NOT_AVAILABLE;
45
if
(sensorStatus) {
46
value = bmp.readTemperature();
47
}
48
}
while
(isnan(value) && !retryDone);
49
return
value;
50
}
51
52
double
getPressure() {
53
float
value = PRESSURE_NOT_AVAILABLE;
54
bool
retryDone =
false
;
55
do
{
56
if
(!sensorStatus || isnan(value)) {
57
sensorStatus = bmp.begin(address);
58
retryDone =
true
;
59
}
60
value = PRESSURE_NOT_AVAILABLE;
61
if
(sensorStatus) {
62
value = bmp.readPressure() / 100.0;
63
}
64
}
while
(isnan(value) && !retryDone);
65
return
value;
66
}
67
68
void
onInit
() {
69
sensorStatus = bmp.begin(address);
70
71
channel.setNewValue(getTemp());
72
pressureChannel.setNewValue(getPressure());
73
}
74
75
protected
:
76
int8_t address;
77
bool
sensorStatus;
78
Adafruit_BMP085 bmp;
// I2C
79
};
80
81
};
// namespace Sensor
82
};
// namespace Supla
83
84
#endif
// SRC_SUPLA_SENSOR_BMP180_H_
Supla::Sensor::BMP180::onInit
void onInit()
Third method called on element in SuplaDevice.begin().
Definition
BMP180.h:68
Generated by
1.17.0