ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
fingerprint_grow.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <limits>
10#include <vector>
11
13
14static const uint16_t START_CODE = 0xEF01;
15
16static const uint16_t ENROLLMENT_SLOT_UNUSED = 0xFFFF;
17
18// The datasheet says a max wake up time of of 200ms.
19static const uint8_t WAIT_FOR_WAKE_UP_MS = 200;
20
21static const uint32_t DEFAULT_IDLE_PERIOD_TO_SLEEP_MS = 5000;
22
24 COMMAND = 0x01,
25 DATA = 0x02,
26 ACK = 0x07,
27 END_DATA = 0x08,
28};
29
31 GET_IMAGE = 0x01,
32 IMAGE_2_TZ = 0x02,
33 SEARCH = 0x04,
34 REG_MODEL = 0x05,
35 STORE = 0x06,
36 LOAD = 0x07,
37 UPLOAD = 0x08,
38 DELETE = 0x0C,
39 DELETE_ALL = 0x0D, // aka EMPTY
46 LED_ON = 0x50,
47 LED_OFF = 0x51,
48};
49
75
77 BREATHING = 0x01,
78 FLASHING = 0x02,
79 ALWAYS_ON = 0x03,
80 ALWAYS_OFF = 0x04,
81 GRADUAL_ON = 0x05,
83};
84
86 RED = 0x01,
87 BLUE = 0x02,
88 PURPLE = 0x03,
89 GREEN = 0x04,
90 YELLOW = 0x05,
91 CYAN = 0x06,
92 WHITE = 0x07,
93};
94
96 public:
97 void update() override;
98 void setup() override;
99 void dump_config() override;
100
102 this->address_[0] = (uint8_t) (address >> 24);
103 this->address_[1] = (uint8_t) (address >> 16);
104 this->address_[2] = (uint8_t) (address >> 8);
105 this->address_[3] = (uint8_t) (address & 0xFF);
106 }
107 void set_sensing_pin(GPIOPin *sensing_pin) { this->sensing_pin_ = sensing_pin; }
108 void set_sensor_power_pin(GPIOPin *sensor_power_pin) { this->sensor_power_pin_ = sensor_power_pin; }
109 void set_password(uint32_t password) { this->password_ = password; }
110 void set_new_password(uint32_t new_password) { this->new_password_ = new_password; }
111 void set_idle_period_to_sleep_ms(uint32_t period_ms) { this->idle_period_to_sleep_ms_ = period_ms; }
112 void set_fingerprint_count_sensor(sensor::Sensor *fingerprint_count_sensor) {
113 this->fingerprint_count_sensor_ = fingerprint_count_sensor;
114 }
115 void set_status_sensor(sensor::Sensor *status_sensor) { this->status_sensor_ = status_sensor; }
116 void set_capacity_sensor(sensor::Sensor *capacity_sensor) { this->capacity_sensor_ = capacity_sensor; }
117 void set_security_level_sensor(sensor::Sensor *security_level_sensor) {
118 this->security_level_sensor_ = security_level_sensor;
119 }
120 void set_last_finger_id_sensor(sensor::Sensor *last_finger_id_sensor) {
121 this->last_finger_id_sensor_ = last_finger_id_sensor;
122 }
123 void set_last_confidence_sensor(sensor::Sensor *last_confidence_sensor) {
124 this->last_confidence_sensor_ = last_confidence_sensor;
125 }
127 this->enrolling_binary_sensor_ = enrolling_binary_sensor;
128 }
129 template<typename F> void add_on_finger_scan_start_callback(F &&callback) {
130 this->finger_scan_start_callback_.add(std::forward<F>(callback));
131 }
132 template<typename F> void add_on_finger_scan_matched_callback(F &&callback) {
133 this->finger_scan_matched_callback_.add(std::forward<F>(callback));
134 }
135 template<typename F> void add_on_finger_scan_unmatched_callback(F &&callback) {
136 this->finger_scan_unmatched_callback_.add(std::forward<F>(callback));
137 }
138 template<typename F> void add_on_finger_scan_misplaced_callback(F &&callback) {
139 this->finger_scan_misplaced_callback_.add(std::forward<F>(callback));
140 }
141 template<typename F> void add_on_finger_scan_invalid_callback(F &&callback) {
142 this->finger_scan_invalid_callback_.add(std::forward<F>(callback));
143 }
144 template<typename F> void add_on_enrollment_scan_callback(F &&callback) {
145 this->enrollment_scan_callback_.add(std::forward<F>(callback));
146 }
147 template<typename F> void add_on_enrollment_done_callback(F &&callback) {
148 this->enrollment_done_callback_.add(std::forward<F>(callback));
149 }
150
151 template<typename F> void add_on_enrollment_failed_callback(F &&callback) {
152 this->enrollment_failed_callback_.add(std::forward<F>(callback));
153 }
154
155 void enroll_fingerprint(uint16_t finger_id, uint8_t num_buffers);
156 void finish_enrollment(uint8_t result);
157 void delete_fingerprint(uint16_t finger_id);
159
160 void led_control(bool state);
161 void aura_led_control(uint8_t state, uint8_t speed, uint8_t color, uint8_t count);
162
163 protected:
164 void scan_and_match_();
165 uint8_t scan_image_(uint8_t buffer);
166 uint8_t save_fingerprint_();
167 bool check_password_();
168 bool set_password_();
169 bool get_parameters_();
171 uint8_t transfer_(std::vector<uint8_t> &data_buffer);
172 uint8_t send_command_();
173 void sensor_wakeup_();
174 void sensor_sleep_();
175
176 std::vector<uint8_t> data_ = {};
177 uint8_t address_[4] = {0xFF, 0xFF, 0xFF, 0xFF};
178 uint16_t capacity_ = 64;
180 uint32_t new_password_ = std::numeric_limits<uint32_t>::max();
183 uint8_t enrollment_image_ = 0;
184 uint16_t enrollment_slot_ = ENROLLMENT_SLOT_UNUSED;
186 bool waiting_removal_ = false;
187 bool has_sensing_pin_ = false;
188 bool has_power_pin_ = false;
189 bool is_sensor_awake_ = false;
210};
211
212template<typename... Ts> class EnrollmentAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
213 public:
214 TEMPLATABLE_VALUE(uint16_t, finger_id)
215 TEMPLATABLE_VALUE(uint8_t, num_scans)
216
217 void play(const Ts &...x) override {
218 auto finger_id = this->finger_id_.value(x...);
219 auto num_scans = this->num_scans_.value(x...);
220 if (num_scans) {
221 this->parent_->enroll_fingerprint(finger_id, num_scans);
222 } else {
223 this->parent_->enroll_fingerprint(finger_id, 2);
224 }
225 }
226};
227
228template<typename... Ts>
229class CancelEnrollmentAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
230 public:
231 void play(const Ts &...x) override { this->parent_->finish_enrollment(1); }
232};
233
234template<typename... Ts> class DeleteAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
235 public:
236 TEMPLATABLE_VALUE(uint16_t, finger_id)
237
238 void play(const Ts &...x) override {
239 auto finger_id = this->finger_id_.value(x...);
240 this->parent_->delete_fingerprint(finger_id);
241 }
242};
243
244template<typename... Ts> class DeleteAllAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
245 public:
246 void play(const Ts &...x) override { this->parent_->delete_all_fingerprints(); }
247};
248
249template<typename... Ts> class LEDControlAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
250 public:
252
253 void play(const Ts &...x) override {
254 auto state = this->state_.value(x...);
255 this->parent_->led_control(state);
256 }
257};
258
259template<typename... Ts> class AuraLEDControlAction : public Action<Ts...>, public Parented<FingerprintGrowComponent> {
260 public:
262 TEMPLATABLE_VALUE(uint8_t, speed)
263 TEMPLATABLE_VALUE(uint8_t, color)
264 TEMPLATABLE_VALUE(uint8_t, count)
265
266 void play(const Ts &...x) override {
267 auto state = this->state_.value(x...);
268 auto speed = this->speed_.value(x...);
269 auto color = this->color_.value(x...);
270 auto count = this->count_.value(x...);
271
272 this->parent_->aura_led_control(state, speed, color, count);
273 }
274};
275
276} // namespace esphome::fingerprint_grow
uint8_t address
Definition bl0906.h:4
virtual void play(const Ts &...x)=0
Helper class to easily give an object a parent of type T.
Definition helpers.h:1861
This class simplifies creating components that periodically check a state.
Definition component.h:585
Base class for all binary_sensor-type classes.
TEMPLATABLE_VALUE(uint8_t, state) TEMPLATABLE_VALUE(uint8_t
speed count void play(const Ts &...x) override
TEMPLATABLE_VALUE(uint16_t, finger_id) void play(const Ts &...x) override
num_scans void play(const Ts &...x) override
TEMPLATABLE_VALUE(uint16_t, finger_id) TEMPLATABLE_VALUE(uint8_t
CallbackManager< void(uint16_t, uint16_t)> finger_scan_matched_callback_
uint8_t transfer_(std::vector< uint8_t > &data_buffer)
void set_last_confidence_sensor(sensor::Sensor *last_confidence_sensor)
void set_capacity_sensor(sensor::Sensor *capacity_sensor)
void enroll_fingerprint(uint16_t finger_id, uint8_t num_buffers)
CallbackManager< void(uint16_t)> enrollment_done_callback_
CallbackManager< void(uint16_t)> enrollment_failed_callback_
void set_fingerprint_count_sensor(sensor::Sensor *fingerprint_count_sensor)
void aura_led_control(uint8_t state, uint8_t speed, uint8_t color, uint8_t count)
CallbackManager< void(uint8_t, uint16_t)> enrollment_scan_callback_
void set_security_level_sensor(sensor::Sensor *security_level_sensor)
void set_last_finger_id_sensor(sensor::Sensor *last_finger_id_sensor)
void set_enrolling_binary_sensor(binary_sensor::BinarySensor *enrolling_binary_sensor)
void set_status_sensor(sensor::Sensor *status_sensor)
TEMPLATABLE_VALUE(bool, state) void play(const Ts &...x) override
Base-class for all sensors.
Definition sensor.h:47
int speed
Definition fan.h:3
bool state
Definition fan.h:2
if(written< 0)
Definition helpers.h:1047
static void uint32_t
uint16_t x
Definition tt21100.cpp:5