supla-device
Loading...
Searching...
No Matches
impulse_counter.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_IMPULSE_COUNTER_H_
20#define SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
21
22#include <supla-common/proto.h>
23#include <supla/sensor/virtual_impulse_counter.h>
24
25namespace Supla {
26
27class Io;
28
29namespace Sensor {
30class ImpulseCounter : public VirtualImpulseCounter {
31 public:
32 ImpulseCounter(Supla::Io *io,
33 int _impulsePin,
34 bool _detectLowToHigh = false,
35 bool inputPullup = true,
36 unsigned int _debounceDelay = 10);
37 ImpulseCounter(int _impulsePin,
38 bool _detectLowToHigh = false,
39 bool inputPullup = true,
40 unsigned int _debounceDelay = 10);
41
42 void onInit() override;
43 void onFastTimer() override;
44
45 protected:
46 Supla::Io *io = nullptr;
47 uint32_t lastImpulseMillis =
48 0; // Stores timestamp of last impulse (used to ignore
49 // changes of state during 10 ms timeframe)
50
51 int16_t impulsePin = -1; // Pin where impulses are counted
52 uint16_t debounceDelay = 10;
53
54 bool detectLowToHigh = false; // defines if we count raining (LOW to HIGH) or
55 // falling (HIGH to LOW) edge
56 bool inputPullup = true;
57 int8_t prevState = 0; // Store previous state of pin (LOW/HIGH). It is used
58 // to track changes on pin state.
59};
60
61} // namespace Sensor
62} // namespace Supla
63
64#endif // SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
Definition io.h:33
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition impulse_counter.cpp:59
void onFastTimer() override
Method called on fast timer interupt.
Definition impulse_counter.cpp:70