Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
flash_led.hpp
Go to the documentation of this file.
1#ifndef SBL_CORE_COMPONENTS_DISPLAY_FLASH_LED_HPP_
2#define SBL_CORE_COMPONENTS_DISPLAY_FLASH_LED_HPP_
3
4/**
5 * @file flash_led.hpp
6 * @brief LED flasher for beat indication
7 * @ingroup components
8 */
9
11
12namespace sbl {
13namespace core {
14namespace components {
15namespace display {
16
17/**
18 * @brief LED flasher for beat and event indication
19 *
20 * Provides timed LED flashing for visual feedback.
21 * Encapsulates flash timing patterns for clean application code.
22 *
23 * @tparam LedImpl LED implementation
24 * @tparam TimerImpl Timer implementation for flash timing
25 */
26template<typename LedImpl, typename TimerImpl>
27class FlashLed {
28public:
29 /**
30 * @brief Construct LED flasher
31 * @param led LED instance to control
32 * @param flash_ms Flash duration in milliseconds (default: 50ms)
33 */
34 FlashLed(LedImpl& led, uint32_t flash_ms = 50)
35 : led_(led), flashDuration_(flash_ms), active_(false) {}
36
37 /**
38 * @brief Flash LED
39 *
40 * Starts LED flash. Call update() regularly to handle timing.
41 */
42 void flash() {
43 led_.on();
44 flashTimer_.start(flashDuration_);
45 active_ = true;
46 }
47
48 /**
49 * @brief Update flash state
50 *
51 * Call regularly from main loop to handle flash timing.
52 */
53 void update() {
54 if (active_ && flashTimer_.hasExpired()) {
55 led_.off();
56 active_ = false;
57 }
58 }
59
60 /**
61 * @brief Check if LED is currently flashing
62 * @return true if flash is active
63 */
64 bool isActive() const {
65 return active_;
66 }
67
68 /**
69 * @brief Set flash duration
70 * @param flash_ms New flash duration in milliseconds
71 */
72 void setFlashDuration(uint32_t flash_ms) {
73 flashDuration_ = flash_ms;
74 }
75
76private:
77 LedImpl& led_;
79 uint32_t flashDuration_;
80 bool active_;
81};
82
83} // namespace display
84} // namespace components
85} // namespace core
86} // namespace sbl
87
88#endif // SBL_CORE_COMPONENTS_DISPLAY_FLASH_LED_HPP_
LED flasher for beat and event indication.
Definition flash_led.hpp:27
void update()
Update flash state.
Definition flash_led.hpp:53
bool isActive() const
Check if LED is currently flashing.
Definition flash_led.hpp:64
void setFlashDuration(uint32_t flash_ms)
Set flash duration.
Definition flash_led.hpp:72
FlashLed(LedImpl &led, uint32_t flash_ms=50)
Construct LED flasher.
Definition flash_led.hpp:34
Simple non-blocking delay using system time.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Non-blocking delay utilities for cooperative scheduling.