Skip to content
Open
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
3 changes: 2 additions & 1 deletion validitysensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ def match_finger(self) -> typing.Tuple[int, int, bytes]:
rsp = tls.app(cmd)
assert_status(rsp)

b = usb.wait_int()
# The sensor drops off the USB bus if the match is interrupted, so let it finish
b = usb.wait_int(cancellable=False)
if b[0] != 3:
raise Exception('Finger not recognized: %s' % hexlify(b).decode())

Expand Down
10 changes: 8 additions & 2 deletions validitysensor/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from binascii import hexlify, unhexlify
from enum import Enum
from struct import unpack
from time import monotonic

import usb.core as ucore
from usb.core import USBError
Expand Down Expand Up @@ -122,8 +123,10 @@ def read_82(self):
def cancel(self):
self.cancel = True

def wait_int(self):
# With cancellable=False a cancel request is ignored and the wait gives up after max_wait seconds instead.
def wait_int(self, cancellable: bool = True, max_wait: float = 5):
self.cancel = False
deadline = monotonic() + max_wait

while True:
try:
Expand All @@ -133,7 +136,10 @@ def wait_int(self):
return resp
except USBError as e:
if e.errno == errno.ETIMEDOUT:
if self.cancel:
if cancellable:
if self.cancel:
raise CancelledException()
elif monotonic() > deadline:
raise CancelledException()
else:
raise e
Expand Down