supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
sensor
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/io.h>
24
#include <supla/sensor/virtual_impulse_counter.h>
25
26
namespace
Supla {
27
28
namespace
Sensor {
29
class
ImpulseCounter :
public
VirtualImpulseCounter {
30
public
:
31
explicit
ImpulseCounter(
Supla::Io::IoPin
impulsePin,
32
bool
_detectLowToHigh =
false
,
33
bool
inputPullup =
true
,
34
uint16_t _debounceDelay = 10,
35
uint16_t minSignalTimeToCountMs = 0);
36
ImpulseCounter(
Supla::Io::Base
*io,
37
int
_impulsePin,
38
bool
_detectLowToHigh =
false
,
39
bool
inputPullup =
true
,
40
uint16_t _debounceDelay = 10,
41
uint16_t minSignalTimeToCountMs = 0);
42
ImpulseCounter(
int
_impulsePin,
43
bool
_detectLowToHigh =
false
,
44
bool
inputPullup =
true
,
45
uint16_t _debounceDelay = 10,
46
uint16_t minSignalTimeToCountMs = 0);
47
48
void
onInit
()
override
;
49
void
onFastTimer
()
override
;
50
51
protected
:
52
uint32_t lastImpulseMillis =
53
0;
// Stores timestamp of last impulse (used to ignore
54
// changes of state during 10 ms timeframe)
55
uint32_t lastChangeMs = 0;
56
57
Supla::Io::IoPin
impulsePin;
// Pin where impulses are counted
58
uint16_t debounceDelayMs = 10;
59
uint16_t minSignalTimeToCountMs = 10;
60
61
bool
detectLowToHigh =
false
;
// defines if we count raining (LOW to HIGH) or
62
// falling (HIGH to LOW) edge
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_
Supla::Io::Base
Definition
io.h:36
Supla::Sensor::ImpulseCounter::onInit
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition
impulse_counter.cpp:77
Supla::Sensor::ImpulseCounter::onFastTimer
void onFastTimer() override
Method called on fast timer interupt.
Definition
impulse_counter.cpp:83
Supla::Io::IoPin
Definition
io_pin.h:28
Generated by
1.17.0