Sound Byte Libs
1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
src
sbl
components
display
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
10
#include <
sbl/patterns/timing/non_blocking_delay.hpp
>
11
12
namespace
sbl
{
13
namespace
core {
14
namespace
components {
15
namespace
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
*/
26
template
<
typename
LedImpl,
typename
TimerImpl>
27
class
FlashLed
{
28
public
:
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
76
private
:
77
LedImpl& led_;
78
sbl::core::patterns::timing::NonBlockingDelay<TimerImpl>
flashTimer_;
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_
sbl::core::components::display::FlashLed
LED flasher for beat and event indication.
Definition
flash_led.hpp:27
sbl::core::components::display::FlashLed::flash
void flash()
Flash LED.
Definition
flash_led.hpp:42
sbl::core::components::display::FlashLed::update
void update()
Update flash state.
Definition
flash_led.hpp:53
sbl::core::components::display::FlashLed::isActive
bool isActive() const
Check if LED is currently flashing.
Definition
flash_led.hpp:64
sbl::core::components::display::FlashLed::setFlashDuration
void setFlashDuration(uint32_t flash_ms)
Set flash duration.
Definition
flash_led.hpp:72
sbl::core::components::display::FlashLed::FlashLed
FlashLed(LedImpl &led, uint32_t flash_ms=50)
Construct LED flasher.
Definition
flash_led.hpp:34
sbl::core::patterns::timing::NonBlockingDelay
Simple non-blocking delay using system time.
Definition
non_blocking_delay.hpp:31
sbl::core::patterns::timing::NonBlockingDelay::start
void start()
Start the delay timer.
Definition
non_blocking_delay.hpp:43
sbl
Root namespace for all Sound Byte Libs functionality.
Definition
aliases.hpp:24
non_blocking_delay.hpp
Non-blocking delay utilities for cooperative scheduling.
Generated by
1.9.8