ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
sen0321
sen0321.cpp
Go to the documentation of this file.
1
#include "
sen0321.h
"
2
#include "
esphome/core/log.h
"
3
#include "
esphome/core/hal.h
"
4
5
namespace
esphome::sen0321_sensor
{
6
7
static
const
char
*
const
TAG =
"sen0321_sensor.sensor"
;
8
9
void
Sen0321Sensor::setup
() {
10
if
(!this->
write_byte
(SENSOR_MODE_REGISTER, SENSOR_MODE_AUTO)) {
11
ESP_LOGW(TAG,
"Error setting measurement mode."
);
12
this->
mark_failed
();
13
};
14
}
15
16
void
Sen0321Sensor::update
() { this->
read_data_
(); }
17
18
void
Sen0321Sensor::dump_config
() {
19
ESP_LOGCONFIG(TAG,
"DF Robot Ozone Sensor sen0321:"
);
20
LOG_I2C_DEVICE(
this
);
21
if
(this->
is_failed
()) {
22
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
23
}
24
LOG_UPDATE_INTERVAL(
this
);
25
}
26
27
void
Sen0321Sensor::read_data_
() {
28
uint8_t result[2];
29
this->
read_bytes
(SENSOR_AUTO_READ_REG, result, (uint8_t) 2);
30
this->
publish_state
(((uint16_t) (result[0] << 8) + result[1]));
31
}
32
33
}
// namespace esphome::sen0321_sensor
esphome::Component::mark_failed
void mark_failed()
Mark this component as failed.
Definition
component.cpp:274
esphome::Component::is_failed
bool is_failed() const
Definition
component.h:272
esphome::i2c::I2CDevice::write_byte
bool write_byte(uint8_t a_register, uint8_t data) const
Definition
i2c.h:265
esphome::i2c::I2CDevice::read_bytes
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Definition
i2c.h:217
esphome::sen0321_sensor::Sen0321Sensor::update
void update() override
Definition
sen0321.cpp:16
esphome::sen0321_sensor::Sen0321Sensor::dump_config
void dump_config() override
Definition
sen0321.cpp:18
esphome::sen0321_sensor::Sen0321Sensor::read_data_
void read_data_()
Definition
sen0321.cpp:27
esphome::sen0321_sensor::Sen0321Sensor::setup
void setup() override
Definition
sen0321.cpp:9
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:68
hal.h
log.h
esphome::sen0321_sensor
Definition
sen0321.cpp:5
sen0321.h
Generated by
1.12.0