7 static const char *
const TAG =
"sfa30";
9 static const uint16_t SFA30_CMD_GET_DEVICE_MARKING = 0xD060;
10 static const uint16_t SFA30_CMD_START_CONTINUOUS_MEASUREMENTS = 0x0006;
11 static const uint16_t SFA30_CMD_READ_MEASUREMENT = 0x0327;
14 ESP_LOGCONFIG(TAG,
"Setting up sfa30...");
17 uint16_t raw_device_marking[16];
18 if (!this->
get_register(SFA30_CMD_GET_DEVICE_MARKING, raw_device_marking, 16, 5)) {
19 ESP_LOGE(TAG,
"Failed to read device marking");
25 for (
size_t i = 0; i < 16; i++) {
26 this->
device_marking_[i * 2] =
static_cast<char>(raw_device_marking[i] >> 8);
27 this->
device_marking_[i * 2 + 1] =
static_cast<char>(raw_device_marking[i] & 0xFF);
31 if (!this->
write_command(SFA30_CMD_START_CONTINUOUS_MEASUREMENTS)) {
32 ESP_LOGE(TAG,
"Error starting measurements.");
38 ESP_LOGD(TAG,
"Sensor initialized");
42 ESP_LOGCONFIG(TAG,
"sfa30:");
46 case DEVICE_MARKING_READ_FAILED:
47 ESP_LOGW(TAG,
"Unable to read device marking!");
49 case MEASUREMENT_INIT_FAILED:
50 ESP_LOGW(TAG,
"Measurement initialization failed!");
53 ESP_LOGW(TAG,
"Unknown setup error!");
57 LOG_UPDATE_INTERVAL(
this);
66 ESP_LOGW(TAG,
"Error reading measurement!");
74 ESP_LOGW(TAG,
"Error reading measurement data!");
80 const float formaldehyde = raw_data[0] / 5.0f;
85 const float humidity = raw_data[1] / 100.0f;
void status_set_warning(const char *message="unspecified")
bool write_command(T i2c_register)
Write a command to the i2c device.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_data(uint16_t *data, uint8_t len)
Read data words from i2c device.
void dump_config() override
sensor::Sensor * temperature_sensor_
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * formaldehyde_sensor_
bool get_register(uint16_t command, uint16_t *data, uint8_t len, uint8_t delay=0)
get data words from i2c register.
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
sensor::Sensor * humidity_sensor_