6static const uint8_t MCP9808_REG_AMBIENT_TEMP = 0x05;
7static const uint8_t MCP9808_REG_MANUF_ID = 0x06;
8static const uint8_t MCP9808_REG_DEVICE_ID = 0x07;
10static const uint16_t MCP9808_MANUF_ID = 0x0054;
11static const uint16_t MCP9808_DEV_ID = 0x0400;
13static const uint8_t MCP9808_AMBIENT_CLEAR_FLAGS = 0x1F;
14static const uint8_t MCP9808_AMBIENT_CLEAR_SIGN = 0x0F;
15static const uint8_t MCP9808_AMBIENT_TEMP_NEGATIVE = 0x10;
17static const char *
const TAG =
"mcp9808";
21 if (!this->
read_byte_16(MCP9808_REG_MANUF_ID, &manu) || manu != MCP9808_MANUF_ID) {
23 ESP_LOGE(TAG,
"Incorrect manufacturer ID (%X) for '%s'", manu, this->
name_.
c_str());
27 if (!this->
read_byte_16(MCP9808_REG_DEVICE_ID, &dev_id) || dev_id != MCP9808_DEV_ID) {
29 ESP_LOGE(TAG,
"Incorrect device ID (%X) for '%s'", dev_id, this->
name_.
c_str());
34 ESP_LOGCONFIG(TAG,
"%s:", this->
name_.
c_str());
37 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL_FOR, this->
name_.
c_str());
39 LOG_UPDATE_INTERVAL(
this);
40 LOG_SENSOR(
" ",
"Temperature",
this);
48 if (raw_temp == 0xFFFF) {
54 uint8_t msb = (uint8_t) ((
raw_temp & 0xff00) >> 8);
57 msb = msb & MCP9808_AMBIENT_CLEAR_FLAGS;
59 if ((msb & MCP9808_AMBIENT_TEMP_NEGATIVE) == MCP9808_AMBIENT_TEMP_NEGATIVE) {
60 msb = msb & MCP9808_AMBIENT_CLEAR_SIGN;
61 temp = (256 - ((uint16_t) (msb) *16 + lsb / 16.0f)) * -1;
63 temp = (uint16_t) (msb) *16 + lsb / 16.0f;
66 if (std::isnan(temp)) {
71 ESP_LOGD(TAG,
"%s: Got temperature=%.4f°C", this->
name_.
c_str(), temp);