HardFOC Vortex V1 HAL
Unified HAL API for the HardFOC Vortex motor-control platform (ESP32-C6, TMC9660)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
LedManager Class Reference

Singleton that drives the on-board WS2812 LED via ESP-IDF RMT. More...

#include <LedManager.h>

Collaboration diagram for LedManager:
[legend]

Public Member Functions

 LedManager (const LedManager &)=delete
 
LedManager & operator= (const LedManager &)=delete
 
 LedManager (LedManager &&)=delete
 
LedManager & operator= (LedManager &&)=delete
 
bool EnsureInitialized () noexcept
 Initialise the WS2812 LED strip (idempotent).
 
bool Shutdown () noexcept
 Turn off the LED and release driver resources.
 
bool Deinitialize () noexcept
 Alias for Shutdown().
 
bool IsInitialized () const noexcept
 Check whether the LED driver is initialised.
 
LedError GetSystemDiagnostics (LedSystemDiagnostics &diagnostics) const noexcept
 Populate a diagnostics snapshot.
 
LedError GetLastError () const noexcept
 Get the most recent error code from any LED operation.
 
LedError SetColor (const LedColor &color, uint32_t led_index=0) noexcept
 Set LED colour from an LedColor struct.
 
LedError SetColor (uint32_t rgb, uint32_t led_index=0) noexcept
 Set LED colour from a packed 0xRRGGBB integer.
 
LedError TurnOff () noexcept
 Turn the LED off (set colour to black).
 
LedError GetCurrentColor (LedColor &color) const noexcept
 Read the currently displayed colour.
 
LedError SetBrightnessPercent (uint8_t brightness_percent) noexcept
 Set brightness as a percentage of max.
 
LedError SetBrightnessRaw (uint8_t brightness_raw) noexcept
 Set brightness as a raw 0–255 value.
 
LedError SetBrightness (uint8_t brightness) noexcept
 Alias for SetBrightnessRaw().
 
LedError SetMaxBrightness (uint8_t max_brightness) noexcept
 Set the upper ceiling for brightness.
 
LedError GetCurrentBrightnessPercent (uint8_t &brightness_percent) const noexcept
 Read current brightness as a percentage of max.
 
LedError GetCurrentBrightnessRaw (uint8_t &brightness_raw) const noexcept
 Read current brightness as a raw 0–255 value.
 
LedError StartAnimation (LedAnimation animation, const LedColor &color=LedColors::WHITE) noexcept
 Start a named animation with an optional base colour.
 
LedError StopAnimation () noexcept
 Stop the current animation and turn the LED off.
 
bool IsAnimationActive () const noexcept
 Check whether an animation is currently running.
 
LedError UpdateAnimation () noexcept
 Advance the animation by one tick. Call periodically (~50 ms).
 
LedError SetStatus (LedAnimation animation) noexcept
 Set a status animation by enum (generic variant).
 
LedError IndicateBoot () noexcept
 Show the boot indicator (blue blink).
 
LedError IndicateReady () noexcept
 Show the ready indicator (solid green).
 
LedError IndicateWarning () noexcept
 Show the warning indicator (yellow blink).
 
LedError IndicateError () noexcept
 Show the error indicator (red fast-blink).
 
LedError IndicateCalibration () noexcept
 Show the calibration indicator (cyan breathe).
 
void DumpStatistics () const noexcept
 Log current LED state and statistics to the console.
 
int GetCurrentGpioPin () const noexcept
 GPIO pin the LED strip is attached to.
 
uint32_t GetLedCount () const noexcept
 Number of LEDs in the strip (always 1 on Vortex V1).
 

Static Public Member Functions

static LedManager & GetInstance () noexcept
 Access the singleton instance (Meyers singleton, thread-safe).
 
static uint32_t ColorWheel (uint8_t position) noexcept
 Map a 0–255 wheel position to a rainbow RGB colour.
 

Private Member Functions

 LedManager () noexcept=default
 
 ~LedManager ()=default
 
bool Initialize () noexcept
 
LedError UpdateAnimationStep () noexcept
 
void UpdateStatistics (bool success) noexcept
 
void UpdateLastError (LedError error_code) noexcept
 
uint64_t GetSystemUptimeMs () const noexcept
 
uint8_t PercentToRaw (uint8_t percent) const noexcept
 
uint8_t RawToPercent (uint8_t raw) const noexcept
 
bool ShowPixel (uint32_t rgb, uint8_t brightness) noexcept
 Latch one colour at a brightness onto the LED through the board binding.
 

Static Private Member Functions

static int GetLedGpioPin () noexcept
 

Private Attributes

std::atomic< bool > is_initialized_ {false}
 
RtosMutex mutex_
 
LedAnimation current_animation_ {LedAnimation::OFF}
 
LedColor current_color_ {}
 
uint8_t current_brightness_ {255}
 
uint8_t max_brightness_ {DEFAULT_MAX_BRIGHTNESS}
 
uint16_t animation_step_ {0}
 
int8_t animation_direction_ {1}
 
uint64_t last_animation_update_ {0}
 
std::atomic< uint32_t > total_operations_ {0}
 
std::atomic< uint32_t > successful_operations_ {0}
 
std::atomic< uint32_t > failed_operations_ {0}
 
std::atomic< uint32_t > animation_cycles_ {0}
 
std::atomic< LedError > last_error_ {LedError::SUCCESS}
 
uint64_t system_start_time_ {0}
 
int current_led_gpio_ {-1}
 

Static Private Attributes

static constexpr uint32_t kNumLeds = 1
 
static constexpr uint8_t DEFAULT_MAX_BRIGHTNESS = 255
 
static constexpr uint32_t ANIMATION_UPDATE_INTERVAL = 50
 
static constexpr uint32_t BREATH_SPEED = 5
 
static constexpr uint32_t BLINK_SPEED = 500
 

Detailed Description

Singleton that drives the on-board WS2812 LED via ESP-IDF RMT.

Controls a single WS2812 NeoPixel LED on GPIO3. Provides:

Note
Call UpdateAnimation() periodically (e.g. every 50 ms from a task) to drive multi-frame animations. Solid colours require no update.

Constructor & Destructor Documentation

◆ LedManager() [1/3]

LedManager::LedManager ( const LedManager &  )
delete

◆ LedManager() [2/3]

LedManager::LedManager ( LedManager &&  )
delete

◆ LedManager() [3/3]

LedManager::LedManager ( )
privatedefaultnoexcept

◆ ~LedManager()

LedManager::~LedManager ( )
privatedefault

Member Function Documentation

◆ ColorWheel()

uint32_t LedManager::ColorWheel ( uint8_t  position)
staticnoexcept

Map a 0–255 wheel position to a rainbow RGB colour.

Parameters
positionWheel position [0–255].
Returns
Packed 0xRRGGBB colour.
Here is the caller graph for this function:

◆ Deinitialize()

bool LedManager::Deinitialize ( )
inlinenoexcept

Alias for Shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DumpStatistics()

void LedManager::DumpStatistics ( ) const
noexcept

Log current LED state and statistics to the console.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureInitialized()

bool LedManager::EnsureInitialized ( )
noexcept

Initialise the WS2812 LED strip (idempotent).

Returns
true on success or if already initialised.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCurrentBrightnessPercent()

LedError LedManager::GetCurrentBrightnessPercent ( uint8_t &  brightness_percent) const
inlinenoexcept

Read current brightness as a percentage of max.

Parameters
[out]brightness_percentFilled with value in [0, 100].
Returns
LedError::SUCCESS.
Here is the call graph for this function:

◆ GetCurrentBrightnessRaw()

LedError LedManager::GetCurrentBrightnessRaw ( uint8_t &  brightness_raw) const
inlinenoexcept

Read current brightness as a raw 0–255 value.

Parameters
[out]brightness_rawFilled with raw brightness.
Returns
LedError::SUCCESS.

◆ GetCurrentColor()

LedError LedManager::GetCurrentColor ( LedColor &  color) const
noexcept

Read the currently displayed colour.

Parameters
[out]colorFilled with current RGB value.
Returns
LedError::SUCCESS on success.

◆ GetCurrentGpioPin()

int LedManager::GetCurrentGpioPin ( ) const
inlinenoexcept

GPIO pin the LED strip is attached to.

◆ GetInstance()

LedManager & LedManager::GetInstance ( )
staticnoexcept

Access the singleton instance (Meyers singleton, thread-safe).

Returns
Reference to the sole LedManager instance.
Here is the caller graph for this function:

◆ GetLastError()

LedError LedManager::GetLastError ( ) const
inlinenoexcept

Get the most recent error code from any LED operation.

Returns
Last LedError set by any API call

◆ GetLedCount()

uint32_t LedManager::GetLedCount ( ) const
inlinenoexcept

Number of LEDs in the strip (always 1 on Vortex V1).

◆ GetLedGpioPin()

static int LedManager::GetLedGpioPin ( )
inlinestaticprivatenoexcept
Here is the caller graph for this function:

◆ GetSystemDiagnostics()

LedError LedManager::GetSystemDiagnostics ( LedSystemDiagnostics &  diagnostics) const
noexcept

Populate a diagnostics snapshot.

Parameters
[out]diagnosticsStruct filled with current counters and state.
Returns
LedError::SUCCESS on success.

◆ GetSystemUptimeMs()

uint64_t LedManager::GetSystemUptimeMs ( ) const
privatenoexcept
Here is the caller graph for this function:

◆ IndicateBoot()

LedError LedManager::IndicateBoot ( )
inlinenoexcept

Show the boot indicator (blue blink).

Here is the call graph for this function:

◆ IndicateCalibration()

LedError LedManager::IndicateCalibration ( )
inlinenoexcept

Show the calibration indicator (cyan breathe).

Here is the call graph for this function:

◆ IndicateError()

LedError LedManager::IndicateError ( )
inlinenoexcept

Show the error indicator (red fast-blink).

Here is the call graph for this function:

◆ IndicateReady()

LedError LedManager::IndicateReady ( )
inlinenoexcept

Show the ready indicator (solid green).

Here is the call graph for this function:

◆ IndicateWarning()

LedError LedManager::IndicateWarning ( )
inlinenoexcept

Show the warning indicator (yellow blink).

Here is the call graph for this function:

◆ Initialize()

bool LedManager::Initialize ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsAnimationActive()

bool LedManager::IsAnimationActive ( ) const
inlinenoexcept

Check whether an animation is currently running.

◆ IsInitialized()

bool LedManager::IsInitialized ( ) const
inlinenoexcept

Check whether the LED driver is initialised.

Returns
true if ready.

◆ operator=() [1/2]

LedManager & LedManager::operator= ( const LedManager &  )
delete

◆ operator=() [2/2]

LedManager & LedManager::operator= ( LedManager &&  )
delete

◆ PercentToRaw()

uint8_t LedManager::PercentToRaw ( uint8_t  percent) const
inlineprivatenoexcept
Here is the caller graph for this function:

◆ RawToPercent()

uint8_t LedManager::RawToPercent ( uint8_t  raw) const
inlineprivatenoexcept
Here is the caller graph for this function:

◆ SetBrightness()

LedError LedManager::SetBrightness ( uint8_t  brightness)
inlinenoexcept

Alias for SetBrightnessRaw().

Here is the call graph for this function:

◆ SetBrightnessPercent()

LedError LedManager::SetBrightnessPercent ( uint8_t  brightness_percent)
noexcept

Set brightness as a percentage of max.

Parameters
brightness_percentValue in [0, 100].
Returns
LedError::SUCCESS on success, INVALID_BRIGHTNESS if out of range.

◆ SetBrightnessRaw()

LedError LedManager::SetBrightnessRaw ( uint8_t  brightness_raw)
noexcept

Set brightness as a raw 0–255 value.

Parameters
brightness_rawRaw brightness [0, max_brightness].
Returns
LedError::SUCCESS on success.
Here is the caller graph for this function:

◆ SetColor() [1/2]

LedError LedManager::SetColor ( const LedColor &  color,
uint32_t  led_index = 0 
)
noexcept

Set LED colour from an LedColor struct.

Parameters
colorRGB colour to display.
led_indexLED index (always 0 for single-LED boards).
Returns
LedError::SUCCESS on success.

◆ SetColor() [2/2]

LedError LedManager::SetColor ( uint32_t  rgb,
uint32_t  led_index = 0 
)
noexcept

Set LED colour from a packed 0xRRGGBB integer.

Parameters
rgb24-bit packed colour.
led_indexLED index (always 0 for single-LED boards).
Returns
LedError::SUCCESS on success.
Here is the call graph for this function:

◆ SetMaxBrightness()

LedError LedManager::SetMaxBrightness ( uint8_t  max_brightness)
noexcept

Set the upper ceiling for brightness.

Parameters
max_brightnessMaximum raw brightness [0–255].
Returns
LedError::SUCCESS on success.

◆ SetStatus()

LedError LedManager::SetStatus ( LedAnimation  animation)
inlinenoexcept

Set a status animation by enum (generic variant).

Parameters
animationThe status animation to start.
Returns
LedError::SUCCESS on success.
Here is the call graph for this function:

◆ ShowPixel()

bool LedManager::ShowPixel ( uint32_t  rgb,
uint8_t  brightness 
)
privatenoexcept

Latch one colour at a brightness onto the LED through the board binding.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shutdown()

bool LedManager::Shutdown ( )
noexcept

Turn off the LED and release driver resources.

Returns
true on success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartAnimation()

LedError LedManager::StartAnimation ( LedAnimation  animation,
const LedColor &  color = LedColors::WHITE 
)
noexcept

Start a named animation with an optional base colour.

Parameters
animationAnimation type to run.
colorBase colour for the animation (default: white).
Returns
LedError::SUCCESS on success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StopAnimation()

LedError LedManager::StopAnimation ( )
noexcept

Stop the current animation and turn the LED off.

Returns
LedError::SUCCESS on success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TurnOff()

LedError LedManager::TurnOff ( )
noexcept

Turn the LED off (set colour to black).

Returns
LedError::SUCCESS on success.
Here is the call graph for this function:

◆ UpdateAnimation()

LedError LedManager::UpdateAnimation ( )
noexcept

Advance the animation by one tick. Call periodically (~50 ms).

Returns
LedError::SUCCESS on success, or ANIMATION_FAILED on error.
Here is the call graph for this function:

◆ UpdateAnimationStep()

LedError LedManager::UpdateAnimationStep ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateLastError()

void LedManager::UpdateLastError ( LedError  error_code)
privatenoexcept
Here is the caller graph for this function:

◆ UpdateStatistics()

void LedManager::UpdateStatistics ( bool  success)
privatenoexcept
Here is the caller graph for this function:

Member Data Documentation

◆ animation_cycles_

std::atomic<uint32_t> LedManager::animation_cycles_ {0}
private

◆ animation_direction_

int8_t LedManager::animation_direction_ {1}
private

◆ animation_step_

uint16_t LedManager::animation_step_ {0}
private

◆ ANIMATION_UPDATE_INTERVAL

constexpr uint32_t LedManager::ANIMATION_UPDATE_INTERVAL = 50
staticconstexprprivate

◆ BLINK_SPEED

constexpr uint32_t LedManager::BLINK_SPEED = 500
staticconstexprprivate

◆ BREATH_SPEED

constexpr uint32_t LedManager::BREATH_SPEED = 5
staticconstexprprivate

◆ current_animation_

LedAnimation LedManager::current_animation_ {LedAnimation::OFF}
private

◆ current_brightness_

uint8_t LedManager::current_brightness_ {255}
private

◆ current_color_

LedColor LedManager::current_color_ {}
private

◆ current_led_gpio_

int LedManager::current_led_gpio_ {-1}
private

◆ DEFAULT_MAX_BRIGHTNESS

constexpr uint8_t LedManager::DEFAULT_MAX_BRIGHTNESS = 255
staticconstexprprivate

◆ failed_operations_

std::atomic<uint32_t> LedManager::failed_operations_ {0}
private

◆ is_initialized_

std::atomic<bool> LedManager::is_initialized_ {false}
private

◆ kNumLeds

constexpr uint32_t LedManager::kNumLeds = 1
staticconstexprprivate

◆ last_animation_update_

uint64_t LedManager::last_animation_update_ {0}
private

◆ last_error_

std::atomic<LedError> LedManager::last_error_ {LedError::SUCCESS}
private

◆ max_brightness_

uint8_t LedManager::max_brightness_ {DEFAULT_MAX_BRIGHTNESS}
private

◆ mutex_

RtosMutex LedManager::mutex_
mutableprivate

◆ successful_operations_

std::atomic<uint32_t> LedManager::successful_operations_ {0}
private

◆ system_start_time_

uint64_t LedManager::system_start_time_ {0}
private

◆ total_operations_

std::atomic<uint32_t> LedManager::total_operations_ {0}
private

The documentation for this class was generated from the following files: