Skip to content

Commit 90706fc

Browse files
Ran pylint and black
1 parent 64a78d2 commit 90706fc

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ redefining-builtins-modules=six.moves,future.builtins
208208

209209
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
210210
# expected-line-ending-format=
211-
expected-line-ending-format=LF
211+
expected-line-ending-format=CRLF
212212

213213
# Regexp for a line that is allowed to be longer than the limit.
214214
ignore-long-lines=^\s*(# )?<?https?://\S+>?$

adafruit_fingerprint.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def load_model(self, location, slot=1):
208208
def get_fpdata(self, sensorbuffer="char", slot=1):
209209
"""Requests the sensor to transfer the fingerprint image or
210210
template. Returns the data payload only."""
211-
if slot != 1 and slot != 2:
211+
if slot not in (1, 2):
212212
# raise error or use default value?
213213
slot = 2
214214
if sensorbuffer == "image":
@@ -219,14 +219,14 @@ def get_fpdata(self, sensorbuffer="char", slot=1):
219219
raise RuntimeError("Uknown sensor buffer type")
220220
if self._get_packet(12)[0] == 0:
221221
res = self._get_data(9)
222-
self._print_debug("get_fpdata data size:", str(len(res)))
222+
self._print_debug("get_fpdata data size:", str(len(res)))
223223
self._print_debug("get_fdata res:", res, data_type="hex")
224224
return res
225225

226226
def send_fpdata(self, data, sensorbuffer="char", slot=1):
227227
"""Requests the sensor to receive data, either a fingerprint image or
228228
a character/template data. Data is the payload only."""
229-
if slot != 1 and slot != 2:
229+
if slot not in (1, 2):
230230
# raise error or use default value?
231231
slot = 2
232232
if sensorbuffer == "image":
@@ -294,7 +294,6 @@ def finger_fast_search(self):
294294
def close_uart(self):
295295
"""close serial port"""
296296
self._uart.close()
297-
return
298297

299298
def finger_search(self):
300299
"""Asks the sensor to search for a matching fingerprint starting at
@@ -314,7 +313,7 @@ def compare_templates(self):
314313
"""Compares two fingerprint templates in char buffers 1 and 2. Stores the confidence score
315314
in self.finger_id and self.confidence. Returns the packet error code or
316315
OK success"""
317-
self._send_packet( [_COMPARE] )
316+
self._send_packet([_COMPARE])
318317
r = self._get_packet(14)
319318
self.confidence = struct.unpack(">H", bytes(r[1:3]))
320319
self._print_debug("compare_templates confidence:", self.confidence)
@@ -437,7 +436,7 @@ def _send_packet(self, data):
437436
def _send_data(self, data):
438437
self._print_debug("_send_data length:", len(data))
439438
self._print_debug("_send_data data:", data, data_type="hex")
440-
#self.read_sysparam() #moved this to init
439+
# self.read_sysparam() #moved this to init
441440
if self.data_packet_size == 0:
442441
data_length = 32
443442
elif self.data_packet_size == 1:
@@ -471,7 +470,7 @@ def _send_data(self, data):
471470
packet.append(length & 0xFF)
472471
checksum = _DATAPACKET + (length >> 8) + (length & 0xFF)
473472

474-
#for j in range(len(data[start:end])):
473+
# for j in range(len(data[start:end])):
475474
for j in range(start, end):
476475
packet.append(data[j])
477476
checksum += data[j]
@@ -491,12 +490,11 @@ def soft_reset(self):
491490

492491
def _print_debug(self, info, data, data_type="str"):
493492
"""Prints debugging information. This is activated
494-
by flag _debug"""
493+
by flag _debug"""
495494
if not self._debug:
496495
return
497496

498497
if data_type == "hex":
499498
print("*** DEBUG ==>", info, ["{:02x}".format(i) for i in data])
500499
elif data_type == "str":
501500
print("*** DEBUG ==>", info, data)
502-

examples/fingerprint_template_file_compare.py

+33-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
"""
5+
`fingerprint_template_file_compare.py`
6+
====================================================
7+
8+
This is an example program to demo storing fingerprint templates in a file. It also allows
9+
comparing a newly obtained print with one stored in the file in previous step. This is helpful
10+
when fingerprint templates are stored centrally (not on sensor's flash memory) and shared
11+
between multiple sensors.
12+
13+
* Author(s): admiralmaggie
14+
15+
Implementation Notes
16+
--------------------
17+
18+
**Hardware:**
19+
20+
* `Fingerprint sensor <https://www.adafruit.com/product/751>`_ (Product ID: 751)
21+
* `Panel Mount Fingerprint sensor <https://www.adafruit.com/product/4651>`_ (Product ID: 4651)
22+
"""
23+
24+
425
import serial
526
import adafruit_fingerprint
627

@@ -9,7 +30,7 @@
930
# uart = busio.UART(board.TX, board.RX, baudrate=57600)
1031

1132
# If using with a computer such as Linux/RaspberryPi, Mac, Windows with USB/serial converter:
12-
uart = serial.Serial("COM4", baudrate=57600, timeout=1)
33+
uart = serial.Serial("COM6", baudrate=57600, timeout=1)
1334

1435
# If using with Linux/Raspberry Pi and hardware UART:
1536
# uart = serial.Serial("/dev/ttyS0", baudrate=57600, timeout=1)
@@ -33,7 +54,7 @@ def sensor_reset():
3354
# pylint: disable=too-many-branches
3455
def fingerprint_check_file():
3556
"""Compares a new fingerprint template to an existing template stored in a file
36-
This is useful when templates are stored centrally (i.e. in a database)"""
57+
This is useful when templates are stored centrally (i.e. in a database)"""
3758
print("Waiting for finger print...")
3859
set_led_local(color=3, mode=1)
3960
while finger.get_image() != adafruit_fingerprint.OK:
@@ -43,8 +64,8 @@ def fingerprint_check_file():
4364
return False
4465

4566
print("Loading file template...", end="", flush=True)
46-
with open('template0.dat', 'rb') as f:
47-
data = f.read()
67+
with open("template0.dat", "rb") as file:
68+
data = file.read()
4869
finger.send_fpdata(list(data), "char", 2)
4970

5071
i = finger.compare_templates()
@@ -125,20 +146,21 @@ def enroll_save_to_file():
125146

126147
print("Downloading template...")
127148
data = finger.get_fpdata("char", 1)
128-
with open("template0.dat", "wb") as f:
129-
f.write(bytearray(data))
149+
with open("template0.dat", "wb") as file:
150+
file.write(bytearray(data))
130151
set_led_local(color=2, speed=150, mode=6)
131152
print("Template is saved in template0.dat file.")
132153

133154
return True
134155

156+
135157
def set_led_local(color=1, mode=3, speed=0x80, cycles=0):
136158
"""this is to make sure LED doesn't interfer with example
137-
running on models without LED support - needs testing"""
159+
running on models without LED support - needs testing"""
138160
try:
139161
finger.set_led(color, mode, speed, cycles)
140-
except:
141-
pass
162+
except Exception as exc:
163+
print("INFO: Sensor les not support LED!")
142164

143165

144166
set_led_local(color=3, mode=2, speed=10, cycles=10)
@@ -164,7 +186,7 @@ def set_led_local(color=1, mode=3, speed=0x80, cycles=0):
164186
print("----------------")
165187
c = input("> ")
166188

167-
if c == "x" or c == "q":
189+
if c in ("x", "q"):
168190
print("Exiting fingerprint example program")
169191
# turn off LED
170192
set_led_local(mode=4)
@@ -176,4 +198,4 @@ def set_led_local(color=1, mode=3, speed=0x80, cycles=0):
176198
elif c == "r":
177199
sensor_reset()
178200
else:
179-
print("Invalid choice: Try again")
201+
print("Invalid choice: Try again")

0 commit comments

Comments
 (0)