Loading poolpay/card/Pirc522CardReader.py +22 −8 Original line number Diff line number Diff line from collections.abc import Callable from time import sleep from pirc522 import RFID Loading @@ -12,26 +13,39 @@ class Pirc522CardReader(CardReader): # the same SPI0 bus (making one device=0, and the other device=1), # but I think that by just separating the buses, it should be less of a hassle. self._reader = RFID(bus=1, device=0, pin_irq=37, pin_rst=33) self._handle_removal: Callable[[CardReader], None] | None = None def read_id(self) -> int: # TODO Cleanup implementation (error, anticoll_uid) = self._reader.anticoll() uid = tuple(self._reader.read_id()) def read_id(self) -> int | None: self._reader.anticoll() uid = self._reader.read_id() if uid is None: return None # Merge list of bytes together into one single (big-endian) byte, by shifting # the bytes the appropriate amount of positions, and adding this all up. return sum(byte << 8 * index for index, byte in enumerate(reversed(uid))) def on_card_presented(self, handle_card: Callable[[CardReader], None]) -> None: # If the interrupt pin (pin_irq) is correctly initialized, self._reader.wait_for_tag() might work # TODO Run this in a background thread card_recently_presented = False while True: # This only works if the interrupt pin (pin_irq) is correctly initialized self._reader.wait_for_tag() uid = self.read_id() if uid is None: if card_recently_presented and self._handle_removal is not None: self._handle_removal(self) card_recently_presented = False elif not card_recently_presented: card_recently_presented = True handle_card(self) sleep(0.1) def on_card_removed(self, handle_removal: Callable[[CardReader], None]) -> None: # TODO Implement pass self._handle_removal = handle_removal def close(self) -> None: # Always stop crypto1 when done working Loading Loading
poolpay/card/Pirc522CardReader.py +22 −8 Original line number Diff line number Diff line from collections.abc import Callable from time import sleep from pirc522 import RFID Loading @@ -12,26 +13,39 @@ class Pirc522CardReader(CardReader): # the same SPI0 bus (making one device=0, and the other device=1), # but I think that by just separating the buses, it should be less of a hassle. self._reader = RFID(bus=1, device=0, pin_irq=37, pin_rst=33) self._handle_removal: Callable[[CardReader], None] | None = None def read_id(self) -> int: # TODO Cleanup implementation (error, anticoll_uid) = self._reader.anticoll() uid = tuple(self._reader.read_id()) def read_id(self) -> int | None: self._reader.anticoll() uid = self._reader.read_id() if uid is None: return None # Merge list of bytes together into one single (big-endian) byte, by shifting # the bytes the appropriate amount of positions, and adding this all up. return sum(byte << 8 * index for index, byte in enumerate(reversed(uid))) def on_card_presented(self, handle_card: Callable[[CardReader], None]) -> None: # If the interrupt pin (pin_irq) is correctly initialized, self._reader.wait_for_tag() might work # TODO Run this in a background thread card_recently_presented = False while True: # This only works if the interrupt pin (pin_irq) is correctly initialized self._reader.wait_for_tag() uid = self.read_id() if uid is None: if card_recently_presented and self._handle_removal is not None: self._handle_removal(self) card_recently_presented = False elif not card_recently_presented: card_recently_presented = True handle_card(self) sleep(0.1) def on_card_removed(self, handle_removal: Callable[[CardReader], None]) -> None: # TODO Implement pass self._handle_removal = handle_removal def close(self) -> None: # Always stop crypto1 when done working Loading