ESPHome 2025.5.0
Loading...
Searching...
No Matches
sen21231.h
Go to the documentation of this file.
1#pragma once
2
6
7// ref:
8// https://github.com/usefulsensors/person_sensor_pico_c/blob/main/person_sensor.h
9
10namespace esphome {
11namespace sen21231_sensor {
12// The I2C address of the person sensor board.
13static const uint8_t PERSON_SENSOR_I2C_ADDRESS = 0x62;
14static const uint8_t PERSON_SENSOR_REG_MODE = 0x01;
15static const uint8_t PERSON_SENSOR_REG_ENABLE_ID = 0x02;
16static const uint8_t PERSON_SENSOR_REG_SINGLE_SHOT = 0x03;
17static const uint8_t PERSON_SENSOR_REG_CALIBRATE_ID = 0x04;
18static const uint8_t PERSON_SENSOR_REG_PERSIST_IDS = 0x05;
19static const uint8_t PERSON_SENSOR_REG_ERASE_IDS = 0x06;
20static const uint8_t PERSON_SENSOR_REG_DEBUG_MODE = 0x07;
21
22static const uint8_t PERSON_SENSOR_MAX_FACES_COUNT = 4;
23static const uint8_t PERSON_SENSOR_MAX_IDS_COUNT = 7;
24
25// The results returned from the sensor have a short header providing
26// information about the length of the data packet:
27// reserved: Currently unused bytes.
28// data_size: Length of the entire packet, excluding the header and
29// checksum.
30// For version 1.0 of the sensor, this should be 40.
32 uint8_t reserved[2]; // Bytes 0-1.
33 uint16_t data_size; // Bytes 2-3.
34};
35
36// Each face found has a set of information associated with it:
37// box_confidence: How certain we are we have found a face, from 0 to 255.
38// box_left: X coordinate of the left side of the box, from 0 to 255.
39// box_top: Y coordinate of the top edge of the box, from 0 to 255.
40// box_width: Width of the box, where 255 is the full view port size.
41// box_height: Height of the box, where 255 is the full view port size.
42// id_confidence: How sure the sensor is about the recognition result.
43// id: Numerical ID assigned to this face.
44// is_looking_at: Whether the person is facing the camera, 0 or 1.
45using person_sensor_face_t = struct __attribute__((__packed__)) {
46 uint8_t box_confidence; // Byte 1.
47 uint8_t box_left; // Byte 2.
48 uint8_t box_top; // Byte 3.
49 uint8_t box_right; // Byte 4.
50 uint8_t box_bottom; // Byte 5.
51 int8_t id_confidence; // Byte 6.
52 int8_t id; // Byte 7
53 uint8_t is_facing; // Byte 8.
54};
55
56// This is the full structure of the packet returned over the wire from the
57// sensor when we do an I2C read from the peripheral address.
58// The checksum should be the CRC16 of bytes 0 to 38. You shouldn't need to
59// verify this in practice, but we found it useful during our own debugging.
60using person_sensor_results_t = struct __attribute__((__packed__)) {
61 person_sensor_results_header_t header; // Bytes 0-4.
62 int8_t num_faces; // Byte 5.
63 person_sensor_face_t faces[PERSON_SENSOR_MAX_FACES_COUNT]; // Bytes 6-37.
64 uint16_t checksum; // Bytes 38-39.
65};
66
68 public:
69 void update() override;
70 void dump_config() override;
71
72 protected:
73 void read_data_();
74};
75
76} // namespace sen21231_sensor
77} // namespace esphome
uint8_t checksum
Definition bl0906.h:3
This class simplifies creating components that periodically check a state.
Definition component.h:301
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:57
struct @67::@68 __attribute__
uint16_t reserved
struct __attribute__((__packed__)) { person_sensor_results_header_t header; int8_t num_faces; person_sensor_face_t faces[PERSON_SENSOR_MAX_FACES_COUNT]; uint16_t checksum; } person_sensor_results_t
Definition sen21231.h:60
struct __attribute__((__packed__)) { uint8_t box_confidence; uint8_t box_left; uint8_t box_top; uint8_t box_right; uint8_t box_bottom; int8_t id_confidence; int8_t id; uint8_t is_facing; } person_sensor_face_t
Definition sen21231.h:45
struct { uint8_t reserved[2]; uint16_t data_size; } person_sensor_results_header_t
Definition sen21231.h:31
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7