ESPHome  2024.12.2
sen21231.cpp
Go to the documentation of this file.
1 #include "sen21231.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace sen21231_sensor {
6 
7 static const char *const TAG = "sen21231_sensor.sensor";
8 
9 void Sen21231Sensor::update() { this->read_data_(); }
10 
12  ESP_LOGCONFIG(TAG, "SEN21231:");
13  LOG_I2C_DEVICE(this);
14  if (this->is_failed()) {
15  ESP_LOGE(TAG, "Communication with SEN21231 failed!");
16  }
17  ESP_LOGI(TAG, "SEN21231: %s", this->is_failed() ? "FAILED" : "OK");
18  LOG_UPDATE_INTERVAL(this);
19 }
20 
23  this->read_bytes(PERSON_SENSOR_I2C_ADDRESS, (uint8_t *) &results, sizeof(results));
24  ESP_LOGD(TAG, "SEN21231: %d faces detected", results.num_faces);
25  this->publish_state(results.num_faces);
26  if (results.num_faces == 1) {
27  ESP_LOGD(TAG, "SEN21231: is facing towards camera: %d", results.faces[0].is_facing);
28  }
29 }
30 
31 } // namespace sen21231_sensor
32 } // namespace esphome
bool is_failed() const
Definition: component.cpp:143
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:212
struct __attribute__((__packed__)) { person_sensor_results_header_t header person_sensor_results_t
Definition: sen21231.h:61
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7