PicoLC Arduino Library
Arduino library for PicoLC hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
PicoLCButton.cpp
1
#include "PicoLCClass.h"
2
3
PicoLCButton::PicoLCButton(
PicoLC
& plc) : _plc(plc) {
4
}
5
6
void
PicoLCButton::update(uint32_t currentMillis, uint8_t value) {
7
_lastValue = _currentValue;
8
_currentValue = value ? true :
false
;
9
if
( _inverted ) {
10
_currentValue = !_currentValue;
11
}
12
if
( _filterMillis == 0 ) {
13
return
;
14
}
15
if
( _filterStart > 0 ) {
16
if
( _currentValue != _candidateValue) {
17
_currentValue = _lastValue;
18
_filterStart = currentMillis;
19
return
;
20
}
21
if
( currentMillis - _filterStart >= _filterMillis ) {
22
_filterStart = 0;
23
}
else
{
24
_currentValue = _lastValue;
25
}
26
}
else
{
27
if
( _currentValue != _lastValue ) {
28
_filterStart = currentMillis;
29
_candidateValue = _currentValue;
30
_currentValue = _lastValue;
31
}
32
}
33
}
34
35
void
PicoLCButton::inverted(
bool
invert) {
36
_inverted = invert;
37
}
38
39
void
PicoLCButton::filterMillis
(uint32_t ms) {
40
_filterMillis = ms;
41
}
42
43
uint32_t
PicoLCButton::filterMillis
()
const
{
44
return
_filterMillis;
45
}
46
47
bool
PicoLCButton::read
()
const
{
48
return
_currentValue;
49
}
50
51
bool
PicoLCButton::rising
()
const
{
52
if
( _plc.cycles() == 0 ) {
53
return
false
;
54
}
55
return
(_currentValue ==
true
&& _lastValue ==
false
);
56
}
57
58
bool
PicoLCButton::falling
()
const
{
59
if
( _plc.cycles() == 0 ) {
60
return
false
;
61
}
62
return
(_currentValue ==
false
&& _lastValue ==
true
);
63
}
64
65
bool
PicoLCButton::changed
()
const
{
66
return
(_currentValue != _lastValue);
67
}
PicoLCButton::changed
bool changed() const
Reports any logical button transition.
Definition
PicoLCButton.cpp:65
PicoLCButton::read
bool read() const
Returns the current filtered logical button state.
Definition
PicoLCButton.cpp:47
PicoLCButton::rising
bool rising() const
Reports a logical button press transition.
Definition
PicoLCButton.cpp:51
PicoLCButton::falling
bool falling() const
Reports a logical button release transition.
Definition
PicoLCButton.cpp:58
PicoLCButton::filterMillis
uint32_t filterMillis() const
Returns the configured button-state stability time.
Definition
PicoLCButton.cpp:43
PicoLC
Main interface to PicoLC hardware and shared runtime services.
Definition
PicoLCClass.h:25
src
ui
PicoLCButton.cpp
Generated by
1.17.0