ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
safe_led.hpp
Go to the documentation of this file.
1
5#ifndef ELEC_C7222_DEVICES_SAFE_LED_HPP
6#define ELEC_C7222_DEVICES_SAFE_LED_HPP
7
8#include <chrono>
9#include <condition_variable>
10#include <mutex>
11
12#include "led.hpp"
13#include "non_copyable.hpp"
14#include "platform.hpp"
15
16namespace c7222 {
17
45 public:
49 explicit SafeLed(Led& led);
57 explicit SafeLed(PicoWBoard::LedId id) : SafeLed(Platform::GetInstance()->GetLed(id)) {}
58
62 void Acquire();
69 bool AcquireFor(uint32_t timeout);
73 void Release();
77 bool IsHeld() const;
78
82 void Set(bool on);
86 void On();
90 void Off();
94 void Toggle();
95
96 private:
98 Led& led_;
100 mutable std::mutex mutex_;
102 std::condition_variable cv_;
104 bool locked_ = false;
105};
106
107} // namespace c7222
108
109#endif // ELEC_C7222_DEVICES_SAFE_LED_HPP
Output-only GPIO wrapper intended for LEDs.
Definition led.hpp:39
Disable both copy and move operations.
Definition non_copyable.hpp:75
LedId
Logical LED identifiers mapped to GPIO pins.
Definition c7222_pico_w_board.hpp:52
Singleton access to platform-specific devices and initialization.
Definition platform.hpp:118
LED wrapper that prevents simultaneous control from multiple threads.
Definition safe_led.hpp:44
bool AcquireFor(uint32_t timeout)
Acquire exclusive control with a timeout.
Definition safe_led.cpp:16
void Toggle()
Toggle the LED (requires Acquire()).
Definition safe_led.cpp:55
void On()
Turn the LED on (requires Acquire()).
Definition safe_led.cpp:45
SafeLed(PicoWBoard::LedId id)
Construct a SafeLed wrapper for a board LED by logical ID.
Definition safe_led.hpp:57
bool IsHeld() const
Return true if this object currently holds the lock.
Definition safe_led.cpp:35
void Set(bool on)
Set the LED state (requires Acquire()).
Definition safe_led.cpp:40
void Acquire()
Acquire exclusive control of the LED (blocks until available).
Definition safe_led.cpp:10
void Off()
Turn the LED off (requires Acquire()).
Definition safe_led.cpp:50
void Release()
Release exclusive control of the LED.
Definition safe_led.cpp:25
Output-only GPIO abstraction for LEDs.
C7222 course abstractions namespace.
Definition ble.hpp:20
Base classes to control copy/move semantics.
Platform encapsulation for board-level devices.