ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
lm75b.cpp
Go to the documentation of this file.
1#include "lm75b.h"
3#include "esphome/core/log.h"
4#include "esphome/core/hal.h"
5
6namespace esphome::lm75b {
7
8ESPHOME_LOG_TAG(TAG, "lm75b");
9
11 ESP_LOGCONFIG(TAG, "LM75B:");
12 LOG_I2C_DEVICE(this);
13 LOG_UPDATE_INTERVAL(this);
14 LOG_SENSOR(" ", "Temperature", this);
15}
16
18 // Create a temporary buffer
19 uint8_t buff[2];
20 if (this->read_register(LM75B_REG_TEMPERATURE, buff, 2) != i2c::ERROR_OK) {
21 this->status_set_warning();
22 return;
23 }
24 // Obtain combined 16-bit value
25 int16_t raw_temperature = encode_value<int16_t>(buff);
26 // Read the 11-bit raw temperature value
27 raw_temperature >>= 5;
28 // Publish the temperature in °C
29 this->publish_state(raw_temperature * 0.125);
30 if (this->status_has_warning()) {
32 }
33}
34
35} // namespace esphome::lm75b
bool status_has_warning() const
Definition component.h:280
void status_clear_warning()
Definition component.h:296
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
Definition i2c.cpp:28
void dump_config() override
Definition lm75b.cpp:10
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:15
ESPHOME_LOG_TAG(TAG, "lm75b")
constexpr T encode_value(const uint8_t *bytes)
Encode a value from its constituent bytes (from most to least significant) in an array with length si...
Definition helpers.h:1019