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

Singleton manager for all temperature sensors on Vortex 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 Deinitialize () noexcept
 Release all temperature sensor resources and reset to uninitialised state.
 
bool IsInitialized () const noexcept
 Check whether the temperature subsystem has been initialised.
 
hf_temp_err_t ReadTemperatureCelsius (std::string_view name, float &temperature_celsius) noexcept
 Read temperature in Celsius from a named sensor.
 
hf_temp_err_t ReadTemperatureFahrenheit (std::string_view name, float &temperature_fahrenheit) noexcept
 Read temperature in Fahrenheit from a named sensor.
 
hf_temp_err_t ReadInternalTemperature (float &temperature_c) noexcept
 Convenience: read the ESP32 internal temperature sensor.
 
hf_temp_err_t ReadNtcTemperature (float &temperature_c) noexcept
 Convenience: read the NTC thermistor temperature.
 
hf_temp_err_t ReadMotorTemperature (float &temperature_c) noexcept
 Convenience: read the TMC9660 motor controller temperature.
 
hf_temp_err_t 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.
 
hf_temp_err_t GetSystemDiagnostics (TempSystemDiagnostics &diagnostics) const noexcept
 Populate a TempSystemDiagnostics snapshot.
 
hf_temp_err_t GetLastError () const noexcept
 Get the most recent error code from any temperature operation.
 
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 ()
 
bool Initialize () noexcept
 
void ReleaseLocked () noexcept
 Destroy every sensor object and clear the table. Caller holds mutex_.
 
bool InitializeEsp32Internal () noexcept
 
bool InitializeNtcThermistor () noexcept
 
bool InitializeTmc9660Chip () 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}
 
BaseTemperature * esp32_temp_ {nullptr}
 MCU die sensor, owned by the board binding.
 
std::optional< NtcTemperatureHandler > ntc_handler_
 In place; emplaced at init.
 
std::optional< Tmc9660TemperatureWrapper > tmc9660_temp_
 In place; emplaced at init.
 
std::atomic< bool > initialized_ {false}
 
std::atomic< hf_temp_err_t > last_error_ {hf_temp_err_t::TEMP_SUCCESS}
 
RtosMutex mutex_
 

Static Private Attributes

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

Detailed Description

Singleton manager for all temperature sensors on Vortex V1.

Manages three temperature sources: ESP32 internal sensor, NTC thermistor via TMC9660 AIN3, and TMC9660 internal chip temperature. Sensors are registered in a fixed-size array; 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 uninitialised 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()

hf_temp_err_t TemperatureManager::GetLastError ( ) const
inlinenoexcept

Get the most recent error code from any temperature operation.

Returns
Last hf_temp_err_t set by any API call

◆ 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()

hf_temp_err_t TemperatureManager::GetSystemDiagnostics ( TempSystemDiagnostics &  diagnostics) const
noexcept

Populate a TempSystemDiagnostics snapshot.

Parameters
[out]diagnosticsDiagnostics structure to fill.
Returns
TEMP_SUCCESS on success.

◆ GetSystemTemperatureStats()

hf_temp_err_t 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
TEMP_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:

◆ InitializeNtcThermistor()

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

◆ InitializeTmc9660Chip()

bool TemperatureManager::InitializeTmc9660Chip ( )
privatenoexcept
Here is the call graph for this function:
Here is the caller 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.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ReadInternalTemperature()

hf_temp_err_t TemperatureManager::ReadInternalTemperature ( float &  temperature_c)
noexcept

Convenience: read the ESP32 internal temperature sensor.

Parameters
temperature_cOutput temperature in °C.
Returns
TEMP_SUCCESS on success.

◆ ReadMotorTemperature()

hf_temp_err_t TemperatureManager::ReadMotorTemperature ( float &  temperature_c)
noexcept

Convenience: read the TMC9660 motor controller temperature.

Parameters
temperature_cOutput temperature in °C.
Returns
TEMP_SUCCESS on success.

◆ ReadNtcTemperature()

hf_temp_err_t TemperatureManager::ReadNtcTemperature ( float &  temperature_c)
noexcept

Convenience: read the NTC thermistor temperature.

Parameters
temperature_cOutput temperature in °C.
Returns
TEMP_SUCCESS on success.

◆ ReadTemperatureCelsius()

hf_temp_err_t TemperatureManager::ReadTemperatureCelsius ( std::string_view  name,
float &  temperature_celsius 
)
noexcept

Read temperature in Celsius from a named sensor.

Parameters
name"ESP32_INTERNAL", "NTC_THERMISTOR", or "MOTOR_TEMP"
temperature_celsiusReference to store temperature value
Returns
TEMP_SUCCESS on success, error code otherwise

◆ ReadTemperatureFahrenheit()

hf_temp_err_t TemperatureManager::ReadTemperatureFahrenheit ( std::string_view  name,
float &  temperature_fahrenheit 
)
noexcept

Read temperature in Fahrenheit from a named sensor.

Parameters
nameSensor name ("ESP32_INTERNAL", "NTC_THERMISTOR", or "MOTOR_TEMP").
temperature_fahrenheitOutput temperature in °F.
Returns
TEMP_SUCCESS on success.

◆ ReleaseLocked()

void TemperatureManager::ReleaseLocked ( )
privatenoexcept

Destroy every sensor object and clear the table. Caller holds mutex_.

Here is the caller graph for this function:

Member Data Documentation

◆ entries_

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

◆ esp32_temp_

BaseTemperature* TemperatureManager::esp32_temp_ {nullptr}
private

MCU die sensor, owned by the board binding.

◆ init_time_ms_

uint64_t TemperatureManager::init_time_ms_ {0}
private

◆ 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>(VortexTempSensorType::SENSOR_COUNT)
staticconstexprprivate

◆ last_error_

std::atomic<hf_temp_err_t> TemperatureManager::last_error_ {hf_temp_err_t::TEMP_SUCCESS}
private

◆ mutex_

RtosMutex TemperatureManager::mutex_
mutableprivate

◆ ntc_handler_

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

In place; emplaced at init.

◆ registered_count_

size_t TemperatureManager::registered_count_ {0}
private

◆ tmc9660_temp_

std::optional<Tmc9660TemperatureWrapper> TemperatureManager::tmc9660_temp_
private

In place; emplaced at init.


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