HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Flux Class Reference

Unified singleton entry point for the HardFOC Flux V1 platform. More...

#include <Flux.h>

Collaboration diagram for Flux:
[legend]

Public Member Functions

 Flux (const Flux &)=delete
 
Flux & operator= (const Flux &)=delete
 
 Flux (Flux &&)=delete
 
Flux & operator= (Flux &&)=delete
 
bool EnsureInitialized () noexcept
 Ensure all Flux subsystems are properly initialized.
 
bool IsInitialized () const noexcept
 Check whether the system is fully initialised.
 
bool Shutdown () noexcept
 Shut down all subsystems in reverse initialisation order.
 
bool GetSystemDiagnostics (FluxSystemDiagnostics &diagnostics) const noexcept
 Populate a full system diagnostics snapshot.
 
std::array< bool, kFluxManagerCount > GetComponentInitializationStatus () const noexcept
 Per-component init status as a bool array.
 
size_t GetFailedComponents (const char *out[], size_t max_count) const noexcept
 Get the list of components that failed initialization.
 
size_t GetSystemWarnings (const char *out[], size_t max_count) const noexcept
 Get accumulated system warnings.
 
bool CollectManagerHealth (ManagerHealthSnapshot &snapshot) noexcept
 Collect per-manager error health into a unified snapshot.
 
bool CollectDiagnostics (FluxHalDiagnostics &out) const noexcept
 Fill the board-level bring-up snapshot (managers in init order, part readiness).
 
flux::hal::ManagerError GetLastError () const noexcept
 Why the last EnsureInitialized() failed: the error of the first required manager that did not come up, or ManagerError::None.
 
uint64_t GetSystemUptimeMs () const noexcept
 Milliseconds elapsed since EnsureInitialized() completed.
 
uint64_t GetInitializationTimeMs () const noexcept
 Time in ms that the initialisation sequence took to complete.
 
uint32_t GetLastResetReason () const noexcept
 Reset reason of the previous boot, opaque to callers.
 
uint32_t GetFreeHeapBytes () const noexcept
 Free bytes available in the default heap.
 
uint32_t GetLargestFreeHeapBlock () const noexcept
 Largest contiguous free block in the default heap.
 
void SystemRestart () const noexcept
 Trigger a software reset of the MCU. Does not return on success.
 
void DumpSystemStatistics () const noexcept
 Log a comprehensive system summary to the console.
 
bool PerformHealthCheck () noexcept
 Run a quick health check across all managers.
 
const char * GetSystemVersion () const noexcept
 Get the Flux HAL semantic version string.
 

Static Public Member Functions

static Flux & GetInstance () noexcept
 Access the singleton instance (Meyers singleton, thread-safe).
 

Public Attributes

CommChannelsManager & comms
 SPI, CAN, UART (I²C not used on Flux V1)
 
NvsManager & nvs
 NVS (flux / flux_cal / flux_cfg)
 
GpioManager & gpio
 ESP32 GPIO pins.
 
ValveManager & valves
 Solenoid + proportional valve control.
 
AdcManager & adc
 ADC channels (NTC, VBUS)
 
LedManager & leds
 WS2812 status LED.
 
TemperatureManager & temp
 Temperature sensors.
 

Private Member Functions

 Flux () noexcept
 
 ~Flux ()=default
 
bool InitializeAllComponents () noexcept
 
bool InitializeNvs () noexcept
 
bool InitializeComms () noexcept
 
bool InitializeGpio () noexcept
 
bool InitializeValves () noexcept
 
bool InitializeAdc () noexcept
 
bool InitializeLeds () noexcept
 
bool InitializeTemperature () noexcept
 
void UpdateSystemDiagnostics () noexcept
 
void AddSystemWarning (const char *warning) noexcept
 

Private Attributes

std::atomic< bool > initialized_ {false}
 
std::atomic< flux::hal::ManagerError > last_error_ {flux::hal::ManagerError::None}
 
std::atomic< uint64_t > initialization_start_time_ {0}
 
std::atomic< uint64_t > initialization_end_time_ {0}
 
std::atomic< bool > nvs_initialized_ {false}
 
std::atomic< bool > comms_initialized_ {false}
 
std::atomic< bool > gpio_initialized_ {false}
 
std::atomic< bool > valves_initialized_ {false}
 
std::atomic< bool > adc_initialized_ {false}
 
std::atomic< bool > leds_initialized_ {false}
 
std::atomic< bool > temp_initialized_ {false}
 
FluxSystemDiagnostics diagnostics_
 
const char * failed_components_ [kMaxFailedComponents] {}
 
size_t failed_components_count_ {0}
 
const char * system_warnings_ [kMaxSystemWarnings] {}
 
size_t system_warnings_count_ {0}
 

Static Private Attributes

static constexpr size_t kMaxFailedComponents = kFluxManagerCount
 
static constexpr size_t kMaxSystemWarnings = 16
 

Detailed Description

Unified singleton entry point for the HardFOC Flux V1 platform.

Orchestrates initialisation of all subsystem managers (NVS, Comms, GPIO, Valves, ADC, LED, Temperature) in deterministic order and exposes them as public reference members for direct access. Provides system-level diagnostics, health checking, graceful shutdown, and runtime warning collection.

Constructor & Destructor Documentation

◆ Flux() [1/3]

Flux::Flux ( const Flux &  )
delete

◆ Flux() [2/3]

Flux::Flux ( Flux &&  )
delete

◆ Flux() [3/3]

Flux::Flux ( )
privatenoexcept

◆ ~Flux()

Flux::~Flux ( )
privatedefault

Member Function Documentation

◆ AddSystemWarning()

void Flux::AddSystemWarning ( const char *  warning)
inlineprivatenoexcept

◆ CollectDiagnostics()

bool Flux::CollectDiagnostics ( FluxHalDiagnostics &  out) const
noexcept

Fill the board-level bring-up snapshot (managers in init order, part readiness).

Works before, during and after initialisation and never fails closed: it reports what is up and why the rest is not. Uses the shared flux::hal::ManagerError catalog, so codes from different managers compare.

Parameters
[out]outOverwritten.
Returns
true (always filled).
Here is the caller graph for this function:

◆ CollectManagerHealth()

bool Flux::CollectManagerHealth ( ManagerHealthSnapshot &  snapshot)
noexcept

Collect per-manager error health into a unified snapshot.

Parameters
snapshotReference to snapshot structure to fill
Returns
true if snapshot collected successfully, false if not initialized
Note
Error codes are manager-specific uint8_t values (0 = success)
Here is the caller graph for this function:

◆ DumpSystemStatistics()

void Flux::DumpSystemStatistics ( ) const
noexcept

Log a comprehensive system summary to the console.

Here is the call graph for this function:

◆ EnsureInitialized()

bool Flux::EnsureInitialized ( )
noexcept

Ensure all Flux subsystems are properly initialized.

Returns
true if all critical systems initialized, false otherwise
Here is the call graph for this function:

◆ GetComponentInitializationStatus()

std::array< bool, kFluxManagerCount > Flux::GetComponentInitializationStatus ( ) const
noexcept

Per-component init status as a bool array.

Returns
Array of 7 booleans: [nvs, comms, gpio, valves, adc, leds, temp].

◆ GetFailedComponents()

size_t Flux::GetFailedComponents ( const char *  out[],
size_t  max_count 
) const
noexcept

Get the list of components that failed initialization.

Parameters
outOutput array of const char* pointers (filled with string literals)
max_countMaximum entries to write
Returns
Number of entries written

◆ GetFreeHeapBytes()

uint32_t Flux::GetFreeHeapBytes ( ) const
noexcept

Free bytes available in the default heap.

Wraps heap_caps_get_free_size(MALLOC_CAP_DEFAULT) on ESP32. Useful for diagnostic logging on thread-start failures (e.g. xTaskCreate returning false often correlates with heap exhaustion). Returns 0 on the unsupported test stub.

Here is the call graph for this function:

◆ GetInitializationTimeMs()

uint64_t Flux::GetInitializationTimeMs ( ) const
noexcept

Time in ms that the initialisation sequence took to complete.

Here is the caller graph for this function:

◆ GetInstance()

Flux & Flux::GetInstance ( )
staticnoexcept

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

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

◆ GetLargestFreeHeapBlock()

uint32_t Flux::GetLargestFreeHeapBlock ( ) const
noexcept

Largest contiguous free block in the default heap.

Wraps heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT) on ESP32. Combined with GetFreeHeapBytes() it tells you whether the heap is fragmented (free total >> largest block) or simply exhausted.

Here is the call graph for this function:

◆ GetLastError()

flux::hal::ManagerError Flux::GetLastError ( ) const
inlinenoexcept

Why the last EnsureInitialized() failed: the error of the first required manager that did not come up, or ManagerError::None.

◆ GetLastResetReason()

uint32_t Flux::GetLastResetReason ( ) const
noexcept

Reset reason of the previous boot, opaque to callers.

Wraps esp_reset_reason() on ESP32 today; on other MCUs an equivalent vendor enum will back this. Apps treat the return as an opaque uint32_t they can persist to NVS or print verbatim; decoding is platform-specific and lives in HAL utilities.

Returns
Vendor-specific reset cause (esp_reset_reason_t-shaped on ESP32; 0 on the unsupported test stub).
Here is the call graph for this function:

◆ GetSystemDiagnostics()

bool Flux::GetSystemDiagnostics ( FluxSystemDiagnostics &  diagnostics) const
noexcept

Populate a full system diagnostics snapshot.

Parameters
[out]diagnosticsStruct filled with per-component status.
Returns
true on success.

◆ GetSystemUptimeMs()

uint64_t Flux::GetSystemUptimeMs ( ) const
noexcept

Milliseconds elapsed since EnsureInitialized() completed.

Here is the caller graph for this function:

◆ GetSystemVersion()

const char * Flux::GetSystemVersion ( ) const
noexcept

Get the Flux HAL semantic version string.

Returns
Null-terminated version string (e.g. "1.0.0").

◆ GetSystemWarnings()

size_t Flux::GetSystemWarnings ( const char *  out[],
size_t  max_count 
) const
noexcept

Get accumulated system warnings.

Parameters
outOutput array of const char* pointers
max_countMaximum entries to write
Returns
Number of entries written

◆ InitializeAdc()

bool Flux::InitializeAdc ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeAllComponents()

bool Flux::InitializeAllComponents ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeComms()

bool Flux::InitializeComms ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeGpio()

bool Flux::InitializeGpio ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeLeds()

bool Flux::InitializeLeds ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeNvs()

bool Flux::InitializeNvs ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeTemperature()

bool Flux::InitializeTemperature ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeValves()

bool Flux::InitializeValves ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsInitialized()

bool Flux::IsInitialized ( ) const
inlinenoexcept

Check whether the system is fully initialised.

Returns
true if EnsureInitialized() has succeeded.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Flux & Flux::operator= ( Flux &&  )
delete

◆ PerformHealthCheck()

bool Flux::PerformHealthCheck ( )
noexcept

Run a quick health check across all managers.

Returns
true if every manager reports no errors.
Here is the call graph for this function:

◆ Shutdown()

bool Flux::Shutdown ( )
noexcept

Shut down all subsystems in reverse initialisation order.

Returns
true if all subsystems shut down cleanly.
Here is the call graph for this function:

◆ SystemRestart()

void Flux::SystemRestart ( ) const
noexcept

Trigger a software reset of the MCU. Does not return on success.

Wraps esp_restart() on ESP32. Apps call this from supervisor paths (e.g. app_main's recovery loop) when something has gone unrecoverably wrong. The HAL closes/flushes nothing here — the caller is responsible for any pre-reboot logging or NVS commit.

Here is the call graph for this function:

◆ UpdateSystemDiagnostics()

void Flux::UpdateSystemDiagnostics ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ adc

AdcManager& Flux::adc

ADC channels (NTC, VBUS)

◆ adc_initialized_

std::atomic<bool> Flux::adc_initialized_ {false}
private

◆ comms

CommChannelsManager& Flux::comms

SPI, CAN, UART (I²C not used on Flux V1)

◆ comms_initialized_

std::atomic<bool> Flux::comms_initialized_ {false}
private

◆ diagnostics_

FluxSystemDiagnostics Flux::diagnostics_
mutableprivate

◆ failed_components_

const char* Flux::failed_components_[kMaxFailedComponents] {}
private

◆ failed_components_count_

size_t Flux::failed_components_count_ {0}
private

◆ gpio

GpioManager& Flux::gpio

ESP32 GPIO pins.

◆ gpio_initialized_

std::atomic<bool> Flux::gpio_initialized_ {false}
private

◆ initialization_end_time_

std::atomic<uint64_t> Flux::initialization_end_time_ {0}
private

◆ initialization_start_time_

std::atomic<uint64_t> Flux::initialization_start_time_ {0}
private

◆ initialized_

std::atomic<bool> Flux::initialized_ {false}
private

◆ kMaxFailedComponents

constexpr size_t Flux::kMaxFailedComponents = kFluxManagerCount
staticconstexprprivate

◆ kMaxSystemWarnings

constexpr size_t Flux::kMaxSystemWarnings = 16
staticconstexprprivate

◆ last_error_

std::atomic<flux::hal::ManagerError> Flux::last_error_ {flux::hal::ManagerError::None}
private

◆ leds

LedManager& Flux::leds

WS2812 status LED.

◆ leds_initialized_

std::atomic<bool> Flux::leds_initialized_ {false}
private

◆ nvs

NvsManager& Flux::nvs

NVS (flux / flux_cal / flux_cfg)

◆ nvs_initialized_

std::atomic<bool> Flux::nvs_initialized_ {false}
private

◆ system_warnings_

const char* Flux::system_warnings_[kMaxSystemWarnings] {}
private

◆ system_warnings_count_

size_t Flux::system_warnings_count_ {0}
private

◆ temp

TemperatureManager& Flux::temp

Temperature sensors.

◆ temp_initialized_

std::atomic<bool> Flux::temp_initialized_ {false}
private

◆ valves

ValveManager& Flux::valves

Solenoid + proportional valve control.

◆ valves_initialized_

std::atomic<bool> Flux::valves_initialized_ {false}
private

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