This repository was archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonGUI.py
More file actions
187 lines (128 loc) · 4.27 KB
/
pythonGUI.py
File metadata and controls
187 lines (128 loc) · 4.27 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import tkinter as tk
from PN532 import PN532
from Crypto.Cipher import AES
from AESED import AESCBC
import RPi.GPIO as GPIO
import sys
import os
import time
import threading
import base64
import re
import codecs
import requests
import json
timeSinceLast = None
pn532 = None
def callbackPN532(tag, id):
print('Found tag: {}, id: {}'.format(tag, id))
pn532.close()
identifier = id.split(":")
r = requests.post("https://medicalidou.com/login.php", data={'email': identifier[0]})
data = json.loads(r.text)
name = data["MID_Name"].split(":")
AES_inst = AESCBC(identifier[1], name[1])
nameDec = AES_inst.decrypt(name[0])
nfcScan(nameDec)
if(":" in id):
os.system('python3 tagtool.py --device "tty:AMA0" format tt2')
pn532 = PN532('tty:AMA0', 'A0000001020304', callbackPN532)
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
#master.bind('<Escape>',self.toggle_geom)
class App(threading.Thread):
def __init__(self, tk_root):
self.root = tk_root
threading.Thread.__init__(self)
self.start()
def run(self):
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
TRIG = 7
ECHO = 11
maxTime = 0.04
while True:
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG,False)
time.sleep(0.01)
GPIO.output(TRIG,True)
time.sleep(0.00001)
GPIO.output(TRIG,False)
pulse_start = time.time()
timeout = pulse_start + maxTime
while GPIO.input(ECHO) == 0 and pulse_start < timeout:
pulse_start = time.time()
pulse_end = time.time()
timeout = pulse_end + maxTime
while GPIO.input(ECHO) == 1 and pulse_end < timeout:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = round(pulse_duration * 17150, 2)
print(distance)
if distance < 25:
currentTime = round(time.time() * 1000)
time.sleep(3)
while round(time.time() * 1000) < (currentTime + 6000):
listen = pn532.listen()
else:
pn532.close()
except:
GPIO.cleanup()
'''
listen = pn532.listen()
if not listen:
break
if counter > 100:
pn532.close()
counter = 0
print("Restarting")
pn532 = PN532('tty:AMA0', 'A0000001020304', callbackPN532)
pn532.close()'''
def term():
pn532.close()
win.destroy()
exit()
# Window Setup
win = tk.Tk()
win.title("Medical ID")
win.resizable(False,False)
win.bind("<Escape>", lambda x: term())
FullScreenApp(win)
# Label
titleLbl = tk.Label(win, text = "Medical ID\n__________________")
labelfont = ('Ariel', 40, 'bold')
titleLbl.config(font=labelfont)
titleLbl.config(fg='#03adfc')
#2nd Label
label2 = tk.Label(win, text = "Scan Phone Here\n...")
label2.config(font=labelfont)
label3 = None
def clearName():
label3.destroy()
label2 = tk.Label(win, text = "Scan Phone Here\n...")
label2.config(font=labelfont)
label2.pack(pady=300)
def nfcScan(name):
label3 = tk.Label(win, text = "Data Transfer Complete!\nWelcome " + name)
label3.config(font=labelfont)
label2.destroy()
simBtn.destroy()
label3.pack(pady=300)
win.after(5000,refresh)
def refresh():
pn532.close()
python = sys.executable
os.execl(python, python, * sys.argv)
simBtn = tk.Button(text = "Simulate Scan", command = nfcScan)
APP = App(win)
titleLbl.pack()
simBtn.pack()
label2.pack(pady=300)
win.mainloop()