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
27namespace Io {
28class Base;
29}
30
31namespace Sensor {
32class ImpulseCounter : public VirtualImpulseCounter {
33 public:
34 ImpulseCounter(Supla::Io::Base *io,
35 int _impulsePin,
36 bool _detectLowToHigh = false,
37 bool inputPullup = true,
38 unsigned int _debounceDelay = 10);
39 ImpulseCounter(int _impulsePin,
40 bool _detectLowToHigh = false,
41 bool inputPullup = true,
42 unsigned int _debounceDelay = 10);
43
44 void onInit() override;
45 void onFastTimer() override;
46
47 protected:
48 Supla::Io::Base *io = nullptr;
49 uint32_t lastImpulseMillis =
50 0; // Stores timestamp of last impulse (used to ignore
51 // changes of state during 10 ms timeframe)
52
53 int16_t impulsePin = -1; // Pin where impulses are counted
54 uint16_t debounceDelay = 10;
55
56 bool detectLowToHigh = false; // defines if we count raining (LOW to HIGH) or
57 // falling (HIGH to LOW) edge
58 bool inputPullup = true;
59 int8_t prevState = 0; // Store previous state of pin (LOW/HIGH). It is used
60 // to track changes on pin state.
61};
62
63} // namespace Sensor
64} // namespace Supla
65
66#endif // SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
Definition io.h:35
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