Skip to content

Commit

Permalink
Merge branch 'bugfix/temperature_get_value_negative_v5.11' into 'rele…
Browse files Browse the repository at this point in the history
…ase/v5.1'

bugfix(temperature_sensor): Fix issue that get the value is negative (backport v5.1)

See merge request espressif/esp-idf!25251
  • Loading branch information
ginkgm committed Aug 17, 2023
2 parents cd21729 + 4528849 commit 5d78511
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/driver/deprecated/rtc_temperature_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static esp_err_t read_delta_t_from_efuse(void)
return ESP_OK;
}

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
read_delta_t_from_efuse();
Expand All @@ -144,7 +144,7 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
temp_sensor_config_t tsens;
temp_sensor_get_config(&tsens);
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);
if (*celsius < TEMPERATURE_SENSOR_LL_MEASURE_MIN || *celsius > TEMPERATURE_SENSOR_LL_MEASURE_MAX) {
ESP_LOGE(TAG, "Exceeding temperature measure range.");
Expand Down
4 changes: 2 additions & 2 deletions components/driver/temperature_sensor/temperature_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static esp_err_t read_delta_t_from_efuse(void)
return ESP_OK;
}

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
read_delta_t_from_efuse();
Expand All @@ -230,7 +230,7 @@ esp_err_t temperature_sensor_get_celsius(temperature_sensor_handle_t tsens, floa
ESP_RETURN_ON_FALSE(out_celsius != NULL, ESP_ERR_INVALID_ARG, TAG, "Celsius points to nothing");
ESP_RETURN_ON_FALSE(tsens->fsm == TEMP_SENSOR_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "tsens not enabled yet");
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);
*out_celsius = parse_temp_sensor_raw_value(tsens_out);

if (*out_celsius < TEMPERATURE_SENSOR_LL_MEASURE_MIN || *out_celsius > TEMPERATURE_SENSOR_LL_MEASURE_MAX) {
Expand Down

0 comments on commit 5d78511

Please sign in to comment.