28 [[nodiscard]]
virtual std::shared_ptr<PinObservable>
on_rising_edge(
const std::function<
void()>& fn) = 0;
33 [[nodiscard]]
virtual std::shared_ptr<PinObservable>
on_falling_edge(
const std::function<
void()>& fn) = 0;
49 enum PinType : uint8_t { IN, OUT, INOUT };
81 [[nodiscard]] std::shared_ptr<PinObservable>
subscribe();
86 [[maybe_unused]]
static Pin
IN_0;
91 [[maybe_unused]]
static Pin
OUT_0;
96 [[maybe_unused]]
static Pin
OUT_1;
114 explicit Pin(std::string name,
unsigned int id,
PinType type);
116 void subscribe(std::shared_ptr<SignalHandler>& handler);
118 [[noreturn]]
void update_value();
123 std::atomic<int> m_last_value;
124 std::vector<std::function<void()>> m_on_rising_edge;
125 std::vector<std::function<void()>> m_on_falling_edge;
General observable interface.
Definition observable.h:20
Observable for handling GPIO states.
Definition pins.h:23
virtual std::shared_ptr< PinObservable > on_falling_edge(const std::function< void()> &fn)=0
Handles the falling edge of the pin.
virtual std::shared_ptr< PinObservable > on_rising_edge(const std::function< void()> &fn)=0
Handles the rising edge of the pin.
Interface for the GPIO pins.
Definition pins.h:43
static void release_pins()
Deallocates the pin resources.
PinValue
The value of the pin can be either high or low.
Definition pins.h:55
static Pin IN_0
The GPIO input pin with index 0.
Definition pins.h:86
PinType
The type of pin can be IN, OUT, or INOUT.
Definition pins.h:49
static Pin OUT_1
The GPIO output pin with index 1.
Definition pins.h:96
PinValue get_value() const
Get the current value of the pin.
std::shared_ptr< PinObservable > subscribe()
Subscribe to the pin's state changes.
static Pin OUT_0
The GPIO output pin with index 0.
Definition pins.h:91
void set_low() const
Set the pin to LOW.
void set_high() const
Set the pin to HIGH.
static bool initialize_pins()
Initializes the hardware to support pin operations.