21#ifndef FLUX_TEMPERATURE_MANAGER_H_
22#define FLUX_TEMPERATURE_MANAGER_H_
30#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseTemperature.h"
31#include "handlers/mcp9700/Mcp9700TemperatureHandler.h"
32#include "handlers/ntc/NtcTemperatureHandler.h"
33#include "handlers/logger/Logger.h"
79 default:
return "Unknown error";
107 default:
return "Unknown";
318 [[nodiscard]]
size_t FindByName(std::string_view name) const noexcept;
TemperatureManager & GetTemperatureManager() noexcept
Convenience accessor — equivalent to TemperatureManager::GetInstance().
Definition TemperatureManager.h:351
TemperatureError
Temperature manager error codes for consistent error reporting.
Definition TemperatureManager.h:47
@ NOT_INITIALIZED
Manager not yet initialised.
@ MUTEX_LOCK_FAILED
RTOS mutex acquire timed out.
@ DEPENDENCY_NOT_READY
Required dependency not initialised.
@ SENSOR_NOT_AVAILABLE
Sensor exists but is unavailable.
@ SENSOR_NOT_FOUND
Named sensor does not exist in registry.
@ READ_FAILED
Driver-level read returned an error.
@ NO_SENSORS_AVAILABLE
No sensors were registered at init.
@ SUCCESS
Operation completed successfully.
@ ALLOCATION_FAILED
Heap allocation for a sensor driver failed.
@ INITIALIZATION_FAILED
Sensor initialisation failed.
@ INVALID_PARAMETER
Null pointer or out-of-range argument.
constexpr const char * FluxTempSensorTypeToString(FluxTempSensorType type) noexcept
Convert FluxTempSensorType to a human-readable string.
Definition TemperatureManager.h:102
FluxTempSensorType
Identifies the physical temperature sensor type on the Flux board.
Definition TemperatureManager.h:90
@ SENSOR_COUNT
Number of sensor types (not a valid sensor)
@ MCP9700_THERMISTOR
MCP9700 on ADS7952 multiplexed channel.
@ ESP32_INTERNAL
ESP32 on-chip temperature sensor.
@ NTC_THERMISTOR
External NTC thermistor via ADC.
constexpr const char * TemperatureErrorToString(TemperatureError error) noexcept
Convert TemperatureError to string for debugging.
Definition TemperatureManager.h:66
Singleton manager for all temperature sensors on Flux V1.
Definition TemperatureManager.h:168
TemperatureError GetSystemDiagnostics(TempSystemDiagnostics &diag) const noexcept
Populate a TempSystemDiagnostics snapshot.
Definition TemperatureManager.cpp:370
RtosMutex mutex_
Definition TemperatureManager.h:340
size_t FindByName(std::string_view name) const noexcept
Definition TemperatureManager.cpp:254
TemperatureError GetSystemTemperatureStats(float &min_c, float &max_c, float &avg_c) noexcept
Read all sensors and compute min, max, and average temperatures.
Definition TemperatureManager.cpp:337
TemperatureError ReadTemperatureFahrenheit(std::string_view name, float &temperature_f) noexcept
Read temperature in Fahrenheit from a named sensor.
Definition TemperatureManager.cpp:317
std::optional< Mcp9700TemperatureHandler > mcp9700_handler_
Definition TemperatureManager.h:335
static constexpr size_t kMaxSensors
Definition TemperatureManager.h:324
static TemperatureManager & GetInstance() noexcept
Return the singleton TemperatureManager instance.
Definition TemperatureManager.cpp:43
flux::hal::ManagerError GetManagerError() const noexcept
Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
Definition TemperatureManager.h:210
TemperatureError ReadMcp9700Temperature(float &temperature_c) noexcept
Convenience: read the MCP9700 sensor (ADS7952 CH8).
Definition TemperatureManager.cpp:333
std::atomic< TemperatureError > last_error_
Definition TemperatureManager.h:338
TemperatureManager & operator=(const TemperatureManager &)=delete
bool InitializeNtcThermistor() noexcept
Definition TemperatureManager.cpp:155
bool IsSensorReady(FluxTempSensorType type) const noexcept
Whether one sensor came up during the last bring-up attempt (valid for diagnosis even when the manage...
Definition TemperatureManager.cpp:64
void ReleaseLocked() noexcept
Definition TemperatureManager.cpp:73
uint64_t init_time_ms_
Timestamp (ms) when Initialize() completed.
Definition TemperatureManager.h:329
TemperatureError ReadTemperatureCelsius(std::string_view name, float &temperature_c) noexcept
Read temperature in Celsius from a named sensor.
Definition TemperatureManager.cpp:271
bool InitializeEsp32Internal() noexcept
Definition TemperatureManager.cpp:131
TemperatureManager(const TemperatureManager &)=delete
BaseTemperature * die_temp_
Definition TemperatureManager.h:333
std::optional< NtcTemperatureHandler > ntc_handler_
Definition TemperatureManager.h:334
bool IsInitialized() const noexcept
Check whether the temperature subsystem has been initialised.
Definition TemperatureManager.h:192
size_t registered_count_
Definition TemperatureManager.h:328
size_t GetSensorCount() const noexcept
Get the number of registered temperature sensors.
Definition TemperatureManager.h:285
TemperatureManager(TemperatureManager &&)=delete
std::array< TempEntry, kMaxSensors > entries_
Definition TemperatureManager.h:327
TemperatureError ReadInternalTemperature(float &temperature_c) noexcept
Convenience: read the ESP32 internal temperature sensor.
Definition TemperatureManager.cpp:325
void DumpStatistics() const noexcept
Log temperature sensor statistics and health info to the console.
Definition TemperatureManager.cpp:414
bool Deinitialize() noexcept
Release all temperature sensor resources and reset to uninitialized state.
Definition TemperatureManager.cpp:434
TemperatureManager & operator=(TemperatureManager &&)=delete
bool EnsureInitialized() noexcept
Initialise the temperature subsystem if not already initialised.
Definition TemperatureManager.cpp:52
TemperatureError GetLastError() const noexcept
Get the most recent error code.
Definition TemperatureManager.h:204
std::atomic< flux::hal::ManagerError > manager_error_
Definition TemperatureManager.h:339
TemperatureError ReadNtcTemperature(float &temperature_c) noexcept
Convenience: read the NTC thermistor temperature.
Definition TemperatureManager.cpp:329
bool IsDegraded() const noexcept
Initialised with at least one fitted sensor missing.
Definition TemperatureManager.h:226
bool InitializeMcp9700Thermistor() noexcept
Definition TemperatureManager.cpp:205
static constexpr size_t kInvalidIndex
Definition TemperatureManager.h:325
const TempEntry * GetSensorEntry(std::string_view name) const noexcept
Look up a sensor entry by name.
Definition TemperatureManager.cpp:261
std::atomic< bool > initialized_
Definition TemperatureManager.h:337
bool Initialize() noexcept
Definition TemperatureManager.cpp:86
Shared HAL types for Flux V1: the manager error catalog and the facade result.
ManagerError
Lifecycle / bind failure catalog shared by every manager (GetManagerError()).
Definition flux_hal_types.hpp:37
@ NotInitialized
Manager not initialised (or shut down)
A single temperature sensor entry in the fixed-size registry.
Definition TemperatureManager.h:118
uint32_t error_count
Cumulative failed reads.
Definition TemperatureManager.h:126
uint32_t read_count
Cumulative successful reads.
Definition TemperatureManager.h:125
FluxTempSensorType sensor_type
Physical sensor type.
Definition TemperatureManager.h:120
std::string_view name
Human-readable name.
Definition TemperatureManager.h:119
bool registered
Whether this entry is active.
Definition TemperatureManager.h:121
float last_reading_celsius
Most recent cached reading in °C.
Definition TemperatureManager.h:122
Temperature subsystem diagnostics snapshot (cross-HAL compatible format).
Definition TemperatureManager.h:136
uint32_t sensors_by_type[8]
Count of sensors per FluxTempSensorType index.
Definition TemperatureManager.h:139
uint32_t hardware_errors
Errors attributed to hardware faults.
Definition TemperatureManager.h:144
uint32_t total_operations
Cumulative read attempts across all sensors.
Definition TemperatureManager.h:140
float system_avg_temp_celsius
Average temperature across all sensors (°C)
Definition TemperatureManager.h:149
uint64_t system_uptime_ms
Milliseconds since temperature subsystem init.
Definition TemperatureManager.h:145
uint32_t failed_operations
Cumulative failed reads.
Definition TemperatureManager.h:142
uint32_t successful_operations
Cumulative successful reads.
Definition TemperatureManager.h:141
bool system_healthy
True when all registered sensors are responsive.
Definition TemperatureManager.h:137
TemperatureError last_error
Most recent error code from any operation.
Definition TemperatureManager.h:146
float system_max_temp_celsius
Maximum temperature across all sensors (°C)
Definition TemperatureManager.h:148
uint32_t total_sensors_registered
Number of sensors currently registered.
Definition TemperatureManager.h:138
uint32_t communication_errors
Errors attributed to bus communication failures.
Definition TemperatureManager.h:143
float system_min_temp_celsius
Minimum temperature across all sensors (°C)
Definition TemperatureManager.h:147