supla-device
Loading...
Searching...
No Matches
HC_SR04.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
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_HC_SR04_H_
20#define SRC_SUPLA_SENSOR_HC_SR04_H_
21
22#include "supla/channel.h"
23#include "supla/io.h"
24#include "supla/sensor/distance.h"
25
26#define DURATION_COUNT 2
27
28namespace Supla {
29namespace Sensor {
30class HC_SR04 : public Distance {
31 public:
32 HC_SR04(int8_t trigPin,
33 int8_t echoPin,
34 int16_t minIn = 0,
35 int16_t maxIn = 500,
36 int16_t minOut = 0,
37 int16_t maxOut = 500,
38 Supla::Io::Base *io = nullptr);
39 void onInit();
40 virtual double getValue();
41 void setMinMaxIn(int16_t minIn, int16_t maxIn);
42 void setMinMaxOut(int16_t minOut, int16_t maxOut);
43
44 protected:
45 int8_t _trigPin;
46 int8_t _echoPin;
47 int16_t _minIn;
48 int16_t _maxIn;
49 int16_t _minOut;
50 int16_t _maxOut;
51 char failCount;
52 uint64_t readouts[5];
53 int index;
55};
56
57}; // namespace Sensor
58}; // namespace Supla
59
60#endif // SRC_SUPLA_SENSOR_HC_SR04_H_
Definition io.h:36
void onInit()
Third method called on element in SuplaDevice.begin().
Definition HC_SR04.cpp:40