13#ifndef M5_UNIT_FLASHLIGHT_UNIT_AW3641E_HPP
14#define M5_UNIT_FLASHLIGHT_UNIT_AW3641E_HPP
16#include <M5UnitComponent.hpp>
91 return static_cast<uint8_t
>(
static_cast<uint8_t
>(b) + 1u);
116class UnitAW3641E :
public Component {
133 explicit UnitAW3641E(
const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
143 virtual bool begin()
override;
146 virtual void update(
const bool force =
false)
override;
193 const uint16_t duration_ms = aw3641e::FLASH_MAX_DURATION_MS);
214 bool torch(
const uint32_t duration_ms = aw3641e::TORCH_DEFAULT_DURATION_MS);
253 bool send_pulse_train(
const uint8_t pulse_count);
261 bool _continuous{
false};
262 types::elapsed_time_t _start_ms{0};
263 uint32_t _duration_ms{0};
virtual ~UnitAW3641E()
Destructor.
Definition unit_AW3641E.hpp:137
bool active() const
Is a flash or torch currently in progress?
Definition unit_AW3641E.hpp:243
void config(const config_t &cfg)
Set the configuration.
Definition unit_AW3641E.hpp:158
config_t config() const
Gets the configuration.
Definition unit_AW3641E.hpp:152
virtual bool begin() override
Begin the unit (configures EN as OUTPUT and drives EN LOW)
Definition unit_AW3641E.cpp:63
virtual void update(const bool force=false) override
Drive EN LOW automatically when the flash/torch duration has elapsed (not for torchOn())
Definition unit_AW3641E.cpp:89
UnitAW3641E(const uint8_t addr=DEFAULT_ADDRESS)
Constructor.
Definition unit_AW3641E.hpp:133
uint32_t lastDurationMs() const
Last applied on-duration in milliseconds (value used for flash() or torch())
Definition unit_AW3641E.hpp:236
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:111
bool torchOn()
Turn the LED on in Torch mode until stop() is called.
Definition unit_AW3641E.cpp:167
bool stop()
Stop any in-flight flash or torch, including torchOn() (drives EN LOW immediately)
Definition unit_AW3641E.cpp:101
bool torch(const uint32_t duration_ms=aw3641e::TORCH_DEFAULT_DURATION_MS)
Drive the LED in Torch mode for the given duration.
Definition unit_AW3641E.cpp:147
Top level namespace of M5Stack.
Settings for begin.
Definition unit_AW3641E.hpp:124
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:128
Brightness
Flash brightness level (percentage of I_FLASH; Flash mode only)
Definition unit_AW3641E.hpp:48
constexpr uint32_t PULSE_LOW_US
Logic-low pulse width in microseconds (T_LO; datasheet range 0.75-10 µs)
Definition unit_AW3641E.hpp:62
constexpr uint32_t PULSE_HIGH_US
Logic-high pulse width in microseconds (T_HI; datasheet range 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 uint32_t TORCH_DEFAULT_DURATION_MS
Default torch() duration in milliseconds (used when torch() is called with no argument)
Definition unit_AW3641E.hpp:76
constexpr uint8_t to_pulse_count(const Brightness b)
Translate a Brightness level to the AW3641E rising-edge pulse count.
Definition unit_AW3641E.hpp:89
constexpr uint16_t TORCH_MAX_DURATION_MS
Alias for TORCH_DEFAULT_DURATION_MS (torch() does not clamp the duration; this is only the default)
Definition unit_AW3641E.hpp:79
constexpr uint32_t PULSE_OFF_US
EN-low time before a pulse sequence in microseconds (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:70