-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
77 lines (55 loc) · 1.74 KB
/
script.py
File metadata and controls
77 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import board
import busio
from digitalio import DigitalInOut
import webbrowser
import pyautogui
from adafruit_pn532.i2c import PN532_I2C
# I2C connection:
i2c = busio.I2C(board.SCL, board.SDA)
UID_LIST = {str(bytearray(b'\x93\x17\xbb\x02')): "White Tag",
str(bytearray(b'\xb1z\xe2\r')): "Blue Tag",
str(None): "Homepage"}
URL_LIST = {}
reset_pin = DigitalInOut(board.D6)
req_pin = DigitalInOut(board.D12)
pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
ic, ver, rev, support = pn532.firmware_version
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
# Configure PN532 to communicate with MiFare cards
pn532.SAM_configuration()
def switch_to_page(cell_part):
if cell_part == None:
pyautogui.hotkey('ctrl', 'w')
pyautogui.press('f11')
return
else:
url = URL_LIST[cell_part]
pyautogui.hotkey('ctrl', 'w')
webbrowser.open(url)
pyautogui.press('f11')
print("Waiting for RFID/NFC card...")
previous_cell_part = UID_LIST[str(None)]
increment = 0
switch_to_page(None)
while True:
# Check if a card is available to read
uid = pn532.read_passive_target(timeout=0.5)
if str(uid) in UID_LIST.keys():
cell_part = UID_LIST[str(uid)]
else:
print("UNKNOWN UID: ", uid)
if cell_part != previous_cell_part:
if increment >= 4:
previous_cell_part = cell_part
switch_to_page(cell_part)
else:
increment += 1
else:
continue
# # Try again if no card is available.
# if uid is None:
# continue
# if str(uid) in UID_LIST.keys():
# print(UID_LIST[str(uid)])
# print("Found card with UID:", [hex(i) for i in uid])
# print(uid)