3-phase PV router
Loading...
Searching...
No Matches
pin_edges.h
Go to the documentation of this file.
1
20
21#ifndef PIN_EDGES_H
22#define PIN_EDGES_H
23
24#include <stdint.h>
25
30{
31 bool active;
32 bool changed;
33
35 constexpr bool pressed() const
36 {
37 return changed && active;
38 }
39
41 constexpr bool released() const
42 {
43 return changed && !active;
44 }
45};
46
54constexpr PinEdges pinEdges(const bool wasActive, const bool active)
55{
56 return { active, active != wasActive };
57}
58
69template< uint8_t pin >
70PinEdges trackPinEdges(const bool active)
71{
72 static bool wasActive{ false };
73 const PinEdges edges{ pinEdges(wasActive, active) };
74
75 wasActive = active;
76 return edges;
77}
78
87constexpr bool isRotationRequested(const PinEdges& pin, const bool bOverridden)
88{
89 return pin.pressed() && !bOverridden;
90}
91
92#endif /* PIN_EDGES_H */
constexpr bool isRotationRequested(const PinEdges &pin, const bool bOverridden)
Tells whether the rotation pin asks for a rotation now.
Definition pin_edges.h:87
constexpr PinEdges pinEdges(const bool wasActive, const bool active)
The edges of a pin, from its previous level and its current one.
Definition pin_edges.h:54
PinEdges trackPinEdges(const bool active)
Gives the edges of a pin from its current level, and keeps that level for the next call.
Definition pin_edges.h:70
State of an active-LOW input pin, and how it changed since the previous reading.
Definition pin_edges.h:30
constexpr bool released() const
it went HIGH since the previous reading
Definition pin_edges.h:41
constexpr bool pressed() const
it went LOW since the previous reading
Definition pin_edges.h:35
bool changed
Definition pin_edges.h:32
bool active
Definition pin_edges.h:31