Skip to content

Commit c2c7357

Browse files
committed
feat: add rfid interface
1 parent 9a95d80 commit c2c7357

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/rfid.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from lib.mfrc522 import MFRC522
2+
3+
4+
class RFIDInterface:
5+
def __init__(self, sda_pin: int, sck_pin: int, mosi_pin: int, miso_pin: int, rst_pin: int):
6+
self.__rfid = MFRC522(sck=sck_pin, miso=miso_pin, mosi=mosi_pin, cs=sda_pin, rst=rst_pin)
7+
8+
def read_card_id(self):
9+
self.__rfid.init()
10+
(stat, tag_type) = self.__rfid.request(self.__rfid.REQIDL)
11+
if stat == self.__rfid.OK:
12+
(stat, uid) = self.__rfid.SelectTagSN()
13+
if stat == self.__rfid.OK:
14+
return int.from_bytes(bytes(uid), "little", False)

0 commit comments

Comments
 (0)