Skip to content

Commit

Permalink
Adds UI Led interactions for rfid_comm_error and while reading metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
wie-niet committed Dec 19, 2024
1 parent 49c5e6f commit 9c05301
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 1 addition & 3 deletions libs/module/DjangoBackendRfidAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,7 @@ def lookup(self, key, target, nfc_tools, *args, **kwargs):

if self.lock_disabled is True:
msg = "Warning: lock disabled or never synchronised, lookup() and last-seen logging ignored."
logger.warning(
"Warning: lock disabled or never synchronised, lookup() and last-seen logging ignored."
)
logger.warning(msg)
return False, msg

# lookup key in access list:
Expand Down
24 changes: 21 additions & 3 deletions libs/module/PN532.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ def callback_tag_detected(self, target):

try:
has_access = dc.rfid_auth.has_access(
hwid_str, target=target, nfc_tools=NfcTools(target)
hwid_str,
target=target,
nfc_tools=NfcTools(
target,
callback_rfid_comm=lambda: self.event_bus.raise_event(
"rfid_comm_pulse"
),
),
)
except TargetGoneWhileReadingError:
has_access = None
Expand Down Expand Up @@ -194,7 +201,10 @@ def callback_tag_detected(self, target):
else:
# has_access is None or anythng else
logger.info("hwid ({:s}) gone while reading.".format(hwid_str))
time.sleep(2)
# show 3 times rfid_comm_error (aprox 0.6 seconds)
self.event_bus.raise_event("rfid_comm_error", wait=True)
self.event_bus.raise_event("rfid_comm_error", wait=True)
self.event_bus.raise_event("rfid_comm_error", wait=True)

def start_thread(self):
if not (self.thread and self.thread.is_alive()):
Expand Down Expand Up @@ -223,8 +233,9 @@ def stop_thread(self):
class NfcTools:
"""Set of tools to communicate with nfc tags or collect various tag data."""

def __init__(self, target):
def __init__(self, target, callback_rfid_comm=lambda: None):
self.target = target
self.callback_rfid_comm = callback_rfid_comm

def _authenticate(
self, secret=bytearray([0x0, 0x0, 0x0, 0x0, 0x0, 0x0]), page=0, timeout=0.005
Expand All @@ -235,6 +246,9 @@ def _authenticate(
if self.target.type != "Type2Tag":
raise Exception("authenticate only for for type Type2Tag")

# show UI feeedback
self.callback_rfid_comm()

# type2tag uses 0x60 for authentication.
send = bytearray([0x60, page]) + secret + self.target._nfcid
logger.debug(f"authenticate using: target.transceive({send.hex()}, {timeout})")
Expand All @@ -246,6 +260,10 @@ def _read(self, page, max_retries=3):
"""wrapper for target.read(page), but then with retries for timeout
Type2TagCommandError(nfc.tag.TIMEOUT_ERROR)
"""

# show UI feeedback
self.callback_rfid_comm()

n = 0
while n != max_retries:
n = n + 1
Expand Down
9 changes: 9 additions & 0 deletions libs/module/UILed4.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def enable(self):
self.s.append(
events.subscribe("rfid_comm_ready", lambda data: self.led2.blink())
)
self.s.append(
events.subscribe(
"rfid_comm_error",
lambda data: self.led3.blink()
or self.led2.blink()
or self.led3.blink()
or self.led2.blink(),
)
)
self.s.append(
events.subscribe("rfid_access_denied", lambda data: self.led3.on())
)
Expand Down

0 comments on commit 9c05301

Please sign in to comment.