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