PicoLC Arduino Library
Arduino library for PicoLC hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
PicoLCButton.h
1
#pragma once
2
3
#include <Arduino.h>
4
5
class
PicoLC
;
6
7
/**
8
* @brief Represents one filtered, logical PicoLC button.
9
*
10
* PicoLCButton samples a board-defined button during PicoLC::update(), applies
11
* its configured inversion, then applies the configured stability filter
12
* before updating the logical button state. Edge detection operates only on
13
* the resulting logical state.
14
*
15
* Instances are created and owned by PicoLC and are accessed through members
16
* such as PicoLC::BootButton, PicoLC::RunStopButton, and PicoLC::UserButton.
17
*/
18
class
PicoLCButton {
19
friend
class
PicoLC;
20
21
private
:
22
PicoLC &_plc;
23
bool
_lastValue =
false
;
24
bool
_currentValue =
false
;
25
uint32_t _filterMillis = 0;
26
uint32_t _filterStart = 0;
27
bool
_candidateValue =
false
;
28
bool
_inverted =
false
;
29
30
/**
31
* @brief Constructs a button associated with an internal channel.
32
*
33
* PicoLC creates and initializes button instances during begin(). The
34
* channel value is an opaque, board-specific identifier and should not be
35
* interpreted by user code.
36
*
37
* @param plc PicoLC instance that owns the button and provides scan state.
38
*/
39
explicit
PicoLCButton(PicoLC& plc);
40
41
/**
42
* @brief Samples and updates the button for one scan.
43
*
44
* Inversion is applied before filtering. A new logical state is accepted
45
* only after the candidate value remains stable for the configured filter
46
* duration. Edge state remains valid until the next PicoLC::update().
47
*
48
* The initial scan synchronizes button state without generating rising,
49
* falling, or changed indications.
50
*
51
* @param currentMillis Current PicoLC scan time in milliseconds.
52
* @param value Sampled button state, true when pressed.
53
*/
54
void
update(uint32_t currentMillis, uint8_t value);
55
56
PicoLCButton(
const
PicoLCButton&) =
delete
;
57
PicoLCButton& operator=(
const
PicoLCButton&) =
delete
;
58
59
/**
60
* @brief Sets the board-defined logical inversion for the button.
61
*
62
* Inversion is configured internally by PicoLC and is applied before
63
* filtering and edge detection.
64
*
65
* @param invert true to invert the sampled physical button state.
66
*/
67
void
inverted(
bool
invert);
68
69
public
:
70
/**
71
* @brief Returns the current filtered logical button state.
72
*
73
* The value is true when the button is logically pressed and changes only
74
* during PicoLC::update().
75
*
76
* @return true when the button is logically pressed.
77
*/
78
bool
read
()
const
;
79
80
/**
81
* @brief Reports a logical button press transition.
82
*
83
* Filtering and inversion are applied before edge detection. The result
84
* remains true for the current scan and is cleared by the next
85
* PicoLC::update().
86
*
87
* @return true when the logical button state changed from released to
88
* pressed during the current scan.
89
*/
90
bool
rising
()
const
;
91
92
/**
93
* @brief Reports a logical button release transition.
94
*
95
* Filtering and inversion are applied before edge detection. The result
96
* remains true for the current scan and is cleared by the next
97
* PicoLC::update().
98
*
99
* @return true when the logical button state changed from pressed to
100
* released during the current scan.
101
*/
102
bool
falling
()
const
;
103
104
/**
105
* @brief Reports any logical button transition.
106
*
107
* Filtering and inversion are applied before change detection. The result
108
* remains true for the current scan and is cleared by the next
109
* PicoLC::update().
110
*
111
* @return true when the logical button state changed during the current
112
* scan.
113
*/
114
bool
changed
()
const
;
115
116
/**
117
* @brief Sets the required button-state stability time.
118
*
119
* A value of zero disables filtering and applies the sampled logical state
120
* during the next PicoLC::update(). Changing the duration does not restart
121
* an active filter interval; the new value is compared against the
122
* existing elapsed interval during the next update.
123
*
124
* @param ms Required stability time in milliseconds.
125
*/
126
void
filterMillis
(uint32_t ms);
127
128
/**
129
* @brief Returns the configured button-state stability time.
130
*
131
* @return Filter duration in milliseconds.
132
*/
133
uint32_t
filterMillis
()
const
;
134
};
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
PicoLCButton.h
Generated by
1.17.0