From 462d865fc97c522303fe51485b9f198061e16475 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 18 Jan 2025 16:08:26 +0100 Subject: [PATCH] implement CPU temp for ESP32 --- src/core/system.cpp | 5 ++++- src/core/system.h | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/system.cpp b/src/core/system.cpp index 44e51453f..18d00f245 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -789,7 +789,10 @@ void System::system_check() { last_system_check_ = uuid::get_uptime(); #ifndef EMSESP_STANDALONE -#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 +#if defined(CONFIG_IDF_TARGET_ESP32) + uint8_t raw = temprature_sens_read(); + temperature_ = (raw - 32) / 1.8f; // convert to Celsius +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 #if ESP_IDF_VERSION_MAJOR < 5 temp_sensor_read_celsius(&temperature_); #else diff --git a/src/core/system.h b/src/core/system.h index 35db0cd83..746803a35 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -39,7 +39,12 @@ #include #include -#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 +#if defined(CONFIG_IDF_TARGET_ESP32) +// there is no official API available on the original ESP32 +extern "C" { +uint8_t temprature_sens_read(); +} +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 #if ESP_IDF_VERSION_MAJOR < 5 #include "driver/temp_sensor.h" #else @@ -331,7 +336,7 @@ class System { test_set_all_active_ = n; } -#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32 float temperature() { return temperature_; } @@ -435,8 +440,8 @@ class System { #if ESP_IDF_VERSION_MAJOR >= 5 temperature_sensor_handle_t temperature_handle_ = NULL; #endif - float temperature_ = 0; #endif + float temperature_ = 0; }; } // namespace emsesp