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 | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TemperatureManager Class Reference

Singleton manager for all temperature sensors on Flux V1. More...

#include <TemperatureManager.h>

Collaboration diagram for TemperatureManager:
[legend]

Public Member Functions

 TemperatureManager (const TemperatureManager &)=delete
 
TemperatureManager & operator= (const TemperatureManager &)=delete
 
 TemperatureManager (TemperatureManager &&)=delete
 
TemperatureManager & operator= (TemperatureManager &&)=delete
 
bool EnsureInitialized () noexcept
 Initialise the temperature subsystem if not already initialised.
 
bool IsInitialized () const noexcept
 Check whether the temperature subsystem has been initialised.
 
bool Deinitialize () noexcept
 Release all temperature sensor resources and reset to uninitialized state.
 
TemperatureError GetLastError () const noexcept
 Get the most recent error code.
 
flux::hal::ManagerError GetManagerError () const noexcept
 Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
 
bool IsSensorReady (FluxTempSensorType type) const noexcept
 Whether one sensor came up during the last bring-up attempt (valid for diagnosis even when the manager failed closed).
 
bool IsDegraded () const noexcept
 Initialised with at least one fitted sensor missing.
 
TemperatureError ReadTemperatureCelsius (std::string_view name, float &temperature_c) noexcept
 Read temperature in Celsius from a named sensor.
 
TemperatureError ReadTemperatureFahrenheit (std::string_view name, float &temperature_f) noexcept
 Read temperature in Fahrenheit from a named sensor.
 
TemperatureError ReadInternalTemperature (float &temperature_c) noexcept
 Convenience: read the ESP32 internal temperature sensor.
 
TemperatureError ReadNtcTemperature (float &temperature_c) noexcept
 Convenience: read the NTC thermistor temperature.
 
TemperatureError ReadMcp9700Temperature (float &temperature_c) noexcept
 Convenience: read the MCP9700 sensor (ADS7952 CH8).
 
TemperatureError GetSystemTemperatureStats (float &min_c, float &max_c, float &avg_c) noexcept
 Read all sensors and compute min, max, and average temperatures.
 
size_t GetSensorCount () const noexcept
 Get the number of registered temperature sensors.
 
const TempEntry * GetSensorEntry (std::string_view name) const noexcept
 Look up a sensor entry by name.
 
TemperatureError GetSystemDiagnostics (TempSystemDiagnostics &diag) const noexcept
 Populate a TempSystemDiagnostics snapshot.
 
void DumpStatistics () const noexcept
 Log temperature sensor statistics and health info to the console.
 

Static Public Member Functions

static TemperatureManager & GetInstance () noexcept
 Return the singleton TemperatureManager instance.
 

Private Member Functions

 TemperatureManager () noexcept=default
 
 ~TemperatureManager ()=default
 
bool Initialize () noexcept
 
void ReleaseLocked () noexcept
 
bool InitializeEsp32Internal () noexcept
 
bool InitializeNtcThermistor () noexcept
 
bool InitializeMcp9700Thermistor () noexcept
 
size_t FindByName (std::string_view name) const noexcept
 

Private Attributes

std::array< TempEntry, kMaxSensors > entries_ {}
 
size_t registered_count_ {0}
 
uint64_t init_time_ms_ {0}
 Timestamp (ms) when Initialize() completed.
 
BaseTemperature * die_temp_ {nullptr}
 
std::optional< NtcTemperatureHandler > ntc_handler_
 
std::optional< Mcp9700TemperatureHandler > mcp9700_handler_
 
std::atomic< bool > initialized_ {false}
 
std::atomic< TemperatureError > last_error_ {TemperatureError::SUCCESS}
 
std::atomic< flux::hal::ManagerError > manager_error_ {flux::hal::ManagerError::NotInitialized}
 
RtosMutex mutex_
 

Static Private Attributes

static constexpr size_t kMaxSensors = static_cast<size_t>(FluxTempSensorType::SENSOR_COUNT)
 
static constexpr size_t kInvalidIndex = SIZE_MAX
 

Detailed Description

Singleton manager for all temperature sensors on Flux V1.

Manages the ESP32 internal temperature sensor and the NTC thermistor connected via ADC (GPIO4 / ADC1_CH4). Sensors are registered in a fixed-size array at initialisation; readings are returned in Celsius or Fahrenheit.

Note
Call EnsureInitialized() once before any reads. All public methods are thread-safe (guarded by an internal RTOS mutex).

Constructor & Destructor Documentation

◆ TemperatureManager() [1/3]

TemperatureManager::TemperatureManager ( const TemperatureManager &  )
delete

◆ TemperatureManager() [2/3]

TemperatureManager::TemperatureManager ( TemperatureManager &&  )
delete

◆ TemperatureManager() [3/3]

TemperatureManager::TemperatureManager ( )
privatedefaultnoexcept

◆ ~TemperatureManager()

TemperatureManager::~TemperatureManager ( )
privatedefault

Member Function Documentation

◆ Deinitialize()

bool TemperatureManager::Deinitialize ( )
noexcept

Release all temperature sensor resources and reset to uninitialized state.

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

◆ DumpStatistics()

void TemperatureManager::DumpStatistics ( ) const
noexcept

Log temperature sensor statistics and health info to the console.

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

◆ EnsureInitialized()

bool TemperatureManager::EnsureInitialized ( )
noexcept

Initialise the temperature subsystem if not already initialised.

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

◆ FindByName()

size_t TemperatureManager::FindByName ( std::string_view  name) const
privatenoexcept

◆ GetInstance()

TemperatureManager & TemperatureManager::GetInstance ( )
staticnoexcept

Return the singleton TemperatureManager instance.

Here is the caller graph for this function:

◆ GetLastError()

TemperatureError TemperatureManager::GetLastError ( ) const
inlinenoexcept

Get the most recent error code.

Returns
Last TemperatureError set by any API call

◆ GetManagerError()

flux::hal::ManagerError TemperatureManager::GetManagerError ( ) const
inlinenoexcept

Lifecycle / bind error of the last EnsureInitialized() (shared catalog).

Returns
ManagerError::None when initialised; otherwise why bring-up failed.
Here is the caller graph for this function:

◆ GetSensorCount()

size_t TemperatureManager::GetSensorCount ( ) const
inlinenoexcept

Get the number of registered temperature sensors.

◆ GetSensorEntry()

const TempEntry * TemperatureManager::GetSensorEntry ( std::string_view  name) const
noexcept

Look up a sensor entry by name.

Parameters
nameSensor name.
Returns
Pointer to the TempEntry, or nullptr if not found.

◆ GetSystemDiagnostics()

TemperatureError TemperatureManager::GetSystemDiagnostics ( TempSystemDiagnostics &  diag) const
noexcept

Populate a TempSystemDiagnostics snapshot.

Parameters
[out]diagDiagnostics structure to fill.
Returns
TemperatureError::SUCCESS on success.

◆ GetSystemTemperatureStats()

TemperatureError TemperatureManager::GetSystemTemperatureStats ( float &  min_c,
float &  max_c,
float &  avg_c 
)
noexcept

Read all sensors and compute min, max, and average temperatures.

Parameters
[out]min_cMinimum temperature across all sensors (°C).
[out]max_cMaximum temperature across all sensors (°C).
[out]avg_cAverage temperature across all sensors (°C).
Returns
TemperatureError::SUCCESS on success.

◆ Initialize()

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

◆ InitializeEsp32Internal()

bool TemperatureManager::InitializeEsp32Internal ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeMcp9700Thermistor()

bool TemperatureManager::InitializeMcp9700Thermistor ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeNtcThermistor()

bool TemperatureManager::InitializeNtcThermistor ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDegraded()

bool TemperatureManager::IsDegraded ( ) const
inlinenoexcept

Initialised with at least one fitted sensor missing.

The temperature manager is the one manager allowed to run degraded: its sensors are independent monitors with a fallback chain (MCP9700, NTC, die sensor). When degraded, GetManagerError() holds the reason and diagnostics never report it healthy.

Here is the call graph for this function:

◆ IsInitialized()

bool TemperatureManager::IsInitialized ( ) const
inlinenoexcept

Check whether the temperature subsystem has been initialised.

Returns
true if initialised and ready for reads.
Here is the caller graph for this function:

◆ IsSensorReady()

bool TemperatureManager::IsSensorReady ( FluxTempSensorType  type) const
noexcept

Whether one sensor came up during the last bring-up attempt (valid for diagnosis even when the manager failed closed).

◆ operator=() [1/2]

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

◆ operator=() [2/2]

TemperatureManager & TemperatureManager::operator= ( TemperatureManager &&  )
delete

◆ ReadInternalTemperature()

TemperatureError TemperatureManager::ReadInternalTemperature ( float &  temperature_c)
noexcept

Convenience: read the ESP32 internal temperature sensor.

Parameters
temperature_cOutput temperature in °C.
Returns
TemperatureError::SUCCESS on success.

◆ ReadMcp9700Temperature()

TemperatureError TemperatureManager::ReadMcp9700Temperature ( float &  temperature_c)
noexcept

Convenience: read the MCP9700 sensor (ADS7952 CH8).

Parameters
temperature_cOutput temperature in °C.
Returns
TemperatureError::SUCCESS on success.

◆ ReadNtcTemperature()

TemperatureError TemperatureManager::ReadNtcTemperature ( float &  temperature_c)
noexcept

Convenience: read the NTC thermistor temperature.

Parameters
temperature_cOutput temperature in °C.
Returns
TemperatureError::SUCCESS on success.

◆ ReadTemperatureCelsius()

TemperatureError TemperatureManager::ReadTemperatureCelsius ( std::string_view  name,
float &  temperature_c 
)
noexcept

Read temperature in Celsius from a named sensor.

Parameters
name"ESP32_INTERNAL", "NTC_THERMISTOR", or "MCP9700_THERMISTOR"
temperature_cOutput temperature in °C
Returns
TemperatureError::SUCCESS on success

◆ ReadTemperatureFahrenheit()

TemperatureError TemperatureManager::ReadTemperatureFahrenheit ( std::string_view  name,
float &  temperature_f 
)
noexcept

Read temperature in Fahrenheit from a named sensor.

Parameters
nameSensor name ("ESP32_INTERNAL" or "NTC_THERMISTOR").
temperature_fOutput temperature in °F.
Returns
TemperatureError::SUCCESS on success.

◆ ReleaseLocked()

void TemperatureManager::ReleaseLocked ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ die_temp_

BaseTemperature* TemperatureManager::die_temp_ {nullptr}
private

◆ entries_

std::array<TempEntry, kMaxSensors> TemperatureManager::entries_ {}
private

◆ init_time_ms_

uint64_t TemperatureManager::init_time_ms_ {0}
private

Timestamp (ms) when Initialize() completed.

◆ initialized_

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

◆ kInvalidIndex

constexpr size_t TemperatureManager::kInvalidIndex = SIZE_MAX
staticconstexprprivate

◆ kMaxSensors

constexpr size_t TemperatureManager::kMaxSensors = static_cast<size_t>(FluxTempSensorType::SENSOR_COUNT)
staticconstexprprivate

◆ last_error_

std::atomic<TemperatureError> TemperatureManager::last_error_ {TemperatureError::SUCCESS}
private

◆ manager_error_

std::atomic<flux::hal::ManagerError> TemperatureManager::manager_error_ {flux::hal::ManagerError::NotInitialized}
private

◆ mcp9700_handler_

std::optional<Mcp9700TemperatureHandler> TemperatureManager::mcp9700_handler_
private

◆ mutex_

RtosMutex TemperatureManager::mutex_
mutableprivate

◆ ntc_handler_

std::optional<NtcTemperatureHandler> TemperatureManager::ntc_handler_
private

◆ registered_count_

size_t TemperatureManager::registered_count_ {0}
private

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