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