PicoLC Arduino Library
Arduino library for PicoLC hardware
Loading...
Searching...
No Matches
PicoLCInput.h
1#pragma once
2
3#include <Arduino.h>
4
5class PicoLC;
6
7/**
8 * @brief Represents one filtered, logical PicoLC input.
9 *
10 * PicoLCInput samples a physical input during PicoLC::update(), applies
11 * optional inversion, then applies the configured stability filter before
12 * updating its logical state. Edge detection operates only on the resulting
13 * logical state.
14 *
15 * Instances are created and owned by PicoLC and are accessed through members
16 * such as PicoLC::X0 through PicoLC::X3.
17 */
18class PicoLCInput {
19 friend class PicoLC;
20
21private:
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 an input associated with an internal channel.
32 *
33 * PicoLC creates and initializes input instances during begin().
34 *
35 * @param plc Reference to the parent PicoLC instance.
36 */
37 PicoLCInput(PicoLC& plc);
38
39 /**
40 * @brief Samples and updates the input for one scan.
41 *
42 * Inversion is applied before filtering. A new logical state is accepted
43 * only after the candidate value remains stable for the configured filter
44 * duration. Edge state remains valid until the next PicoLC::update().
45 *
46 * The initialization scan synchronizes input state without generating
47 * rising, falling, or changed indications.
48 *
49 * @param currentMillis Current PicoLC scan time in milliseconds.
50 * @param value Sampled input state, true when active.
51 */
52 void update(uint32_t currentMillis, uint8_t value);
53
54 PicoLCInput(const PicoLCInput&) = delete;
55 PicoLCInput& operator=(const PicoLCInput&) = delete;
56
57public:
58 /**
59 * @brief Returns the current filtered logical input state.
60 *
61 * The value changes only during PicoLC::update().
62 *
63 * @return Current logical input state.
64 */
65 bool read() const;
66
67 /**
68 * @brief Reports a false-to-true logical transition.
69 *
70 * Filtering and inversion are applied before edge detection. The result
71 * remains true for the current scan and is cleared by the next
72 * PicoLC::update().
73 *
74 * @return true when the logical input rose during the current scan.
75 */
76 bool rising() const;
77
78 /**
79 * @brief Reports a true-to-false logical transition.
80 *
81 * Filtering and inversion are applied before edge detection. The result
82 * remains true for the current scan and is cleared by the next
83 * PicoLC::update().
84 *
85 * @return true when the logical input fell during the current scan.
86 */
87 bool falling() const;
88
89 /**
90 * @brief Reports any logical input transition.
91 *
92 * Filtering and inversion are applied before change detection. The result
93 * remains true for the current scan and is cleared by the next
94 * PicoLC::update().
95 *
96 * @return true when the logical input changed during the current scan.
97 */
98 bool changed() const;
99
100 /**
101 * @brief Sets the required input stability time.
102 *
103 * A value of zero disables filtering and applies the sampled logical state
104 * during the next PicoLC::update(). Changing the duration does not restart
105 * an active filter interval; the new value is compared against the
106 * existing elapsed interval during the next update.
107 *
108 * @param ms Required stability time in milliseconds.
109 */
110 void filterMillis(uint32_t ms);
111
112 /**
113 * @brief Returns the configured input stability time.
114 *
115 * @return Filter duration in milliseconds.
116 */
117 uint32_t filterMillis() const;
118
119 /**
120 * @brief Enables or disables logical input inversion.
121 *
122 * Inversion is applied before filtering and edge detection. This is a
123 * setup-time configuration setting. Behavior is undefined if changed
124 * while normal scan processing is active.
125 *
126 * The new setting takes effect during the next PicoLC::update().
127 *
128 * @param invert true to invert the sampled physical input.
129 */
130 void inverted(bool invert);
131
132 /**
133 * @brief Returns whether logical input inversion is enabled.
134 *
135 * @return true when the sampled physical input is inverted.
136 */
137 bool inverted() const;
138};
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.