M5Unit-FLASHLIGHT 0.0.1 git rev:9a14869
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.
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Operation control
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.
 
Status accessors
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?
 

Protected Member Functions

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)
 

Protected Attributes

config_t _cfg {}
 
bool _flash_active {false}
 
uint32_t _flash_start_ms {0}
 
uint16_t _flash_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 (<= 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.

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 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
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
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_countNumber 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()

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

Parameters
duration_msTorch 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
forceCurrently ignored (kept for API symmetry)