43#include "driver/temperature_sensor.h"
47#include "freertos/FreeRTOS.h"
48#include "freertos/task.h"
78#define ESP_TEMP_DEFAULT_RESOLUTION_CELSIUS 0.25f
79#define ESP_TEMP_DEFAULT_RESPONSE_TIME_MS 50
80#define ESP_TEMP_DEFAULT_SAMPLE_RATE_HZ 10
81#define ESP_TEMP_MAX_SAMPLE_RATE_HZ 1000
82#define ESP_TEMP_MIN_SAMPLE_RATE_HZ 1
83#define ESP_TEMP_DEFAULT_TIMEOUT_MS 1000
88#define ESP_TEMP_ABSOLUTE_MIN_CELSIUS -40.0f
89#define ESP_TEMP_ABSOLUTE_MAX_CELSIUS 125.0f
90#define ESP_TEMP_RECOMMENDED_MIN_CELSIUS -10.0f
91#define ESP_TEMP_RECOMMENDED_MAX_CELSIUS 80.0f
157 std::function<void(
EspTemperature* sensor,
float temperature,
bool is_high_threshold)>;
300 float high_threshold_celsius) noexcept override;
309 float* high_threshold_celsius) const noexcept override;
318 void* user_data) noexcept override;
335 void* user_data) noexcept override;
385 [[nodiscard]]
bool IsSleeping() const noexcept override;
458 float* accuracy_celsius) const noexcept;
467 float max_celsius) const noexcept;
480 [[nodiscard]] temperature_sensor_handle_t
GetEspHandle() const noexcept;
549 float* accuracy_celsius) const noexcept;
619#define ESP_TEMP_CONFIG_DEFAULT() \
620 {.range = ESP_TEMP_RANGE_NEG10_80, \
621 .calibration_offset = 0.0f, \
622 .enable_threshold_monitoring = false, \
623 .high_threshold_celsius = 80.0f, \
624 .low_threshold_celsius = -10.0f, \
625 .enable_continuous_monitoring = false, \
626 .sample_rate_hz = ESP_TEMP_DEFAULT_SAMPLE_RATE_HZ, \
627 .allow_power_down = true, \
Abstract base class for temperature sensor implementations in the HardFOC system.
hf_temp_err_t
Temperature sensor error codes enumeration.
Definition BaseTemperature.h:113
void(*)(BaseTemperature *temp_sensor, const hf_temp_reading_t *reading, void *user_data) hf_temp_reading_callback_t
Temperature reading callback function type (for continuous monitoring)
Definition BaseTemperature.h:308
void(*)(BaseTemperature *temp_sensor, float temperature_celsius, hf_u32_t threshold_type, void *user_data) hf_temp_threshold_callback_t
Temperature threshold callback function type.
Definition BaseTemperature.h:298
std::function< void(EspTemperature *sensor, float temperature, bool is_high_threshold)> esp_temp_threshold_callback_t
ESP32-C6 threshold callback function type.
Definition EspTemperature.h:156
esp_temp_range_t
ESP32-C6 Temperature sensor measurement ranges.
Definition EspTemperature.h:66
@ ESP_TEMP_RANGE_20_100
20°C to 100°C, ±2°C accuracy (high temperature applications)
Definition EspTemperature.h:68
@ ESP_TEMP_RANGE_NEG30_50
-30°C to 50°C, ±2°C accuracy (low temperature applications)
Definition EspTemperature.h:69
@ ESP_TEMP_RANGE_NEG40_20
-40°C to 20°C, ±3°C accuracy (extreme low temperature)
Definition EspTemperature.h:71
@ ESP_TEMP_RANGE_COUNT
Number of available ranges.
Definition EspTemperature.h:72
@ ESP_TEMP_RANGE_NEG10_80
-10°C to 80°C, ±1°C accuracy (recommended for most applications)
Definition EspTemperature.h:67
@ ESP_TEMP_RANGE_50_125
50°C to 125°C, ±3°C accuracy (extreme high temperature)
Definition EspTemperature.h:70
std::function< void(EspTemperature *sensor, float temperature, hf_u64_t timestamp_us)> esp_temp_monitoring_callback_t
ESP32-C6 continuous monitoring callback function type.
Definition EspTemperature.h:162
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint64_t hf_u64_t
Platform-agnostic 64-bit unsigned integer type.
Definition HardwareTypes.h:58
Abstract base class for all temperature sensor implementations.
Definition BaseTemperature.h:407
ESP32-C6 internal temperature sensor implementation.
Definition EspTemperature.h:192
hf_temp_err_t last_error_
Last error code.
Definition EspTemperature.h:507
hf_temp_err_t ReadTemperatureCelsiusImpl(float *temperature_celsius) noexcept override
ESP32-specific implementation for reading temperature in Celsius.
Definition EspTemperature.cpp:292
hf_temp_err_t CheckHealth() noexcept override
Check sensor health status (ESP32-C6 supported)
Definition EspTemperature.cpp:782
static const char * TAG
ESP-IDF logging tag.
Definition EspTemperature.h:603
esp_temp_range_t FindOptimalRange(float min_celsius, float max_celsius) const noexcept
Find optimal range for given temperature requirements.
Definition EspTemperature.cpp:966
void SetLastError(hf_temp_err_t error) noexcept
Set last error code and update diagnostics.
Definition EspTemperature.cpp:1074
hf_temp_err_t EnableThresholdMonitoring(hf_temp_threshold_callback_t callback, void *user_data) noexcept override
Enable threshold monitoring (ESP32-C6 supported)
Definition EspTemperature.cpp:502
hf_temp_config_t base_config_
Base class configuration.
Definition EspTemperature.h:504
hf_temp_err_t SetCalibrationOffset(float offset_celsius) noexcept override
Set calibration offset (ESP32-C6 supported)
Definition EspTemperature.cpp:643
hf_temp_err_t InitializeEsp32(const esp_temp_config_t &esp_config) noexcept
Initialize with ESP32-specific configuration.
Definition EspTemperature.cpp:873
temperature_sensor_handle_t GetEspHandle() const noexcept
Get ESP-IDF temperature sensor handle.
Definition EspTemperature.cpp:1009
hf_temp_err_t GetSensorInfo(hf_temp_sensor_info_t *info) const noexcept override
Get ESP32-C6 temperature sensor information.
Definition EspTemperature.cpp:382
hf_temp_err_t ResetCalibration() noexcept override
Reset calibration to default (ESP32-C6 supported)
Definition EspTemperature.cpp:671
hf_temp_err_t ReadRawTemperature(float *raw_value) noexcept
Read raw temperature value (before calibration)
Definition EspTemperature.cpp:990
hf_temp_statistics_t statistics_
Operation statistics.
Definition EspTemperature.h:505
hf_temp_err_t SetupRange(esp_temp_range_t range) noexcept
Setup measurement range configuration.
hf_temp_err_t DisableThresholdMonitoring() noexcept override
Disable threshold monitoring (ESP32-C6 supported)
Definition EspTemperature.cpp:523
hf_temp_err_t GetRangeInfo(esp_temp_range_t range, float *min_celsius, float *max_celsius, float *accuracy_celsius) const noexcept
Get range information for a specific range.
Definition EspTemperature.cpp:951
static PlatformMutex s_shared_mutex_
Protect shared handle/refcount.
Definition EspTemperature.h:607
void GetRangeConfig(esp_temp_range_t range, float *min_celsius, float *max_celsius, float *accuracy_celsius) const noexcept
Get range configuration values.
Definition EspTemperature.cpp:1053
hf_temp_err_t GetRange(float *min_celsius, float *max_celsius) const noexcept override
Get temperature measurement range (ESP32-C6 supported)
Definition EspTemperature.cpp:437
static hf_u64_t GetCurrentTimeUs() noexcept
Get current timestamp in microseconds.
Definition EspTemperature.cpp:1183
virtual ~EspTemperature() noexcept
Virtual destructor for proper cleanup.
Definition EspTemperature.cpp:116
esp_temp_config_t esp_config_
ESP32-specific configuration.
Definition EspTemperature.h:503
hf_temp_err_t ExitSleepMode() noexcept override
Exit low power mode (ESP32-C6 supported)
Definition EspTemperature.cpp:703
void * threshold_user_data_
User data for threshold callback.
Definition EspTemperature.h:514
hf_temp_err_t ConfigureEspSensor() noexcept
Configure ESP temperature sensor with current settings.
PlatformMutex mutex_
Thread safety mutex (RTOS-aware)
Definition EspTemperature.h:501
void UpdateDiagnostics(hf_temp_err_t error) noexcept
Update diagnostic information.
Definition EspTemperature.cpp:1110
void * monitoring_user_data_
User data for monitoring callback.
Definition EspTemperature.h:515
bool Initialize() noexcept override
ESP32-specific implementation for initialization.
Definition EspTemperature.cpp:128
hf_temp_err_t SetRange(float min_celsius, float max_celsius) noexcept override
Set temperature measurement range (ESP32-C6 supported)
Definition EspTemperature.cpp:417
hf_temp_err_t SetEspThresholdCallback(esp_temp_threshold_callback_t callback) noexcept
Set ESP32-specific threshold callback.
Definition EspTemperature.cpp:1014
hf_temp_diagnostics_t diagnostics_
Diagnostic information.
Definition EspTemperature.h:506
hf_temp_err_t SetEspMonitoringCallback(esp_temp_monitoring_callback_t callback) noexcept
Set ESP32-specific monitoring callback.
Definition EspTemperature.cpp:1021
hf_temp_err_t ConvertEspError(esp_err_t esp_err) const noexcept
Convert ESP-IDF error to HardFOC temperature error.
Definition EspTemperature.cpp:1032
hf_temp_err_t EnterSleepMode() noexcept override
Enter low power mode (ESP32-C6 supported)
Definition EspTemperature.cpp:675
hf_temp_err_t StopContinuousMonitoring() noexcept override
Stop continuous temperature monitoring (ESP32-C6 supported)
Definition EspTemperature.cpp:598
static const esp_temp_range_info_t RANGE_INFO[]
Range information table.
Definition EspTemperature.h:52
EspTemperature & operator=(const EspTemperature &)=delete
Assignment operator is deleted to avoid copying instances.
hf_temp_err_t SetThresholds(float low_threshold_celsius, float high_threshold_celsius) noexcept override
Set temperature thresholds (ESP32-C6 supported)
Definition EspTemperature.cpp:459
hf_temp_err_t ResetDiagnostics() noexcept override
Reset diagnostic information (ESP32-C6 supported)
Definition EspTemperature.cpp:857
bool IsMonitoringActive() const noexcept override
Check if continuous monitoring is active (ESP32-C6 supported)
Definition EspTemperature.cpp:638
static void MonitoringTimerCallback(void *arg) noexcept
Timer callback for continuous monitoring.
Definition EspTemperature.cpp:1120
void CheckThresholds(float temperature) noexcept
Check thresholds and trigger callbacks if needed.
Definition EspTemperature.cpp:1151
hf_temp_err_t ResetStatistics() noexcept override
Reset operation statistics (ESP32-C6 supported)
Definition EspTemperature.cpp:844
EspTemperature() noexcept
Default constructor.
Definition EspTemperature.cpp:63
bool IsSleeping() const noexcept override
Check if sensor is in sleep mode (ESP32-C6 supported)
Definition EspTemperature.cpp:724
esp_temp_threshold_callback_t esp_threshold_callback_
ESP32-specific threshold callback.
Definition EspTemperature.h:512
hf_temp_err_t StartContinuousMonitoring(hf_u32_t sample_rate_hz, hf_temp_reading_callback_t callback, void *user_data) noexcept override
Start continuous temperature monitoring (ESP32-C6 supported)
Definition EspTemperature.cpp:537
static temperature_sensor_handle_t s_shared_handle_
Shared ESP-IDF handle.
Definition EspTemperature.h:609
hf_temp_err_t SetMeasurementRange(esp_temp_range_t range) noexcept
Set measurement range using ESP32 enum.
Definition EspTemperature.cpp:878
bool Deinitialize() noexcept override
ESP32-specific implementation for deinitialization.
Definition EspTemperature.cpp:195
hf_temp_err_t ValidateConfig(const hf_temp_config_t *config) const noexcept
Validate base configuration.
void UpdateStatistics(bool operation_successful, hf_u32_t operation_time_us) noexcept
Update operation statistics.
Definition EspTemperature.cpp:1079
hf_temp_err_t ValidateEspConfig(const esp_temp_config_t *esp_config) const noexcept
Validate ESP32-specific configuration.
hf_temp_err_t GetCalibrationOffset(float *offset_celsius) const noexcept override
Get calibration offset (ESP32-C6 supported)
Definition EspTemperature.cpp:660
EspTemperature(const EspTemperature &)=delete
Copy constructor is deleted to avoid copying instances.
esp_temp_monitoring_callback_t esp_monitoring_callback_
ESP32-specific monitoring callback.
Definition EspTemperature.h:513
hf_temp_err_t GetThresholds(float *low_threshold_celsius, float *high_threshold_celsius) const noexcept override
Get temperature thresholds (ESP32-C6 supported)
Definition EspTemperature.cpp:488
hf_temp_err_t GetResolution(float *resolution_celsius) const noexcept override
Get measurement resolution (ESP32-C6 supported)
Definition EspTemperature.cpp:450
esp_temp_state_t esp_state_
ESP32-specific state.
Definition EspTemperature.h:502
hf_temp_err_t SelfTest() noexcept override
Perform sensor self-test (ESP32-C6 supported)
Definition EspTemperature.cpp:729
static std::atomic< int > s_refcount_
Number of active instances.
Definition EspTemperature.h:41
esp_temp_range_t GetMeasurementRange() const noexcept
Get current measurement range.
Definition EspTemperature.cpp:946
hf_u32_t GetCapabilities() const noexcept override
Get ESP32-C6 temperature sensor capabilities.
Definition EspTemperature.cpp:407
hf_temp_err_t GetStatistics(hf_temp_statistics_t &statistics) noexcept override
Get operation statistics (ESP32-C6 supported)
Definition EspTemperature.cpp:825
hf_temp_reading_callback_t monitoring_callback_
Base monitoring callback.
Definition EspTemperature.h:511
hf_temp_err_t GetDiagnostics(hf_temp_diagnostics_t &diagnostics) noexcept override
Get diagnostic information (ESP32-C6 supported)
Definition EspTemperature.cpp:831
hf_temp_threshold_callback_t threshold_callback_
Base threshold callback.
Definition EspTemperature.h:510
ESP32-C6 specific temperature sensor configuration.
Definition EspTemperature.h:116
esp_temp_range_t range
Measurement range.
Definition EspTemperature.h:117
float calibration_offset
Initial calibration offset.
Definition EspTemperature.h:118
float low_threshold_celsius
Low temperature threshold.
Definition EspTemperature.h:121
hf_u32_t sample_rate_hz
Sample rate for continuous monitoring.
Definition EspTemperature.h:123
bool enable_continuous_monitoring
Enable continuous monitoring.
Definition EspTemperature.h:122
bool enable_threshold_monitoring
Enable threshold monitoring.
Definition EspTemperature.h:119
float high_threshold_celsius
High temperature threshold.
Definition EspTemperature.h:120
hf_u32_t clk_src
Clock source (usually default)
Definition EspTemperature.h:125
bool allow_power_down
Allow sensor power down in light sleep.
Definition EspTemperature.h:124
Temperature range information structure.
Definition EspTemperature.h:135
float min_celsius
Minimum temperature.
Definition EspTemperature.h:137
esp_temp_range_t range
Range identifier.
Definition EspTemperature.h:136
float max_celsius
Maximum temperature.
Definition EspTemperature.h:138
const char * description
Human-readable description.
Definition EspTemperature.h:140
float accuracy_celsius
Typical accuracy.
Definition EspTemperature.h:139
ESP32-C6 specific temperature sensor state.
Definition EspTemperature.h:100
float last_temperature_celsius
Last temperature reading.
Definition EspTemperature.h:109
bool continuous_monitoring_active
Continuous monitoring status.
Definition EspTemperature.h:105
float calibration_offset
Calibration offset in Celsius.
Definition EspTemperature.h:103
bool threshold_monitoring_enabled
Threshold monitoring status.
Definition EspTemperature.h:104
temperature_sensor_handle_t handle
ESP-IDF temperature sensor handle.
Definition EspTemperature.h:101
esp_temp_range_t current_range
Current measurement range.
Definition EspTemperature.h:102
hf_u32_t sample_rate_hz
Current sample rate.
Definition EspTemperature.h:107
hf_u64_t last_reading_timestamp_us
Last reading timestamp.
Definition EspTemperature.h:108
esp_timer_handle_t monitoring_timer
Timer handle for continuous monitoring.
Definition EspTemperature.h:106
bool allow_power_down
Allow power down during light sleep.
Definition EspTemperature.h:110
Temperature sensor configuration structure.
Definition BaseTemperature.h:207
Temperature sensor diagnostics.
Definition BaseTemperature.h:271
Temperature sensor information structure.
Definition BaseTemperature.h:237
Temperature sensor statistics.
Definition BaseTemperature.h:253