1A flash LED driver controlled via EN-pin pulse protocol
More...
#include <unit_AW3641E.hpp>
|
| | UnitAW3641E (const uint8_t addr=DEFAULT_ADDRESS) |
| | Constructor.
|
| |
|
virtual | ~UnitAW3641E () |
| | Destructor.
|
| |
| virtual bool | begin () override |
| | Begin the unit (configures EN as OUTPUT and drives EN LOW)
|
| |
| virtual void | update (const bool force=false) override |
| | Drive EN LOW automatically when the flash/torch duration has elapsed.
|
| |
|
| config_t | config () |
| | Gets the configuration.
|
| |
| void | config (const config_t &cfg) |
| | Set the configuration.
|
| |
|
| bool | stop () |
| | Stop any in-flight flash or torch (drives EN LOW immediately)
|
| |
| bool | flash (const aw3641e::Brightness brightness=aw3641e::Brightness::Pct100, const uint16_t duration_ms=aw3641e::FLASH_MAX_DURATION_MS) |
| | Fire a flash with the given brightness for up to FLASH_MAX_DURATION_MS.
|
| |
| bool | torch (const uint16_t duration_ms=aw3641e::TORCH_MAX_DURATION_MS) |
| | Drive the LED continuously in Torch mode for up to TORCH_MAX_DURATION_MS.
|
| |
|
| uint16_t | lastDurationMs () const |
| | Last applied on-duration in milliseconds (clamped value used for flash() or torch())
|
| |
| bool | active () const |
| | Is a flash or torch currently in progress?
|
| |
|
| bool | send_pulse_train (const uint8_t pulse_count) |
| | Send a 1-wire EN pulse train of the given count (1..8 for Brightness Pct100..Pct30)
|
| |
|
|
config_t | _cfg {} |
| |
|
bool | _flash_active {false} |
| |
|
uint32_t | _flash_start_ms {0} |
| |
|
uint16_t | _flash_duration_ms {0} |
| |
1A flash LED driver controlled via EN-pin pulse protocol
- Warning
- UnitFlashLight (U152) has an on-board mode selection switch (silkscreen
S1, SPDT type) that selects between Flash and Torch mode by routing the chip's FLASH pin to +5V or GND. The switch state is NOT wired to the host MCU and cannot be read from software; the driver trusts the value declared in config_t::switch_position.
-
Flash mode (S1 = Flash side): use flash() to fire short metered pulses (<= 220 ms). Calling flash() while S1 is on the Torch side does NOT produce a metered flash; the LED will simply turn on continuously at the chip's Torch current.
-
Torch mode (S1 = Torch side): use torch() for steady ~214 mA illumination (<= 1.3 s). Calling torch() while S1 is on the Flash side will fire the LED briefly (~220 ms) and then dim due to Flash-mode thermal protection.
- Note
- If observed behavior does not match the API, power down the unit and toggle the physical switch on the PCB before retrying. config_t::switch_position must match the physical switch.
◆ UnitAW3641E()
| m5::unit::UnitAW3641E::UnitAW3641E |
( |
const uint8_t | addr = DEFAULT_ADDRESS | ) |
|
|
inlineexplicit |
Constructor.
- Parameters
-
| addr | Placeholder (GPIO unit; address is ignored) |
◆ active()
| bool m5::unit::UnitAW3641E::active |
( |
| ) |
const |
|
inline |
Is a flash or torch currently in progress?
- Returns
- True while update() is still waiting to drive EN LOW
◆ begin()
| bool m5::unit::UnitAW3641E::begin |
( |
| ) |
|
|
overridevirtual |
Begin the unit (configures EN as OUTPUT and drives EN LOW)
- Returns
- True if successful
◆ config() [1/2]
| config_t m5::unit::UnitAW3641E::config |
( |
| ) |
|
|
inline |
Gets the configuration.
- Returns
- Current configuration
◆ config() [2/2]
| void m5::unit::UnitAW3641E::config |
( |
const config_t & | cfg | ) |
|
|
inline |
Set the configuration.
- Parameters
-
| cfg | Configuration to apply |
◆ flash()
Fire a flash with the given brightness for up to FLASH_MAX_DURATION_MS.
- Parameters
-
| brightness | Brightness level (Pct100..Pct30; default Pct100) |
| duration_ms | Flash duration in milliseconds (default 220). Clamped to FLASH_MAX_DURATION_MS (220 ms) with a warning if exceeded. A value of 0 returns false without driving the pin. |
- Returns
- True on success. False if config_t::switch_position is not Flash (logs error), if duration_ms is 0, or if the GPIO write fails.
- Note
- Always auto-off: update() drives EN LOW after duration_ms elapses. If a previous flash/torch is still active(), it is cancelled and the new flash starts after T_OFF (>500 µs).
- Warning
- Requires config_t::switch_position == SwitchPosition::Flash to match the physical S1 switch.
◆ lastDurationMs()
| uint16_t m5::unit::UnitAW3641E::lastDurationMs |
( |
| ) |
const |
|
inline |
Last applied on-duration in milliseconds (clamped value used for flash() or torch())
- Returns
- Duration in milliseconds (after clamping); 0 if no operation has been issued yet
◆ send_pulse_train()
| bool m5::unit::UnitAW3641E::send_pulse_train |
( |
const uint8_t | pulse_count | ) |
|
|
protected |
Send a 1-wire EN pulse train of the given count (1..8 for Brightness Pct100..Pct30)
- Parameters
-
| pulse_count | Number of rising edges (1..8). Final state is EN = HIGH. |
- Returns
- True if the GPIO writes succeeded.
◆ stop()
| bool m5::unit::UnitAW3641E::stop |
( |
| ) |
|
Stop any in-flight flash or torch (drives EN LOW immediately)
- Returns
- True if the GPIO write succeeded; safe to call when idle (no-op success)
◆ torch()
Drive the LED continuously in Torch mode for up to TORCH_MAX_DURATION_MS.
- Parameters
-
| duration_ms | Torch duration in milliseconds (default 1300). Clamped to TORCH_MAX_DURATION_MS (1300 ms) with a warning if exceeded. A value of 0 returns false without driving the pin. |
- Returns
- True on success. False if config_t::switch_position is not Torch (logs error), if duration_ms is 0, or if the GPIO write fails.
- Note
- Always auto-off: update() drives EN LOW after duration_ms elapses. If a previous flash/torch is still active(), it is cancelled and the new torch starts. Torch current is fixed at approximately 214 mA; brightness is not adjustable.
- Warning
- Requires config_t::switch_position == SwitchPosition::Torch to match the physical S1 switch.
◆ update()
| void m5::unit::UnitAW3641E::update |
( |
const bool | force = false | ) |
|
|
overridevirtual |
Drive EN LOW automatically when the flash/torch duration has elapsed.
- Parameters
-
| force | Currently ignored (kept for API symmetry) |