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 uint16_t _debounceDelay = 10,
39 uint16_t minSignalTimeToCountMs = 0);
40 ImpulseCounter(int _impulsePin,
41 bool _detectLowToHigh = false,
42 bool inputPullup = true,
43 uint16_t _debounceDelay = 10,
44 uint16_t minSignalTimeToCountMs = 0);
45
46 void onInit() override;
47 void onFastTimer() override;
48
49 protected:
50 Supla::Io::Base *io = nullptr;
51 uint32_t lastImpulseMillis =
52 0; // Stores timestamp of last impulse (used to ignore
53 // changes of state during 10 ms timeframe)
54 uint32_t lastChangeMs = 0;
55
56 int16_t impulsePin = -1; // Pin where impulses are counted
57 uint16_t debounceDelayMs = 10;
58 uint16_t minSignalTimeToCountMs = 10;
59
60 bool detectLowToHigh = false; // defines if we count raining (LOW to HIGH) or
61 // falling (HIGH to LOW) edge
62 bool inputPullup = true;
63 int8_t prevState = 0; // Store previous state of pin (LOW/HIGH). It is used
64 // to track changes on pin state.
65 int8_t newStateCandidate = 0; // Stores new state of pin (LOW/HIGH)
66};
67
68} // namespace Sensor
69} // namespace Supla
70
71#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:66
void onFastTimer() override
Method called on fast timer interupt.
Definition impulse_counter.cpp:78