Skip to content

Commit cdb797b

Browse files
authored
Merge pull request #21 from jerryneedell/jerryn_fingersearch
add finger_search
2 parents 1155d89 + cedbc64 commit cdb797b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

adafruit_fingerprint.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
**Hardware:**
3535
3636
* `Fingerprint sensor <https://www.adafruit.com/product/751>`_ (Product ID: 751)
37+
* `Panel Mount Fingerprint sensor <https://www.adafruit.com/product/4651>`_ (Product ID: 4651)
3738
3839
**Software and Dependencies:**
3940
@@ -59,6 +60,7 @@
5960

6061
_GETIMAGE = const(0x01)
6162
_IMAGE2TZ = const(0x02)
63+
_FINGERPRINTSEARCH = const(0x04)
6264
_REGMODEL = const(0x05)
6365
_STORE = const(0x06)
6466
_LOAD = const(0x07)
@@ -100,7 +102,7 @@
100102
PASSVERIFY = const(0x21)
101103
MODULEOK = const(0x55)
102104

103-
105+
# pylint: disable=too-many-instance-attributes
104106
class Adafruit_Fingerprint:
105107
"""UART based fingerprint sensor."""
106108

@@ -117,6 +119,8 @@ class Adafruit_Fingerprint:
117119
device_address = None
118120
data_packet_size = None
119121
baudrate = None
122+
system_id = None
123+
status_register = None
120124

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

290+
def finger_search(self):
291+
"""Asks the sensor to search for a matching fingerprint starting at
292+
slot 1. Stores the location and confidence in self.finger_id
293+
and self.confidence. Returns the packet error code or OK success"""
294+
self.read_sysparam()
295+
capacity = self.library_size
296+
self._send_packet(
297+
[_FINGERPRINTSEARCH, 0x01, 0x00, 0x00, capacity >> 8, capacity & 0xFF]
298+
)
299+
r = self._get_packet(16)
300+
self.finger_id, self.confidence = struct.unpack(">HH", bytes(r[1:5]))
301+
# print(r)
302+
return r[0]
303+
284304
##################################################
285305

286306
def _get_packet(self, expected):

examples/fingerprint_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_fingerprint():
3131
if finger.image_2_tz(1) != adafruit_fingerprint.OK:
3232
return False
3333
print("Searching...")
34-
if finger.finger_fast_search() != adafruit_fingerprint.OK:
34+
if finger.finger_search() != adafruit_fingerprint.OK:
3535
return False
3636
return True
3737

examples/fingerprint_simpletest_rpi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import time
2+
import serial
23
import board
34

45
# import busio
5-
import serial
66
from digitalio import DigitalInOut, Direction
77
import adafruit_fingerprint
88

@@ -37,7 +37,7 @@ def get_fingerprint():
3737
if finger.image_2_tz(1) != adafruit_fingerprint.OK:
3838
return False
3939
print("Searching...")
40-
if finger.finger_fast_search() != adafruit_fingerprint.OK:
40+
if finger.finger_search() != adafruit_fingerprint.OK:
4141
return False
4242
return True
4343

0 commit comments

Comments
 (0)