Skip to content

add finger_search #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion adafruit_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
**Hardware:**

* `Fingerprint sensor <https://www.adafruit.com/product/751>`_ (Product ID: 751)
* `Panel Mount Fingerprint sensor <https://www.adafruit.com/product/4651>`_ (Product ID: 4651)

**Software and Dependencies:**

Expand All @@ -59,6 +60,7 @@

_GETIMAGE = const(0x01)
_IMAGE2TZ = const(0x02)
_FINGERPRINTSEARCH = const(0x04)
_REGMODEL = const(0x05)
_STORE = const(0x06)
_LOAD = const(0x07)
Expand Down Expand Up @@ -100,7 +102,7 @@
PASSVERIFY = const(0x21)
MODULEOK = const(0x55)


# pylint: disable=too-many-instance-attributes
class Adafruit_Fingerprint:
"""UART based fingerprint sensor."""

Expand All @@ -117,6 +119,8 @@ class Adafruit_Fingerprint:
device_address = None
data_packet_size = None
baudrate = None
system_id = None
status_register = None

def __init__(self, uart, passwd=(0, 0, 0, 0)):
# Create object with UART for interface, and default 32-bit password
Expand Down Expand Up @@ -152,6 +156,8 @@ def read_sysparam(self):
r = self._get_packet(28)
if r[0] != OK:
raise RuntimeError("Command failed.")
self.status_register = struct.unpack(">H", bytes(r[1:3]))[0]
self.system_id = struct.unpack(">H", bytes(r[3:5]))[0]
self.library_size = struct.unpack(">H", bytes(r[5:7]))[0]
self.security_level = struct.unpack(">H", bytes(r[7:9]))[0]
self.device_address = bytes(r[9:13])
Expand Down Expand Up @@ -281,6 +287,20 @@ def finger_fast_search(self):
# print(r)
return r[0]

def finger_search(self):
"""Asks the sensor to search for a matching fingerprint starting at
slot 1. Stores the location and confidence in self.finger_id
and self.confidence. Returns the packet error code or OK success"""
self.read_sysparam()
capacity = self.library_size
self._send_packet(
[_FINGERPRINTSEARCH, 0x01, 0x00, 0x00, capacity >> 8, capacity & 0xFF]
)
r = self._get_packet(16)
self.finger_id, self.confidence = struct.unpack(">HH", bytes(r[1:5]))
# print(r)
return r[0]

##################################################

def _get_packet(self, expected):
Expand Down
2 changes: 1 addition & 1 deletion examples/fingerprint_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_fingerprint():
if finger.image_2_tz(1) != adafruit_fingerprint.OK:
return False
print("Searching...")
if finger.finger_fast_search() != adafruit_fingerprint.OK:
if finger.finger_search() != adafruit_fingerprint.OK:
return False
return True

Expand Down
4 changes: 2 additions & 2 deletions examples/fingerprint_simpletest_rpi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import time
import serial
import board

# import busio
import serial
from digitalio import DigitalInOut, Direction
import adafruit_fingerprint

Expand Down Expand Up @@ -37,7 +37,7 @@ def get_fingerprint():
if finger.image_2_tz(1) != adafruit_fingerprint.OK:
return False
print("Searching...")
if finger.finger_fast_search() != adafruit_fingerprint.OK:
if finger.finger_search() != adafruit_fingerprint.OK:
return False
return True

Expand Down