1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-13 14:20:29 +01:00

[tmp1075] fix component for TMP1075N (#8317)

This commit is contained in:
Samuel Sieb 2025-03-02 07:10:18 -08:00 committed by GitHub
parent f11ad9ad5b
commit 23687b2afd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 13 deletions

View File

@ -18,14 +18,9 @@ static uint16_t temp2regvalue(float temp);
static float regvalue2temp(uint16_t regvalue);
void TMP1075Sensor::setup() {
uint8_t die_id;
if (!this->read_byte(REG_DIEID, &die_id)) {
ESP_LOGW(TAG, "'%s' - unable to read ID", this->name_.c_str());
this->mark_failed();
return;
}
if (die_id != EXPECT_DIEID) {
ESP_LOGW(TAG, "'%s' - unexpected ID 0x%x found, expected 0x%x", this->name_.c_str(), die_id, EXPECT_DIEID);
uint8_t cfg;
if (!this->read_byte(REG_CFGR, &cfg)) {
ESP_LOGE(TAG, "'%s' - unable to read", this->name_.c_str());
this->mark_failed();
return;
}
@ -37,9 +32,10 @@ void TMP1075Sensor::update() {
uint16_t regvalue;
if (!read_byte_16(REG_TEMP, &regvalue)) {
ESP_LOGW(TAG, "'%s' - unable to read temperature register", this->name_.c_str());
this->status_set_warning();
this->status_set_warning("can't read");
return;
}
this->status_clear_warning();
const float temp = regvalue2temp(regvalue);
this->publish_state(temp);
@ -89,9 +85,9 @@ void TMP1075Sensor::write_config() {
}
void TMP1075Sensor::send_config_() {
ESP_LOGV(TAG, "'%s' - sending configuration %04x", this->name_.c_str(), config_.regvalue);
ESP_LOGV(TAG, "'%s' - sending configuration %02x", this->name_.c_str(), config_.regvalue);
log_config_();
if (!this->write_byte_16(REG_CFGR, config_.regvalue)) {
if (!this->write_byte(REG_CFGR, config_.regvalue)) {
ESP_LOGW(TAG, "'%s' - unable to write configuration register", this->name_.c_str());
return;
}

View File

@ -36,9 +36,8 @@ struct TMP1075Config {
uint8_t shutdown : 1; // Sets the device in shutdown mode to conserve power.
// 0: Device is in continuous conversion
// 1: Device is in shutdown mode
uint8_t unused : 8;
} fields;
uint16_t regvalue;
uint8_t regvalue;
};
};