5 namespace dallas_temp {
7 static const char *
const TAG =
"dallas.temp.sensor";
9 static const uint8_t DALLAS_MODEL_DS18S20 = 0x10;
10 static const uint8_t DALLAS_COMMAND_START_CONVERSION = 0x44;
11 static const uint8_t DALLAS_COMMAND_READ_SCRATCH_PAD = 0xBE;
12 static const uint8_t DALLAS_COMMAND_WRITE_SCRATCH_PAD = 0x4E;
13 static const uint8_t DALLAS_COMMAND_COPY_SCRATCH_PAD = 0x48;
29 ESP_LOGCONFIG(TAG,
"Dallas Temperature Sensor:");
31 ESP_LOGW(TAG,
" Unable to select an address");
34 LOG_ONE_WIRE_DEVICE(
this);
35 ESP_LOGCONFIG(TAG,
" Resolution: %u bits", this->
resolution_);
36 LOG_UPDATE_INTERVAL(
this);
54 ESP_LOGD(TAG,
"'%s': Got Temperature=%.1f°C", this->
get_name().c_str(), tempc);
69 success = this->
send_command_(DALLAS_COMMAND_READ_SCRATCH_PAD);
74 ESP_LOGW(TAG,
"'%s' - reading scratch pad failed bus reset", this->
get_name().c_str());
81 ESP_LOGCONFIG(TAG,
"setting up Dallas temperature sensor...");
89 if ((this->
address_ & 0xff) == DALLAS_MODEL_DS18S20) {
91 ESP_LOGW(TAG,
"DS18S20 doesn't support setting resolution.");
132 #ifdef ESPHOME_LOG_LEVEL_VERY_VERBOSE 133 ESP_LOGVV(TAG,
"Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->
scratch_pad_[0],
138 if (!chksum_validity) {
139 ESP_LOGW(TAG,
"'%s' - Scratch pad checksum invalid!", this->
get_name().c_str());
142 return chksum_validity;
147 if ((this->
address_ & 0xff) == DALLAS_MODEL_DS18S20) {
void read_scratch_pad_int_()
void status_set_warning(const char *message="unspecified")
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool check_scratch_pad_()
uint8_t crc8(const uint8_t *data, uint8_t len)
Calculate a CRC-8 checksum of data with size len.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
virtual void write8(uint8_t val)=0
Write a word to the bus. LSB first.
Helper class to disable interrupts.
bool check_address_()
find an address if necessary should be called from setup
const std::string & get_address_name()
Helper to create (and cache) the name for this sensor. For example "0xfe0000031f1eaf29".
void dump_config() override
Implementation of SPI Controller mode.
OneWireBus * bus_
pointer to OneWireBus instance
virtual uint8_t read8()=0
Read an 8 bit word from the bus.
bool send_command_(uint8_t cmd)
send command on the bus
const StringRef & get_name() const
uint16_t millis_to_wait_for_conversion_() const
Get the number of milliseconds we have to wait for the conversion phase.