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