18#ifndef VORTEX_LED_MANAGER_H_
19#define VORTEX_LED_MANAGER_H_
21#include "handlers/logger/Logger.h"
23#include "core/hf-core-drivers/internal/hf-pincfg/src/hf_functional_pin_config_vortex_v1.hpp"
59 default:
return "Unknown error";
98 default:
return "Unknown";
131 [[nodiscard]]
constexpr uint32_t
ToRgb() const noexcept {
132 return (
static_cast<uint32_t
>(
red) << 16) |
133 (
static_cast<uint32_t
>(
green) << 8) |
134 static_cast<uint32_t
>(
blue);
144 static_cast<uint8_t
>((rgb >> 16) & 0xFF),
145 static_cast<uint8_t
>((rgb >> 8) & 0xFF),
146 static_cast<uint8_t
>(rgb & 0xFF));
226 [[nodiscard]]
bool Shutdown() noexcept;
266 [[nodiscard]]
LedError SetColor(uint32_t rgb, uint32_t led_index = 0) noexcept;
387 [[nodiscard]]
static uint32_t
ColorWheel(uint8_t position)
noexcept;
409 if (percent > 100) percent = 100;
410 return static_cast<uint8_t
>((
static_cast<uint32_t
>(percent) *
max_brightness_) / 100);
415 return static_cast<uint8_t
>((
static_cast<uint32_t
>(raw) * 100) /
max_brightness_);
419 const auto* mapping = GetGpioMapping(HfFunctionalGpioPin::WS2812_LED_DAT);
420 if (mapping && mapping->chip_type ==
static_cast<uint8_t
>(HfGpioChipType::ESP32_INTERNAL)) {
421 return static_cast<int>(mapping->physical_pin);
427 [[nodiscard]]
bool ShowPixel(uint32_t rgb, uint8_t brightness)
noexcept;
LedError
Error codes returned by LedManager operations.
Definition LedManager.h:33
@ 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:68
@ 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:472
constexpr const char * LedAnimationToString(LedAnimation animation) noexcept
Convert a LedAnimation to a human-readable C-string.
Definition LedManager.h:86
constexpr const char * LedErrorToString(LedError error) noexcept
Convert a LedError to a human-readable C-string.
Definition LedManager.h:49
Singleton that drives the on-board WS2812 LED via ESP-IDF RMT.
Definition LedManager.h:199
LedError IndicateBoot() noexcept
Show the boot indicator (blue blink).
Definition LedManager.h:368
LedError UpdateAnimation() noexcept
Advance the animation by one tick. Call periodically (~50 ms).
Definition LedManager.cpp:200
LedError IndicateWarning() noexcept
Show the warning indicator (yellow blink).
Definition LedManager.h:372
LedError SetBrightness(uint8_t brightness) noexcept
Alias for SetBrightnessRaw().
Definition LedManager.h:300
std::atomic< uint32_t > successful_operations_
Definition LedManager.h:456
LedError StopAnimation() noexcept
Stop the current animation and turn the LED off.
Definition LedManager.cpp:189
LedError UpdateAnimationStep() noexcept
Definition LedManager.cpp:279
LedColor current_color_
Definition LedManager.h:448
static constexpr uint32_t BLINK_SPEED
Definition LedManager.h:437
uint16_t animation_step_
Definition LedManager.h:451
std::atomic< LedError > last_error_
Definition LedManager.h:459
static constexpr uint32_t kNumLeds
Definition LedManager.h:433
LedError GetSystemDiagnostics(LedSystemDiagnostics &diagnostics) const noexcept
Populate a diagnostics snapshot.
Definition LedManager.cpp:55
bool Shutdown() noexcept
Turn off the LED and release driver resources.
Definition LedManager.cpp:40
bool ShowPixel(uint32_t rgb, uint8_t brightness) noexcept
Latch one colour at a brightness onto the LED through the board binding.
Definition LedManager.cpp:275
static int GetLedGpioPin() noexcept
Definition LedManager.h:418
void DumpStatistics() const noexcept
Log current LED state and statistics to the console.
Definition LedManager.cpp:231
static constexpr uint32_t BREATH_SPEED
Definition LedManager.h:436
LedError GetLastError() const noexcept
Get the most recent error code from any LED operation.
Definition LedManager.h:246
bool Deinitialize() noexcept
Alias for Shutdown().
Definition LedManager.h:229
int GetCurrentGpioPin() const noexcept
GPIO pin the LED strip is attached to.
Definition LedManager.h:393
LedError GetCurrentBrightnessPercent(uint8_t &brightness_percent) const noexcept
Read current brightness as a percentage of max.
Definition LedManager.h:314
LedError GetCurrentColor(LedColor &color) const noexcept
Read the currently displayed colour.
Definition LedManager.cpp:118
LedManager(LedManager &&)=delete
bool IsAnimationActive() const noexcept
Check whether an animation is currently running.
Definition LedManager.h:348
LedError GetCurrentBrightnessRaw(uint8_t &brightness_raw) const noexcept
Read current brightness as a raw 0–255 value.
Definition LedManager.h:324
bool IsInitialized() const noexcept
Check whether the LED driver is initialised.
Definition LedManager.h:233
void UpdateLastError(LedError error_code) noexcept
Definition LedManager.cpp:321
static uint32_t ColorWheel(uint8_t position) noexcept
Map a 0–255 wheel position to a rainbow RGB colour.
Definition LedManager.cpp:218
std::atomic< bool > is_initialized_
Definition LedManager.h:443
LedError StartAnimation(LedAnimation animation, const LedColor &color=LedColors::WHITE) noexcept
Start a named animation with an optional base colour.
Definition LedManager.cpp:160
LedError TurnOff() noexcept
Turn the LED off (set colour to black).
Definition LedManager.cpp:100
LedAnimation current_animation_
Definition LedManager.h:447
uint8_t PercentToRaw(uint8_t percent) const noexcept
Definition LedManager.h:408
LedError IndicateCalibration() noexcept
Show the calibration indicator (cyan breathe).
Definition LedManager.h:376
uint32_t GetLedCount() const noexcept
Number of LEDs in the strip (always 1 on Vortex V1).
Definition LedManager.h:396
std::atomic< uint32_t > total_operations_
Definition LedManager.h:455
LedManager & operator=(const LedManager &)=delete
std::atomic< uint32_t > animation_cycles_
Definition LedManager.h:458
LedError SetBrightnessPercent(uint8_t brightness_percent) noexcept
Set brightness as a percentage of max.
Definition LedManager.cpp:128
std::atomic< uint32_t > failed_operations_
Definition LedManager.h:457
int8_t animation_direction_
Definition LedManager.h:452
RtosMutex mutex_
Definition LedManager.h:444
uint8_t current_brightness_
Definition LedManager.h:449
LedManager() noexcept=default
static constexpr uint8_t DEFAULT_MAX_BRIGHTNESS
Definition LedManager.h:434
LedError SetBrightnessRaw(uint8_t brightness_raw) noexcept
Set brightness as a raw 0–255 value.
Definition LedManager.cpp:139
uint8_t max_brightness_
Definition LedManager.h:450
LedManager(const LedManager &)=delete
uint64_t system_start_time_
Definition LedManager.h:460
uint64_t last_animation_update_
Definition LedManager.h:453
LedError SetMaxBrightness(uint8_t max_brightness) noexcept
Set the upper ceiling for brightness.
Definition LedManager.cpp:149
static constexpr uint32_t ANIMATION_UPDATE_INTERVAL
Definition LedManager.h:435
bool Initialize() noexcept
Definition LedManager.cpp:248
uint64_t GetSystemUptimeMs() const noexcept
Definition LedManager.cpp:325
LedManager & operator=(LedManager &&)=delete
void UpdateStatistics(bool success) noexcept
Definition LedManager.cpp:315
int current_led_gpio_
Definition LedManager.h:461
LedError IndicateError() noexcept
Show the error indicator (red fast-blink).
Definition LedManager.h:374
uint8_t RawToPercent(uint8_t raw) const noexcept
Definition LedManager.h:413
LedError SetColor(const LedColor &color, uint32_t led_index=0) noexcept
Set LED colour from an LedColor struct.
Definition LedManager.cpp:74
static LedManager & GetInstance() noexcept
Access the singleton instance (Meyers singleton, thread-safe).
Definition LedManager.cpp:24
bool EnsureInitialized() noexcept
Initialise the WS2812 LED strip (idempotent).
Definition LedManager.cpp:33
LedError SetStatus(LedAnimation animation) noexcept
Set a status animation by enum (generic variant).
Definition LedManager.h:365
LedError IndicateReady() noexcept
Show the ready indicator (solid green).
Definition LedManager.h:370
Predefined named colour constants.
Definition LedManager.h:151
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.
Simple RGB colour triplet.
Definition LedManager.h:111
uint8_t blue
Blue channel [0–255].
Definition LedManager.h:114
uint8_t green
Green channel [0–255].
Definition LedManager.h:113
constexpr uint32_t ToRgb() const noexcept
Pack into a 24-bit 0xRRGGBB integer.
Definition LedManager.h:131
static constexpr LedColor FromRgb(uint32_t rgb) noexcept
Unpack from a 24-bit 0xRRGGBB integer.
Definition LedManager.h:142
constexpr LedColor(uint8_t r, uint8_t g, uint8_t b) noexcept
Construct from individual R/G/B components.
Definition LedManager.h:125
uint8_t red
Red channel [0–255].
Definition LedManager.h:112
constexpr LedColor() noexcept
Default-construct black (0, 0, 0).
Definition LedManager.h:117
Snapshot of LED subsystem health and counters.
Definition LedManager.h:169
bool animation_active
true if an animation is currently running.
Definition LedManager.h:172
uint32_t total_operations
Lifetime count of all API calls.
Definition LedManager.h:174
uint32_t successful_operations
Calls that returned SUCCESS.
Definition LedManager.h:175
uint32_t current_color
Current colour as packed 0xRRGGBB.
Definition LedManager.h:179
LedAnimation current_animation
Currently active animation mode.
Definition LedManager.h:173
uint32_t current_brightness
Current brightness value [0–255].
Definition LedManager.h:178
bool led_initialized
true after WS2812 strip init succeeds.
Definition LedManager.h:171
bool system_healthy
true when driver initialised and operational.
Definition LedManager.h:170
uint32_t failed_operations
Calls that returned an error.
Definition LedManager.h:176
uint32_t animation_cycles
Number of animation update ticks processed.
Definition LedManager.h:177