forked from espressif/esp-idf
bugfix(temperature_sensor): Fix issue that get the value is negative
This commit is contained in:
@@ -126,7 +126,7 @@ static void read_delta_t_from_efuse(void)
|
|||||||
ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT);
|
ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float parse_temp_sensor_raw_value(uint32_t tsens_raw)
|
static float parse_temp_sensor_raw_value(int16_t tsens_raw)
|
||||||
{
|
{
|
||||||
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
||||||
read_delta_t_from_efuse();
|
read_delta_t_from_efuse();
|
||||||
@@ -141,7 +141,7 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
|
|||||||
temp_sensor_config_t tsens;
|
temp_sensor_config_t tsens;
|
||||||
temp_sensor_get_config(&tsens);
|
temp_sensor_get_config(&tsens);
|
||||||
bool range_changed;
|
bool range_changed;
|
||||||
uint16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
int16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
||||||
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
||||||
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
||||||
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
||||||
|
@@ -148,7 +148,7 @@ static void read_delta_t_from_efuse(void)
|
|||||||
ESP_LOGD(TAG, "s_deltaT = %f\n", s_deltaT);
|
ESP_LOGD(TAG, "s_deltaT = %f\n", s_deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float parse_temp_sensor_raw_value(uint32_t tsens_raw)
|
static float parse_temp_sensor_raw_value(int16_t tsens_raw)
|
||||||
{
|
{
|
||||||
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
||||||
read_delta_t_from_efuse();
|
read_delta_t_from_efuse();
|
||||||
@@ -163,7 +163,7 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
|
|||||||
temp_sensor_config_t tsens;
|
temp_sensor_config_t tsens;
|
||||||
temp_sensor_get_config(&tsens);
|
temp_sensor_get_config(&tsens);
|
||||||
bool range_changed;
|
bool range_changed;
|
||||||
uint16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
int16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
||||||
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
||||||
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
||||||
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
||||||
|
@@ -128,7 +128,7 @@ static void read_delta_t_from_efuse(void)
|
|||||||
ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT);
|
ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float parse_temp_sensor_raw_value(uint32_t tsens_raw)
|
static float parse_temp_sensor_raw_value(int16_t tsens_raw)
|
||||||
{
|
{
|
||||||
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
if (isnan(s_deltaT)) { //suggests that the value is not initialized
|
||||||
read_delta_t_from_efuse();
|
read_delta_t_from_efuse();
|
||||||
@@ -143,7 +143,7 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
|
|||||||
temp_sensor_config_t tsens;
|
temp_sensor_config_t tsens;
|
||||||
temp_sensor_get_config(&tsens);
|
temp_sensor_get_config(&tsens);
|
||||||
bool range_changed;
|
bool range_changed;
|
||||||
uint16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
int16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
||||||
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
*celsius = parse_temp_sensor_raw_value(tsens_out);
|
||||||
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
if (*celsius < TEMPERATURE_SENSOR_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_MEASURE_MAX) {
|
||||||
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
||||||
|
@@ -210,4 +210,4 @@ int16_t temp_sensor_get_raw_value(bool *range_changed)
|
|||||||
|
|
||||||
portEXIT_CRITICAL(&rtc_spinlock);
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
return degree;
|
return degree;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user