Skip to content

Commit 1e343c3

Browse files
finger_fast_search() based on module's capacity
1 parent 9c4034d commit 1e343c3

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

adafruit_fingerprint.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ def create_model(self):
174174
self._send_packet([_REGMODEL])
175175
return self._get_packet(12)[0]
176176

177-
def store_model(self, location, charbuf=1):
177+
def store_model(self, location, slot=1):
178178
"""Requests the sensor store the model into flash memory and assign
179179
a location. Returns the packet error code or OK success"""
180-
self._send_packet([_STORE, charbuf, location >> 8, location & 0xFF])
180+
self._send_packet([_STORE, slot, location >> 8, location & 0xFF])
181181
return self._get_packet(12)[0]
182182

183183
def delete_model(self, location):
@@ -186,22 +186,22 @@ def delete_model(self, location):
186186
self._send_packet([_DELETE, location >> 8, location & 0xFF, 0x00, 0x01])
187187
return self._get_packet(12)[0]
188188

189-
def load_model(self, location, charbuf=1):
189+
def load_model(self, location, slot=1):
190190
"""Requests the sensor to load a model from the given memory location
191-
to the given charbuf. Returns the packet error code or success"""
192-
self._send_packet([_LOAD, charbuf, location >> 8, location & 0xFF])
191+
to the given slot. Returns the packet error code or success"""
192+
self._send_packet([_LOAD, slot, location >> 8, location & 0xFF])
193193
return self._get_packet(12)[0]
194194

195-
def get_fpdata(self, buffer='char', charbuf=1):
195+
def get_fpdata(self, buffer='char', slot=1):
196196
"""Requests the sensor to transfer the fingerprint image or
197197
template. Returns the data payload only."""
198-
if charbuf != 1 or charbuf != 2:
198+
if slot != 1 or slot != 2:
199199
# raise error or use default value?
200-
charbuf = 1
200+
slot = 2
201201
if buffer == 'image':
202202
self._send_packet([_UPLOADIMAGE])
203203
elif buffer == 'char':
204-
self._send_packet([_UPLOAD, charbuf])
204+
self._send_packet([_UPLOAD, slot])
205205
else:
206206
raise RuntimeError('Uknown buffer type')
207207
if self._get_packet(12)[0] == 0:
@@ -210,16 +210,16 @@ def get_fpdata(self, buffer='char', charbuf=1):
210210
#print(res)
211211
return res
212212

213-
def send_fpdata(self, data, buffer='char', charbuf=1):
213+
def send_fpdata(self, data, buffer='char', slot=1):
214214
"""Requests the sensor to receive data, either a fingerprint image or
215215
a character/template data. Data is the payload only."""
216-
if charbuf != 1 or charbuf != 2:
216+
if slot != 1 or slot != 2:
217217
# raise error or use default value?
218-
charbuf = 2
218+
slot = 2
219219
if buffer == 'image':
220220
self._send_packet([_DOWNLOADIMAGE])
221221
elif buffer == 'char':
222-
self._send_packet([_DOWNLOAD, charbuf])
222+
self._send_packet([_DOWNLOAD, slot])
223223
else:
224224
raise RuntimeError('Uknown buffer type')
225225
if self._get_packet(12)[0] == 0:
@@ -240,7 +240,7 @@ def read_templates(self):
240240
self.templates = []
241241
self.read_sysparam()
242242
temp_r = [0x0c, ]
243-
for j in range(int(self.library_size/250)):
243+
for j in range(int(self.library_size/256)):
244244
self._send_packet([_TEMPLATEREAD, j])
245245
r = self._get_packet(44)
246246
if r[0] == OK:
@@ -261,7 +261,12 @@ def finger_fast_search(self):
261261
# high speed search of slot #1 starting at page 0x0000 and page #0x00A3
262262
#self._send_packet([_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3])
263263
# or page #0x03E9 to accommodate modules with up to 1000 capacity
264-
self._send_packet([_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x03, 0xE9])
264+
#self._send_packet([_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x03, 0xE9])
265+
# or base the page on module's capacity
266+
self.read_sysparam()
267+
capacity = self.library_size
268+
self._send_packet([_HISPEEDSEARCH, 0x01, 0x00, 0x00, capacity >> 8,
269+
capacity & 0xFF])
265270
r = self._get_packet(16)
266271
self.finger_id, self.confidence = struct.unpack('>HH', bytes(r[1:5]))
267272
return r[0]

0 commit comments

Comments
 (0)