M5Unit-FLASHLIGHT 0.1.0 git rev:ba3d197
Loading...
Searching...
No Matches
m5::unit::UnitAW3641E Class Reference

1A flash LED driver controlled via EN-pin pulse protocol More...

#include <unit_AW3641E.hpp>

Inheritance diagram for m5::unit::UnitAW3641E:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 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 (not for torchOn())
 
Settings for begin
config_t config () const
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Operation control
bool stop ()
 Stop any in-flight flash or torch, including torchOn() (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 uint32_t duration_ms=aw3641e::TORCH_DEFAULT_DURATION_MS)
 Drive the LED in Torch mode for the given duration.
 
bool torchOn ()
 Turn the LED on in Torch mode until stop() is called.
 
Status accessors
uint32_t lastDurationMs () const
 Last applied on-duration in milliseconds (value used for flash() or torch())
 
bool active () const
 Is a flash or torch currently in progress?
 

Protected Member Functions

bool send_pulse_train (const uint8_t pulse_count)
 
bool start_torch ()
 

Protected Attributes

config_t _cfg {}
 
bool _active {false}
 
bool _continuous {false}
 
types::elapsed_time_t _start_ms {0}
 
uint32_t _duration_ms {0}
 

Detailed Description

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 for a given time, or torchOn() to keep it on until stop(). Calling torch() or torchOn() while S1 is on the Flash side fires a 100% flash, and after the Flash-mode timeout (T_FLASH 180-310 ms) the LED stays on at a lower current until EN goes LOW.
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.

Constructor & Destructor Documentation

◆ UnitAW3641E()

m5::unit::UnitAW3641E::UnitAW3641E ( const uint8_t addr = DEFAULT_ADDRESS)
inlineexplicit

Constructor.

Parameters
addrPlaceholder (GPIO unit; address is ignored)

Member Function Documentation

◆ active()

bool m5::unit::UnitAW3641E::active ( ) const
inline

Is a flash or torch currently in progress?

Returns
True while EN is driven HIGH (until update() drives it LOW after the duration, or stop() is called)

◆ 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 ( ) const
inline

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

void m5::unit::UnitAW3641E::config ( const config_t & cfg)
inline

Set the configuration.

Parameters
cfgConfiguration to apply

◆ flash()

bool m5::unit::UnitAW3641E::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.

Parameters
brightnessBrightness level (Pct100..Pct30; default Pct100)
duration_msFlash 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
Auto-off depends on periodic Units.update() calls — update() drives EN LOW after duration_ms elapses. The AW3641E ends the flash at its hardware timeout (T_FLASH typ 220 ms, 180-310 ms), but the LED does NOT turn off: while EN stays HIGH it keeps lighting at a lower current. If update() is not called (blocked task, long delay(), etc.), the LED stays on until stop() is called or power is removed. With duration_ms of 180-220 ms the flash may end before update() drives EN LOW. 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()

uint32_t m5::unit::UnitAW3641E::lastDurationMs ( ) const
inline

Last applied on-duration in milliseconds (value used for flash() or torch())

Returns
Duration in milliseconds (after clamping for flash()); 0 if no operation has been issued yet or after torchOn()

◆ stop()

bool m5::unit::UnitAW3641E::stop ( )

Stop any in-flight flash or torch, including torchOn() (drives EN LOW immediately)

Returns
True if the GPIO write succeeded; safe to call when idle (no-op success)

◆ torch()

bool m5::unit::UnitAW3641E::torch ( const uint32_t duration_ms = aw3641e::TORCH_DEFAULT_DURATION_MS)

Drive the LED in Torch mode for the given duration.

Parameters
duration_msTorch duration in milliseconds (default TORCH_DEFAULT_DURATION_MS = 1300). 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
Auto-off is COOPERATIVE — update() drives EN LOW after duration_ms only when the caller runs Units.update() (typically once per loop()). Torch mode has NO hardware timeout: if update() stops being called (blocked task, long delay(), etc.), the LED stays on continuously at ~214 mA until stop() is called or power is removed. Call stop() explicitly for hard cutoff. 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.

◆ torchOn()

bool m5::unit::UnitAW3641E::torchOn ( )

Turn the LED on in Torch mode until stop() is called.

Returns
True on success. False if config_t::switch_position is not Torch (logs error), or if the GPIO write fails.
Note
The LED stays on at ~214 mA; update() does not turn it off. Call stop() to turn it off. Calling torchOn() while the LED is already on keeps it on without a break and returns true; for a timed torch() in progress, its timed turn-off is cancelled. Long continuous operation heats the LED; check the temperature for your use case.
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 (not for torchOn())

Parameters
forceIgnored