supla-device
Loading...
Searching...
No Matches
impulse_counter.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
5#define SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
6
7#include <supla-common/proto.h>
8#include <supla/io.h>
9#include <supla/sensor/virtual_impulse_counter.h>
10
11namespace Supla {
12
13namespace Sensor {
15 public:
16 explicit ImpulseCounter(Supla::Io::IoPin impulsePin,
17 bool _detectLowToHigh = false,
18 bool inputPullup = true,
19 uint16_t _debounceDelay = 10,
20 uint16_t minSignalTimeToCountMs = 0);
22 int _impulsePin,
23 bool _detectLowToHigh = false,
24 bool inputPullup = true,
25 uint16_t _debounceDelay = 10,
26 uint16_t minSignalTimeToCountMs = 0);
27 ImpulseCounter(int _impulsePin,
28 bool _detectLowToHigh = false,
29 bool inputPullup = true,
30 uint16_t _debounceDelay = 10,
31 uint16_t minSignalTimeToCountMs = 0);
32
33 void onInit() override;
34 void onFastTimer() override;
35
36 protected:
37 uint32_t lastImpulseMillis =
38 0; // Stores timestamp of last impulse (used to ignore
39 // changes of state during 10 ms timeframe)
40 uint32_t lastChangeMs = 0;
41
42 Supla::Io::IoPin impulsePin; // Pin where impulses are counted
43 uint16_t debounceDelayMs = 10;
44 uint16_t minSignalTimeToCountMs = 10;
45
46 bool detectLowToHigh = false; // defines if we count raining (LOW to HIGH) or
47 // falling (HIGH to LOW) edge
48 int8_t prevState = 0; // Store previous state of pin (LOW/HIGH). It is used
49 // to track changes on pin state.
50 int8_t newStateCandidate = 0; // Stores new state of pin (LOW/HIGH)
51};
52
53} // namespace Sensor
54} // namespace Supla
55
56#endif // SRC_SUPLA_SENSOR_IMPULSE_COUNTER_H_
Definition io.h:23
Definition impulse_counter.h:14
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition impulse_counter.cpp:62
void onFastTimer() override
Method called on fast timer interupt.
Definition impulse_counter.cpp:68
Definition virtual_impulse_counter.h:14
Definition io_pin.h:14