19#ifndef FLUX_LED_MANAGER_H_
20#define FLUX_LED_MANAGER_H_
22#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/HardwareTypes.h"
23#include "handlers/logger/Logger.h"
26#include "core/hf-core-drivers/internal/hf-pincfg/src/hf_functional_pin_config_flux_v1.hpp"
62 default:
return "Unknown error";
101 default:
return "Unknown";
134 [[nodiscard]]
constexpr uint32_t
ToRgb() const noexcept {
135 return (
static_cast<uint32_t
>(
red) << 16) |
136 (
static_cast<uint32_t
>(
green) << 8) |
137 static_cast<uint32_t
>(
blue);
147 static_cast<uint8_t
>((rgb >> 16) & 0xFF),
148 static_cast<uint8_t
>((rgb >> 8) & 0xFF),
149 static_cast<uint8_t
>(rgb & 0xFF));
229 [[nodiscard]]
bool Shutdown() noexcept;
277 [[nodiscard]]
LedError SetColor(uint32_t rgb, uint32_t led_index = 0) noexcept;
398 [[nodiscard]]
static uint32_t
ColorWheel(uint8_t position)
noexcept;
420 if (percent > 100) percent = 100;
421 return static_cast<uint8_t
>((
static_cast<uint32_t
>(percent) *
max_brightness_) / 100);
426 return static_cast<uint8_t
>((
static_cast<uint32_t
>(raw) * 100) /
max_brightness_);
430 const auto* mapping = GetGpioMapping(HfFunctionalGpioPin::WS2812_LED_DAT);
431 if (mapping && mapping->chip_type ==
static_cast<uint8_t
>(HfGpioChipType::ESP32_INTERNAL)) {
432 return static_cast<hf_pin_num_t
>(mapping->physical_pin);
LedError
Error codes returned by LedManager operations.
Definition LedManager.h:36
@ NOT_INITIALIZED
Manager has not been initialized yet.
@ ANIMATION_FAILED
Animation start/update failed.
@ INVALID_COLOR
Colour value rejected.
@ HARDWARE_ERROR
RMT peripheral or strip communication error.
@ INVALID_BRIGHTNESS
Brightness value out of [0, max] range.
@ SUCCESS
Operation completed successfully.
@ INITIALIZATION_FAILED
WS2812 strip/RMT setup failed.
@ INVALID_PARAMETER
Argument out of valid range.
LedAnimation
Available LED animation modes.
Definition LedManager.h:71
@ STATUS_WARN
Warning indicator (yellow blink).
@ BREATH
Smooth brightness ramp up/down.
@ OFF
LED turned off (no animation).
@ STATUS_BOOT
Boot-up indicator (blue blink).
@ STATUS_ERROR
Error indicator (red fast-blink).
@ STATUS_OK
System-ready indicator (solid green).
@ SOLID
Constant colour, no animation.
@ BLINK
On/off blink at BLINK_SPEED interval.
@ STATUS_CALIBRATE
Calibration indicator (cyan breathe).
@ RAINBOW
Continuous colour-wheel cycle.
LedManager & GetLedManager() noexcept
Convenience accessor — equivalent to LedManager::GetInstance().
Definition LedManager.h:483
constexpr const char * LedAnimationToString(LedAnimation animation) noexcept
Convert a LedAnimation to a human-readable C-string.
Definition LedManager.h:89
constexpr const char * LedErrorToString(LedError error) noexcept
Convert a LedError to a human-readable C-string.
Definition LedManager.h:52
Singleton that drives the on-board WS2812 status LED.
Definition LedManager.h:202
LedError IndicateBoot() noexcept
Show the boot indicator (blue blink).
Definition LedManager.h:379
bool strip_ready_
The binding's strip was started by Initialize()
Definition LedManager.h:455
LedError UpdateAnimation() noexcept
Advance the animation by one tick. Call periodically (~50 ms).
Definition LedManager.cpp:233
LedError IndicateWarning() noexcept
Show the warning indicator (yellow blink).
Definition LedManager.h:383
LedError SetBrightness(uint8_t brightness) noexcept
Alias for SetBrightnessRaw().
Definition LedManager.h:311
std::atomic< uint32_t > successful_operations_
Definition LedManager.h:466
LedError StopAnimation() noexcept
Stop the current animation and turn the LED off.
Definition LedManager.cpp:220
LedError UpdateAnimationStep() noexcept
Definition LedManager.cpp:309
LedColor current_color_
Definition LedManager.h:458
static constexpr uint32_t BLINK_SPEED
Definition LedManager.h:446
uint16_t animation_step_
Definition LedManager.h:461
std::atomic< LedError > last_error_
Definition LedManager.h:469
static constexpr uint32_t kNumLeds
Definition LedManager.h:442
LedError GetSystemDiagnostics(LedSystemDiagnostics &diagnostics) const noexcept
Populate a diagnostics snapshot.
Definition LedManager.cpp:65
bool Shutdown() noexcept
Turn off the LED and release driver resources.
Definition LedManager.cpp:42
void DumpStatistics() const noexcept
Log current LED state and statistics to the console.
Definition LedManager.cpp:264
static constexpr uint32_t BREATH_SPEED
Definition LedManager.h:445
LedError GetLastError() const noexcept
Get the most recent error code from any LED operation.
Definition LedManager.h:249
bool Deinitialize() noexcept
Alias for Shutdown().
Definition LedManager.h:232
LedError GetCurrentBrightnessPercent(uint8_t &brightness_percent) const noexcept
Read current brightness as a percentage of max.
Definition LedManager.h:325
LedError GetCurrentColor(LedColor &color) const noexcept
Read the currently displayed colour.
Definition LedManager.cpp:144
LedManager(LedManager &&)=delete
hf_pin_num_t GetCurrentGpioPin() const noexcept
GPIO pin the LED strip is attached to.
Definition LedManager.h:404
bool IsAnimationActive() const noexcept
Check whether an animation is currently running.
Definition LedManager.h:359
LedError GetCurrentBrightnessRaw(uint8_t &brightness_raw) const noexcept
Read current brightness as a raw 0–255 value.
Definition LedManager.h:335
bool IsInitialized() const noexcept
Check whether the LED driver is initialised.
Definition LedManager.h:236
void UpdateLastError(LedError error_code) noexcept
Definition LedManager.cpp:350
static uint32_t ColorWheel(uint8_t position) noexcept
Map a 0–255 wheel position to a rainbow RGB colour.
Definition LedManager.cpp:251
std::atomic< bool > is_initialized_
Definition LedManager.h:452
LedError StartAnimation(LedAnimation animation, const LedColor &color=LedColors::WHITE) noexcept
Start a named animation with an optional base colour.
Definition LedManager.cpp:189
LedError TurnOff() noexcept
Turn the LED off (set colour to black).
Definition LedManager.cpp:118
std::atomic< flux::hal::ManagerError > manager_error_
Definition LedManager.h:470
LedAnimation current_animation_
Definition LedManager.h:457
uint8_t PercentToRaw(uint8_t percent) const noexcept
Definition LedManager.h:419
LedError IndicateCalibration() noexcept
Show the calibration indicator (cyan breathe).
Definition LedManager.h:387
uint32_t GetLedCount() const noexcept
Number of LEDs in the strip (always 1 on Flux V1).
Definition LedManager.h:407
std::atomic< uint32_t > total_operations_
Definition LedManager.h:465
static constexpr hf_pin_num_t kFallbackLedPin
Board default if the pin map lacks the LED.
Definition LedManager.h:441
LedManager & operator=(const LedManager &)=delete
std::atomic< uint32_t > animation_cycles_
Definition LedManager.h:468
LedError SetBrightnessPercent(uint8_t brightness_percent) noexcept
Set brightness as a percentage of max.
Definition LedManager.cpp:154
std::atomic< uint32_t > failed_operations_
Definition LedManager.h:467
int8_t animation_direction_
Definition LedManager.h:462
RtosMutex mutex_
Definition LedManager.h:453
uint8_t current_brightness_
Definition LedManager.h:459
LedManager() noexcept=default
static constexpr uint8_t DEFAULT_MAX_BRIGHTNESS
Definition LedManager.h:443
LedError SetBrightnessRaw(uint8_t brightness_raw) noexcept
Set brightness as a raw 0–255 value.
Definition LedManager.cpp:167
uint8_t max_brightness_
Definition LedManager.h:460
flux::hal::ManagerError GetManagerError() const noexcept
Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
Definition LedManager.h:255
LedManager(const LedManager &)=delete
uint64_t system_start_time_
Definition LedManager.h:471
uint64_t last_animation_update_
Definition LedManager.h:463
LedError SetMaxBrightness(uint8_t max_brightness) noexcept
Set the upper ceiling for brightness.
Definition LedManager.cpp:178
static constexpr uint32_t ANIMATION_UPDATE_INTERVAL
Definition LedManager.h:444
hf_pin_num_t current_led_gpio_
Definition LedManager.h:472
static hf_pin_num_t GetLedGpioPin() noexcept
Definition LedManager.h:429
bool Initialize() noexcept
Definition LedManager.cpp:281
uint64_t GetSystemUptimeMs() const noexcept
Definition LedManager.cpp:354
LedManager & operator=(LedManager &&)=delete
void UpdateStatistics(bool success) noexcept
Definition LedManager.cpp:344
LedError IndicateError() noexcept
Show the error indicator (red fast-blink).
Definition LedManager.h:385
uint8_t RawToPercent(uint8_t raw) const noexcept
Definition LedManager.h:424
LedError SetColor(const LedColor &color, uint32_t led_index=0) noexcept
Set LED colour from an LedColor struct.
Definition LedManager.cpp:84
static LedManager & GetInstance() noexcept
Access the singleton instance (Meyers singleton, thread-safe).
Definition LedManager.cpp:26
bool EnsureInitialized() noexcept
Initialise the WS2812 LED strip (idempotent).
Definition LedManager.cpp:35
LedError SetStatus(LedAnimation animation) noexcept
Set a status animation by enum (generic variant).
Definition LedManager.h:376
LedError IndicateReady() noexcept
Show the ready indicator (solid green).
Definition LedManager.h:381
Shared HAL types for Flux V1: the manager error catalog and the facade result.
Predefined named colour constants.
Definition LedManager.h:154
static constexpr LedColor GREEN(0, 255, 0)
Pure green.
static constexpr LedColor WHITE(255, 255, 255)
Full white.
static constexpr LedColor YELLOW(255, 255, 0)
Yellow.
static constexpr LedColor MAGENTA(255, 0, 255)
Magenta.
static constexpr LedColor PURPLE(128, 0, 128)
Purple.
static constexpr LedColor ORANGE(255, 165, 0)
Orange.
static constexpr LedColor BLACK(0, 0, 0)
Off / black.
static constexpr LedColor BLUE(0, 0, 255)
Pure blue.
static constexpr LedColor RED(255, 0, 0)
Pure red.
static constexpr LedColor CYAN(0, 255, 255)
Cyan.
ManagerError
Lifecycle / bind failure catalog shared by every manager (GetManagerError()).
Definition flux_hal_types.hpp:37
@ NotInitialized
Manager not initialised (or shut down)
Simple RGB colour triplet.
Definition LedManager.h:114
uint8_t blue
Blue channel [0–255].
Definition LedManager.h:117
uint8_t green
Green channel [0–255].
Definition LedManager.h:116
constexpr uint32_t ToRgb() const noexcept
Pack into a 24-bit 0xRRGGBB integer.
Definition LedManager.h:134
static constexpr LedColor FromRgb(uint32_t rgb) noexcept
Unpack from a 24-bit 0xRRGGBB integer.
Definition LedManager.h:145
constexpr LedColor(uint8_t r, uint8_t g, uint8_t b) noexcept
Construct from individual R/G/B components.
Definition LedManager.h:128
uint8_t red
Red channel [0–255].
Definition LedManager.h:115
constexpr LedColor() noexcept
Default-construct black (0, 0, 0).
Definition LedManager.h:120
Snapshot of LED subsystem health and counters.
Definition LedManager.h:172
bool animation_active
true if an animation is currently running.
Definition LedManager.h:175
uint32_t total_operations
Lifetime count of all API calls.
Definition LedManager.h:177
uint32_t successful_operations
Calls that returned SUCCESS.
Definition LedManager.h:178
uint32_t current_color
Current colour as packed 0xRRGGBB.
Definition LedManager.h:182
LedAnimation current_animation
Currently active animation mode.
Definition LedManager.h:176
uint32_t current_brightness
Current brightness value [0–255].
Definition LedManager.h:181
bool led_initialized
true after WS2812 strip init succeeds.
Definition LedManager.h:174
bool system_healthy
true when driver initialised and operational.
Definition LedManager.h:173
uint32_t failed_operations
Calls that returned an error.
Definition LedManager.h:179
uint32_t animation_cycles
Number of animation update ticks processed.
Definition LedManager.h:180