ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
hlk_fm22x.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <utility>
12
13namespace esphome::hlk_fm22x {
14
15static const uint16_t START_CODE = 0xEFAA;
16static constexpr size_t HLK_FM22X_NAME_SIZE = 32;
17// Maximum response payload: command(1) + result(1) + face_id(2) + name(32) = 36
18static constexpr size_t HLK_FM22X_MAX_RESPONSE_SIZE = 36;
20 NONE = 0x00,
21 RESET = 0x10,
22 GET_STATUS = 0x11,
23 VERIFY = 0x12,
24 ENROLL = 0x13,
30};
31
33 REPLY = 0x00,
34 NOTE = 0x01,
35 IMAGE = 0x02,
36};
37
39 READY = 0x00,
40 FACE_STATE = 0x01,
41};
42
64
73
75 public:
76 void setup() override;
77 void update() override;
78 void dump_config() override;
79
80 void set_face_count_sensor(sensor::Sensor *face_count_sensor) { this->face_count_sensor_ = face_count_sensor; }
81 void set_status_sensor(sensor::Sensor *status_sensor) { this->status_sensor_ = status_sensor; }
82 void set_last_face_id_sensor(sensor::Sensor *last_face_id_sensor) {
83 this->last_face_id_sensor_ = last_face_id_sensor;
84 }
85 void set_last_face_name_text_sensor(text_sensor::TextSensor *last_face_name_text_sensor) {
86 this->last_face_name_text_sensor_ = last_face_name_text_sensor;
87 }
89 this->enrolling_binary_sensor_ = enrolling_binary_sensor;
90 }
92 this->version_text_sensor_ = version_text_sensor;
93 }
94 template<typename F> void add_on_face_scan_matched_callback(F &&callback) {
95 this->face_scan_matched_callback_.add(std::forward<F>(callback));
96 }
97 template<typename F> void add_on_face_scan_unmatched_callback(F &&callback) {
98 this->face_scan_unmatched_callback_.add(std::forward<F>(callback));
99 }
100 template<typename F> void add_on_face_scan_invalid_callback(F &&callback) {
101 this->face_scan_invalid_callback_.add(std::forward<F>(callback));
102 }
103 template<typename F> void add_on_face_info_callback(F &&callback) {
104 this->face_info_callback_.add(std::forward<F>(callback));
105 }
106 template<typename F> void add_on_enrollment_done_callback(F &&callback) {
107 this->enrollment_done_callback_.add(std::forward<F>(callback));
108 }
109 template<typename F> void add_on_enrollment_failed_callback(F &&callback) {
110 this->enrollment_failed_callback_.add(std::forward<F>(callback));
111 }
112
113 void enroll_face(const std::string &name, HlkFm22xFaceDirection direction);
114 void scan_face();
115 void delete_face(int16_t face_id);
116 void delete_all_faces();
117 void reset();
118
119 protected:
120 void get_face_count_();
121 void send_command_(HlkFm22xCommand command, const uint8_t *data = nullptr, size_t size = 0);
122 void recv_command_();
123 void handle_note_(const uint8_t *data, size_t length);
124 void handle_reply_(const uint8_t *data, size_t length);
125 void set_enrolling_(bool enrolling);
126
127 std::array<uint8_t, HLK_FM22X_MAX_RESPONSE_SIZE> recv_buf_;
129 uint16_t wait_cycles_ = 0;
137 CallbackManager<void(int16_t, std::string)> face_scan_matched_callback_;
139 CallbackManager<void(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t)> face_info_callback_;
142};
143
144} // namespace esphome::hlk_fm22x
This class simplifies creating components that periodically check a state.
Definition component.h:519
Base class for all binary_sensor-type classes.
void delete_face(int16_t face_id)
Definition hlk_fm22x.cpp:54
void handle_reply_(const uint8_t *data, size_t length)
text_sensor::TextSensor * last_face_name_text_sensor_
Definition hlk_fm22x.h:134
void add_on_enrollment_failed_callback(F &&callback)
Definition hlk_fm22x.h:109
void add_on_face_scan_matched_callback(F &&callback)
Definition hlk_fm22x.h:94
CallbackManager< void(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, int16_t)> face_info_callback_
Definition hlk_fm22x.h:139
void enroll_face(const std::string &name, HlkFm22xFaceDirection direction)
Definition hlk_fm22x.cpp:32
void send_command_(HlkFm22xCommand command, const uint8_t *data=nullptr, size_t size=0)
Definition hlk_fm22x.cpp:78
CallbackManager< void(uint8_t)> face_scan_invalid_callback_
Definition hlk_fm22x.h:136
std::array< uint8_t, HLK_FM22X_MAX_RESPONSE_SIZE > recv_buf_
Definition hlk_fm22x.h:127
void set_face_count_sensor(sensor::Sensor *face_count_sensor)
Definition hlk_fm22x.h:80
CallbackManager< void()> face_scan_unmatched_callback_
Definition hlk_fm22x.h:138
void set_enrolling_binary_sensor(binary_sensor::BinarySensor *enrolling_binary_sensor)
Definition hlk_fm22x.h:88
void set_version_text_sensor(text_sensor::TextSensor *version_text_sensor)
Definition hlk_fm22x.h:91
void add_on_face_scan_unmatched_callback(F &&callback)
Definition hlk_fm22x.h:97
CallbackManager< void(int16_t, uint8_t)> enrollment_done_callback_
Definition hlk_fm22x.h:140
void set_last_face_id_sensor(sensor::Sensor *last_face_id_sensor)
Definition hlk_fm22x.h:82
void add_on_face_info_callback(F &&callback)
Definition hlk_fm22x.h:103
CallbackManager< void(uint8_t)> enrollment_failed_callback_
Definition hlk_fm22x.h:141
void add_on_face_scan_invalid_callback(F &&callback)
Definition hlk_fm22x.h:100
text_sensor::TextSensor * version_text_sensor_
Definition hlk_fm22x.h:135
void handle_note_(const uint8_t *data, size_t length)
void set_last_face_name_text_sensor(text_sensor::TextSensor *last_face_name_text_sensor)
Definition hlk_fm22x.h:85
void add_on_enrollment_done_callback(F &&callback)
Definition hlk_fm22x.h:106
CallbackManager< void(int16_t, std::string)> face_scan_matched_callback_
Definition hlk_fm22x.h:137
binary_sensor::BinarySensor * enrolling_binary_sensor_
Definition hlk_fm22x.h:133
void set_status_sensor(sensor::Sensor *status_sensor)
Definition hlk_fm22x.h:81
Base-class for all sensors.
Definition sensor.h:47
FanDirection direction
Definition fan.h:5
uint16_t size
Definition helpers.cpp:34