PicoLC Arduino Library
Arduino library for PicoLC hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
PicoLCInput.cpp
1
#include "PicoLCClass.h"
2
3
PicoLCInput::PicoLCInput(
PicoLC
& plc) : _plc(plc) {
4
}
5
6
void
PicoLCInput::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
PicoLCInput::inverted
(
bool
invert) {
36
_inverted = invert;
37
}
38
39
bool
PicoLCInput::inverted
()
const
{
40
return
_inverted;
41
}
42
43
void
PicoLCInput::filterMillis
(uint32_t ms) {
44
_filterMillis = ms;
45
}
46
47
uint32_t
PicoLCInput::filterMillis
()
const
{
48
return
_filterMillis;
49
}
50
51
bool
PicoLCInput::read
()
const
{
52
return
_currentValue;
53
}
54
55
bool
PicoLCInput::rising
()
const
{
56
if
( _plc.cycles() == 0 ) {
57
return
false
;
58
}
59
return
(_currentValue ==
true
&& _lastValue ==
false
);
60
}
61
62
bool
PicoLCInput::falling
()
const
{
63
if
( _plc.cycles() == 0 ) {
64
return
false
;
65
}
66
return
(_currentValue ==
false
&& _lastValue ==
true
);
67
}
68
69
bool
PicoLCInput::changed
()
const
{
70
return
(_currentValue != _lastValue);
71
}
PicoLC
Main interface to PicoLC hardware and shared runtime services.
Definition
PicoLCClass.h:25
PicoLCInput::filterMillis
uint32_t filterMillis() const
Returns the configured input stability time.
Definition
PicoLCInput.cpp:47
PicoLCInput::changed
bool changed() const
Reports any logical input transition.
Definition
PicoLCInput.cpp:69
PicoLCInput::inverted
bool inverted() const
Returns whether logical input inversion is enabled.
Definition
PicoLCInput.cpp:39
PicoLCInput::read
bool read() const
Returns the current filtered logical input state.
Definition
PicoLCInput.cpp:51
PicoLCInput::falling
bool falling() const
Reports a true-to-false logical transition.
Definition
PicoLCInput.cpp:62
PicoLCInput::rising
bool rising() const
Reports a false-to-true logical transition.
Definition
PicoLCInput.cpp:55
src
io
PicoLCInput.cpp
Generated by
1.17.0