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