A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
PhysicalButtonModule.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <chrono>
9#include <optional>
10#include <string>
11
24
29 std::optional<int> arm_gpio;
30 std::optional<int> disarm_gpio;
31 std::optional<int> acknowledge_gpio;
32 bool active_low = true;
33 std::chrono::milliseconds debounce{50};
34};
35
40public:
45
50
55 explicit PhysicalButtonModule(const PhysicalButtonConfig& config);
56
61 bool available() const noexcept;
62
68 bool poll(PhysicalButtonEvent& event) noexcept;
69
77 std::chrono::milliseconds timeout) noexcept;
78
84 bool readAcknowledgePressed(bool& pressed) noexcept;
85
90 const char* lastErrorString() const noexcept;
91
96 const char* statusString() const noexcept;
97
103
109 static const char* eventToString(PhysicalButtonEvent event) noexcept;
110
111private:
112 struct ChannelState {
113 std::optional<int> gpio;
115 std::string value_path;
116 std::string device_path;
117 int line_fd = -1;
118 bool active = false;
119 bool initialised = false;
120 bool last_sample_pressed = false;
121 bool stable_pressed = false;
122 std::chrono::steady_clock::time_point last_transition{};
123 };
124
125 PhysicalButtonConfig config_;
126 ChannelState arm_channel_;
127 ChannelState disarm_channel_;
128 ChannelState acknowledge_channel_;
129 bool available_ = false;
130 std::string last_error_;
131 std::string status_string_;
132
133 static std::optional<int> parseEnvInt(const char* name) noexcept;
134 static bool parseEnvBool(const char* name, bool default_value) noexcept;
135 static std::chrono::milliseconds parseEnvDuration(
136 const char* name,
137 std::chrono::milliseconds default_value) noexcept;
138 static std::string makeValuePath(int gpio);
139
140 void initialiseChannel(ChannelState& channel,
141 std::optional<int> gpio,
142 PhysicalButtonEvent event) noexcept;
143 bool sampleChannel(ChannelState& channel,
144 std::chrono::steady_clock::time_point now,
145 PhysicalButtonEvent& event) noexcept;
146 bool readPressedState(const ChannelState& channel, bool& pressed) noexcept;
147};
PhysicalButtonEvent
Semantic operator requests produced by button input.
@ DISARM_REQUEST
Request to disarm/stop controlled motion.
@ ACK_REQUEST
Request acknowledge/continue after freeze.
@ ARM_REQUEST
Request to arm/start controlled motion.
GPIO character-device based physical button module.
static const char * eventToString(PhysicalButtonEvent event) noexcept
Convert semantic event enum to readable string.
bool poll(PhysicalButtonEvent &event) noexcept
Poll channels and emit a debounced semantic event if available.
const char * statusString() const noexcept
Get compact status summary string.
bool readAcknowledgePressed(bool &pressed) noexcept
Read current acknowledge-button pressed state.
~PhysicalButtonModule()
Destroy module and release any open line descriptors.
bool available() const noexcept
Check whether at least one input channel is available.
const char * lastErrorString() const noexcept
Get last error string.
PhysicalButtonModule()
Construct module from environment-derived configuration.
static PhysicalButtonConfig configFromEnvironment() noexcept
Build button configuration from environment variables.
bool waitForEvent(PhysicalButtonEvent &event, std::chrono::milliseconds timeout) noexcept
Wait for next debounced event using blocking GPIO edge reads.
Configuration for physical button inputs.
std::optional< int > disarm_gpio
BCM GPIO for disarm request, if present.
std::chrono::milliseconds debounce
Debounce interval.
bool active_low
Interpret low level as pressed when true.
std::optional< int > acknowledge_gpio
BCM GPIO for acknowledge request, if present.
std::optional< int > arm_gpio
BCM GPIO for arm request, if present.