13#ifndef M5_UNIT_FLASHLIGHT_UNIT_AW3641E_HPP
14#define M5_UNIT_FLASHLIGHT_UNIT_AW3641E_HPP
16#include <M5UnitComponent.hpp>
87 return static_cast<uint8_t
>(
static_cast<uint8_t
>(b) + 1u);
111class UnitAW3641E :
public Component {
128 explicit UnitAW3641E(
const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
138 virtual bool begin()
override;
141 virtual void update(
const bool force =
false)
override;
183 const uint16_t duration_ms = aw3641e::FLASH_MAX_DURATION_MS);
201 bool torch(
const uint16_t duration_ms = aw3641e::TORCH_MAX_DURATION_MS);
210 return _flash_duration_ms;
216 return _flash_active;
229 bool _flash_active{
false};
230 uint32_t _flash_start_ms{0};
231 uint16_t _flash_duration_ms{0};
virtual ~UnitAW3641E()
Destructor.
Definition unit_AW3641E.hpp:132
bool active() const
Is a flash or torch currently in progress?
Definition unit_AW3641E.hpp:214
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)
Definition unit_AW3641E.cpp:173
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.
Definition unit_AW3641E.cpp:138
void config(const config_t &cfg)
Set the configuration.
Definition unit_AW3641E.hpp:153
virtual bool begin() override
Begin the unit (configures EN as OUTPUT and drives EN LOW)
Definition unit_AW3641E.cpp:56
virtual void update(const bool force=false) override
Drive EN LOW automatically when the flash/torch duration has elapsed.
Definition unit_AW3641E.cpp:81
UnitAW3641E(const uint8_t addr=DEFAULT_ADDRESS)
Constructor.
Definition unit_AW3641E.hpp:128
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.
Definition unit_AW3641E.cpp:103
bool stop()
Stop any in-flight flash or torch (drives EN LOW immediately)
Definition unit_AW3641E.cpp:94
config_t config()
Gets the configuration.
Definition unit_AW3641E.hpp:147
uint16_t lastDurationMs() const
Last applied on-duration in milliseconds (clamped value used for flash() or torch())
Definition unit_AW3641E.hpp:208
Top level namespace of M5Stack.
Settings for begin.
Definition unit_AW3641E.hpp:119
aw3641e::SwitchPosition switch_position
Declaration of the physical S1 switch position. The driver cannot detect S1 at runtime; it trusts thi...
Definition unit_AW3641E.hpp:123
Brightness
Flash brightness level (percentage of I_FLASH; Flash mode only)
Definition unit_AW3641E.hpp:48
constexpr uint32_t PULSE_LOW_US
Minimum logic-low pulse width in microseconds (T_LO; datasheet 0.75-10 µs)
Definition unit_AW3641E.hpp:62
constexpr uint32_t PULSE_HIGH_US
Minimum logic-high pulse width in microseconds (T_HI; datasheet 0.75-10 µs)
Definition unit_AW3641E.hpp:60
SwitchPosition
Position of the on-board mode selection switch (silkscreen S1, SPDT type)
Definition unit_AW3641E.hpp:36
@ Torch
S1 = Torch side. FLASH pin = GND. Use torch() to drive continuous illumination.
@ Flash
S1 = Flash side. FLASH pin = +5V. Use flash() to fire pulse-controlled flashes.
constexpr uint8_t to_pulse_count(const Brightness b)
Translate a Brightness level to the AW3641E rising-edge pulse count.
Definition unit_AW3641E.hpp:85
constexpr uint16_t TORCH_MAX_DURATION_MS
Maximum duration for a single torch() call in milliseconds.
Definition unit_AW3641E.hpp:75
constexpr uint32_t PULSE_OFF_US
Minimum EN-low delay required before a pulse sequence (T_OFF; datasheet > 500 µs)
Definition unit_AW3641E.hpp:64
constexpr uint16_t FLASH_MAX_DURATION_MS
Maximum duration for a single flash() call in milliseconds.
Definition unit_AW3641E.hpp:69