ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
fingerprint_grow.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <limits>
9#include <vector>
10
12
13static const uint16_t START_CODE = 0xEF01;
14
15static const uint16_t ENROLLMENT_SLOT_UNUSED = 0xFFFF;
16
17// The datasheet says a max wake up time of of 200ms.
18static const uint8_t WAIT_FOR_WAKE_UP_MS = 200;
19
20static const uint32_t DEFAULT_IDLE_PERIOD_TO_SLEEP_MS = 5000;
21
23 COMMAND = 0x01,
24 DATA = 0x02,
25 ACK = 0x07,
26 END_DATA = 0x08,
27};
28
30 GET_IMAGE = 0x01,
31 IMAGE_2_TZ = 0x02,
32 SEARCH = 0x04,
33 REG_MODEL = 0x05,
34 STORE = 0x06,
35 LOAD = 0x07,
36 UPLOAD = 0x08,
37 DELETE = 0x0C,
38 DELETE_ALL = 0x0D, // aka EMPTY
45 LED_ON = 0x50,
46 LED_OFF = 0x51,
47};
48
74
76 BREATHING = 0x01,
77 FLASHING = 0x02,
78 ALWAYS_ON = 0x03,
79 ALWAYS_OFF = 0x04,
80 GRADUAL_ON = 0x05,
82};
83
85 RED = 0x01,
86 BLUE = 0x02,
87 PURPLE = 0x03,
88 GREEN = 0x04,
89 YELLOW = 0x05,
90 CYAN = 0x06,
91 WHITE = 0x07,
92};
93
95 public:
96 void update() override;
97 void setup() override;
98 void dump_config() override;
99
101 this->address_[0] = (uint8_t) (address >> 24);
102 this->address_[1] = (uint8_t) (address >> 16);
103 this->address_[2] = (uint8_t) (address >> 8);
104 this->address_[3] = (uint8_t) (address & 0xFF);
105 }
106 void set_sensing_pin(GPIOPin *sensing_pin) { this->sensing_pin_ = sensing_pin; }
107 void set_sensor_power_pin(GPIOPin *sensor_power_pin) { this->sensor_power_pin_ = sensor_power_pin; }
108 void set_password(uint32_t password) { this->password_ = password; }
109 void set_new_password(uint32_t new_password) { this->new_password_ = new_password; }
110 void set_idle_period_to_sleep_ms(uint32_t period_ms) { this->idle_period_to_sleep_ms_ = period_ms; }
111 void set_fingerprint_count_sensor(sensor::Sensor *fingerprint_count_sensor) {
112 this->fingerprint_count_sensor_ = fingerprint_count_sensor;
113 }
114 void set_status_sensor(sensor::Sensor *status_sensor) { this->status_sensor_ = status_sensor; }
115 void set_capacity_sensor(sensor::Sensor *capacity_sensor) { this->capacity_sensor_ = capacity_sensor; }
116 void set_security_level_sensor(sensor::Sensor *security_level_sensor) {
117 this->security_level_sensor_ = security_level_sensor;
118 }
119 void set_last_finger_id_sensor(sensor::Sensor *last_finger_id_sensor) {
120 this->last_finger_id_sensor_ = last_finger_id_sensor;
121 }
122 void set_last_confidence_sensor(sensor::Sensor *last_confidence_sensor) {
123 this->last_confidence_sensor_ = last_confidence_sensor;
124 }
126 this->enrolling_binary_sensor_ = enrolling_binary_sensor;
127 }
128 template<typename F> void add_on_finger_scan_start_callback(F &&callback) {
129 this->finger_scan_start_callback_.add(std::forward<F>(callback));
130 }
131 template<typename F> void add_on_finger_scan_matched_callback(F &&callback) {
132 this->finger_scan_matched_callback_.add(std::forward<F>(callback));
133 }
134 template<typename F> void add_on_finger_scan_unmatched_callback(F &&callback) {
135 this->finger_scan_unmatched_callback_.add(std::forward<F>(callback));
136 }
137 template<typename F> void add_on_finger_scan_misplaced_callback(F &&callback) {
138 this->finger_scan_misplaced_callback_.add(std::forward<F>(callback));
139 }
140 template<typename F> void add_on_finger_scan_invalid_callback(F &&callback) {
141 this->finger_scan_invalid_callback_.add(std::forward<F>(callback));
142 }
143 template<typename F> void add_on_enrollment_scan_callback(F &&callback) {
144 this->enrollment_scan_callback_.add(std::forward<F>(callback));
145 }
146 template<typename F> void add_on_enrollment_done_callback(F &&callback) {
147 this->enrollment_done_callback_.add(std::forward<F>(callback));
148 }
149
150 template<typename F> void add_on_enrollment_failed_callback(F &&callback) {
151 this->enrollment_failed_callback_.add(std::forward<F>(callback));
152 }
153
154 void enroll_fingerprint(uint16_t finger_id, uint8_t num_buffers);
155 void finish_enrollment(uint8_t result);
156 void delete_fingerprint(uint16_t finger_id);
158
159 void led_control(bool state);
160 void aura_led_control(uint8_t state, uint8_t speed, uint8_t color, uint8_t count);
161
162 protected:
163 void scan_and_match_();
164 uint8_t scan_image_(uint8_t buffer);
165 uint8_t save_fingerprint_();
166 bool check_password_();
167 bool set_password_();
168 bool get_parameters_();
170 uint8_t transfer_(std::vector<uint8_t> &data_buffer);
171 uint8_t send_command_();
172 void sensor_wakeup_();
173 void sensor_sleep_();
174
175 std::vector<uint8_t> data_ = {};
176 uint8_t address_[4] = {0xFF, 0xFF, 0xFF, 0xFF};
177 uint16_t capacity_ = 64;
179 uint32_t new_password_ = std::numeric_limits<uint32_t>::max();
182 uint8_t enrollment_image_ = 0;
183 uint16_t enrollment_slot_ = ENROLLMENT_SLOT_UNUSED;
185 bool waiting_removal_ = false;
186 bool has_sensing_pin_ = false;
187 bool has_power_pin_ = false;
188 bool is_sensor_awake_ = false;
209};
210
211} // namespace esphome::fingerprint_grow
uint8_t address
Definition bl0906.h:4
This class simplifies creating components that periodically check a state.
Definition component.h:519
Base class for all binary_sensor-type classes.
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)
Base-class for all sensors.
Definition sensor.h:47
bool state
Definition fan.h:2
unsigned count
Definition gif.cpp:51
uint32_t buffer
Definition gif.cpp:50
static void uint32_t