6 namespace fingerprint_grow {
8 static const char *
const TAG =
"fingerprint_grow";
21 ESP_LOGV(TAG,
"No touch sensing");
35 ESP_LOGD(TAG,
"Finger removed");
60 ESP_LOGCONFIG(TAG,
"Setting up Grow Fingerprint Reader...");
97 ESP_LOGI(TAG,
"Starting enrollment in slot %d", finger_id);
120 ESP_LOGI(TAG,
"Finished enrollment");
125 ESP_LOGD(TAG,
"Scan and match");
127 ESP_LOGV(TAG,
"Scan and match");
134 ESP_LOGD(TAG,
"Fingerprint matched");
135 uint16_t finger_id = ((uint16_t) this->
data_[1] << 8) | this->
data_[2];
136 uint16_t confidence = ((uint16_t) this->
data_[3] << 8) | this->
data_[4];
147 ESP_LOGD(TAG,
"Fingerprint not matched to any saved slots");
156 ESP_LOGD(TAG,
"Getting image %d", buffer);
158 ESP_LOGV(TAG,
"Getting image %d", buffer);
162 switch (send_result) {
168 ESP_LOGD(TAG,
"Finger Misplaced");
171 ESP_LOGV(TAG,
"No finger");
175 ESP_LOGE(TAG,
"Imaging error");
179 ESP_LOGD(TAG,
"Unknown Scan Error: %d", send_result);
183 ESP_LOGD(TAG,
"Processing image %d", buffer);
186 switch (send_result) {
188 ESP_LOGI(TAG,
"Processed image %d", buffer);
191 ESP_LOGE(TAG,
"Image too messy");
196 ESP_LOGE(TAG,
"Could not find fingerprint features");
204 ESP_LOGI(TAG,
"Creating model");
210 ESP_LOGE(TAG,
"Scans do not match");
212 return this->
data_[0];
215 ESP_LOGI(TAG,
"Storing model");
219 ESP_LOGI(TAG,
"Stored model");
222 ESP_LOGE(TAG,
"Invalid slot");
225 ESP_LOGE(TAG,
"Error writing to flash");
228 return this->
data_[0];
232 ESP_LOGD(TAG,
"Checking password");
237 ESP_LOGD(TAG,
"Password verified");
240 ESP_LOGE(TAG,
"Wrong password");
247 ESP_LOGI(TAG,
"Setting new password: %" PRIu32, this->
new_password_);
251 ESP_LOGI(TAG,
"New password successfully set");
252 ESP_LOGI(TAG,
"Define the new password in your configuration and reflash now");
253 ESP_LOGW(TAG,
"!!!Forgetting the password will render your device unusable!!!");
260 ESP_LOGD(TAG,
"Getting parameters");
263 ESP_LOGD(TAG,
"Got parameters");
285 ESP_LOGD(TAG,
"Getting fingerprint count");
288 ESP_LOGD(TAG,
"Got fingerprint count");
295 ESP_LOGI(TAG,
"Deleting fingerprint in slot %d", finger_id);
296 this->
data_ = {
DELETE, (uint8_t) (finger_id >> 8), (uint8_t) (finger_id & 0xFF), 0x00, 0x01};
299 ESP_LOGI(TAG,
"Deleted fingerprint");
303 ESP_LOGE(TAG,
"Reader failed to delete fingerprint");
309 ESP_LOGI(TAG,
"Deleting all stored fingerprints");
313 ESP_LOGI(TAG,
"Deleted all fingerprints");
317 ESP_LOGE(TAG,
"Reader failed to clear fingerprint library");
323 ESP_LOGD(TAG,
"Setting LED");
331 ESP_LOGD(TAG,
"LED set");
337 ESP_LOGE(TAG,
"Try aura_led_control instead");
343 const uint32_t now =
millis();
346 delay(this->last_aura_led_duration_ - elapsed);
348 ESP_LOGD(TAG,
"Setting Aura LED");
352 ESP_LOGD(TAG,
"Aura LED set");
353 this->last_aura_led_control_ =
millis();
354 this->last_aura_led_duration_ = 10 * speed * count;
360 ESP_LOGE(TAG,
"Try led_control instead");
368 this->
write((uint8_t) (START_CODE >> 8));
369 this->
write((uint8_t) (START_CODE & 0xFF));
376 uint16_t wire_length = p_data_buffer->size() + 2;
377 this->
write((uint8_t) (wire_length >> 8));
378 this->
write((uint8_t) (wire_length & 0xFF));
380 uint16_t sum = (wire_length >> 8) + (wire_length & 0xFF) +
COMMAND;
381 for (
auto data : *p_data_buffer) {
386 this->
write((uint8_t) (sum >> 8));
387 this->
write((uint8_t) (sum & 0xFF));
389 p_data_buffer->clear();
392 uint16_t idx = 0,
length = 0;
394 for (uint16_t timer = 0; timer < 1000; timer++) {
404 if (byte != (uint8_t) (START_CODE >> 8))
408 if (byte != (uint8_t) (START_CODE & 0xFF)) {
417 if (byte != this->
address_[idx - 2]) {
429 length = (uint16_t) byte << 8;
435 p_data_buffer->push_back(byte);
436 if ((idx - 8) ==
length) {
437 switch ((*p_data_buffer)[0]) {
454 ESP_LOGE(TAG,
"Reader failed to process request");
457 ESP_LOGE(TAG,
"Unknown response received from reader: 0x%.2X", (*p_data_buffer)[0]);
461 return (*p_data_buffer)[0];
467 ESP_LOGE(TAG,
"No response received from reader");
489 for (uint16_t timer = 0; timer < WAIT_FOR_WAKE_UP_MS; timer++) {
507 ESP_LOGD(TAG,
"Sensor has woken up!");
509 ESP_LOGE(TAG,
"Timed out waiting for sensor wake-up");
511 ESP_LOGE(TAG,
"Received wrong byte from the sensor during wake-up: 0x%.2X", byte);
522 ESP_LOGE(TAG,
"Wrong password");
533 ESP_LOGD(TAG,
"Fingerprint sensor is now in sleep mode.");
537 ESP_LOGCONFIG(TAG,
"GROW_FINGERPRINT_READER:");
539 ESP_LOGCONFIG(TAG,
" Touch Sensing Pin: %s",
541 ESP_LOGCONFIG(TAG,
" Sensor Power Pin: %s",
546 ESP_LOGCONFIG(TAG,
" Idle Period to Sleep: Never");
548 LOG_UPDATE_INTERVAL(
this);
virtual void digital_write(bool value)=0
CallbackManager< void(uint16_t, uint16_t)> finger_scan_matched_callback_
void finish_enrollment(uint8_t result)
uint16_t system_identifier_code_
CallbackManager< void(uint8_t, uint16_t)> enrollment_scan_callback_
uint16_t last_aura_led_duration_
std::vector< uint8_t > data_
void delete_all_fingerprints()
uint8_t scan_image_(uint8_t buffer)
uint32_t IRAM_ATTR HOT millis()
uint8_t save_fingerprint_()
void get_fingerprint_count_()
void delete_fingerprint(uint16_t finger_id)
sensor::Sensor * fingerprint_count_sensor_
virtual std::string dump_summary() const =0
CallbackManager< void()> finger_scan_start_callback_
GPIOPin * sensor_power_pin_
uint8_t transfer_(std::vector< uint8_t > *p_data_buffer)
sensor::Sensor * status_sensor_
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * last_finger_id_sensor_
sensor::Sensor * security_level_sensor_
uint8_t enrollment_image_
void publish_state(bool state)
Publish a new state to the front-end.
void enroll_fingerprint(uint16_t finger_id, uint8_t num_buffers)
CallbackManager< void(uint16_t)> enrollment_failed_callback_
sensor::Sensor * last_confidence_sensor_
CallbackManager< void()> finger_scan_unmatched_callback_
uint32_t last_transfer_ms_
virtual bool digital_read()=0
binary_sensor::BinarySensor * enrolling_binary_sensor_
float get_state() const
Getter-syntax for .state.
void led_control(bool state)
sensor::Sensor * capacity_sensor_
uint8_t enrollment_buffers_
virtual void mark_failed()
Mark this component as failed.
CallbackManager< void()> finger_scan_misplaced_callback_
CallbackManager< void(uint16_t)> enrollment_done_callback_
Implementation of SPI Controller mode.
uint16_t enrollment_slot_
uint32_t idle_period_to_sleep_ms_
void aura_led_control(uint8_t state, uint8_t speed, uint8_t color, uint8_t count)
size_t write(uint8_t data)
uint32_t last_aura_led_control_
CallbackManager< void()> finger_scan_invalid_callback_
void IRAM_ATTR HOT delay(uint32_t ms)
void dump_config() override