4 #if defined(PLATFORM_ESP32)
7 #if defined(PLATFORM_ESP32_S3) || defined(PLATFORM_ESP32_C3)
8 #include "driver/temp_sensor.h"
11 static const uint8_t thermal_threshold_data
[] = {
12 THERMAL_FAN_DEFAULT_HIGH_THRESHOLD
,
13 THERMAL_FAN_DEFAULT_LOW_THRESHOLD
,
14 THERMAL_FAN_ALWAYS_ON_HIGH_THRESHOLD
,
15 THERMAL_FAN_ALWAYS_ON_LOW_THRESHOLD
,
16 THERMAL_FAN_OFF_HIGH_THRESHOLD
,
17 THERMAL_FAN_OFF_LOW_THRESHOLD
20 static Thermal_Status_t thermal_status
= THERMAL_STATUS_FAIL
;
25 if (OPT_HAS_THERMAL_LM75A
)
27 status
= lm75a
.init();
29 #if defined(PLATFORM_ESP32_S3) || defined(PLATFORM_ESP32_C3)
32 temp_sensor_config_t temp_sensor
= TSENS_CONFIG_DEFAULT();
33 temp_sensor
.dac_offset
= TSENS_DAC_L2
; //TSENS_DAC_L2 is default L4(-40℃ ~ 20℃), L2(-10℃ ~ 80℃) L1(20℃ ~ 100℃) L0(50℃ ~ 125℃)
34 temp_sensor_set_config(temp_sensor
);
40 ERRLN("Thermal failed!");
46 thermal_status
= THERMAL_STATUS_NORMAL
;
50 void Thermal::handle()
52 temp_value
= read_temp();
55 uint8_t Thermal::read_temp()
57 if(thermal_status
!= THERMAL_STATUS_NORMAL
)
59 ERRLN("thermal not ready!");
62 if (OPT_HAS_THERMAL_LM75A
)
64 return lm75a
.read_lm75a();
67 #if defined(PLATFORM_ESP32_S3) || defined(PLATFORM_ESP32_C3)
69 temp_sensor_read_celsius(&result
);
70 return static_cast<int>(result
);
76 void Thermal::update_threshold(int index
)
78 static int prevIndex
= -1;
79 if (index
== prevIndex
)
84 if(thermal_status
!= THERMAL_STATUS_NORMAL
)
86 ERRLN("thermal not ready!");
89 constexpr int size
= sizeof(thermal_threshold_data
)/sizeof(thermal_threshold_data
[0]);
92 ERRLN("thermal index out of range!");
95 if (OPT_HAS_THERMAL_LM75A
)
97 const uint8_t high
= thermal_threshold_data
[2*index
];
98 const uint8_t low
= thermal_threshold_data
[2*index
+1];
99 lm75a
.update_lm75a_threshold(high
, low
);