-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal_client.py
234 lines (210 loc) · 6.15 KB
/
original_client.py
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import RPi.GPIO as GPIO
import Adafruit_CharLCD as LCDLib
import math
import time
import random
#import connection
from aldenC import *
from subprocess import call
kioskNumber = 1
lcd = LCDLib.Adafruit_CharLCDBackpack()
print("Initalized lcd library")
lcd.set_backlight(0)
max_len = 4
row_pins = [16,6,12,13]
col_pins = [19,20,21]
color_pins = [18,23]
txt = ""
#server_ip = "96.225.21.203"
#server_port = 25565
#server_connection = Connection(server_ip, server_port)
#server_connections.connect()
#lcd.message("ID: ")
#server_ip = "96.225.21.203"
#server_port = 25565
#server_connection = connection.Connection(server_ip,server_port)
#server_connection.connect()
color_dict = {
"white": 0,
"hotpink": 1,
"yellow": 2,
"red": 3,
"babyblue": 4,
"darkblue": 5,
"green": 6,
"null": 7
}
def set_color(color):
port1 = color & 0b1
port0 = (color >> 1) & 0b1
back = (color >> 2) & 0b1
GPIO.output(color_pins[1], port1)
GPIO.output(color_pins[0], port0)
lcd.set_backlight(back)
def send_to_server():
#replaces bottom text with Checking and waits for a response from the server
lcd.set_cursor(0,1)
lcd.message("Checking... ")
#sends
#print(myConnection.send(Message(MessageType.CONNECTION, 0, b'/00/00')))
#response = myConnection.message_protocol(Message(MessageType.INPUT, 0, 12598))
#if(response.transactionID != -1):
# set_color(color_dict['green'])
# lcd.set_cursor(0,1)
# name = response.messageValue[4:][1::2].decode('utf-8')
# lcd.message('ID is invalid \n' + name)
# else:
# set_color(color_dict['red'])
# lcd.set_cursor(0,1)
# lcd.message("ID is invalid ")
rObj = makeRec(txt)
if (rObj.failed):
set_color(color_dict['red'])
lcd.set_cursor(0,0)
lcd.message("Server Error")
lcd.set_cursor(0,1)
lcd.message("Contact Office")
time.sleep(2)
else:
if (rObj.works):
set_color(color_dict['green'])
lcd.set_cursor(0,0)
welcStr = "ID Accepted \n" + rObj.names + ""
'''
welcStr = ''
if (rObj.leaving):
welcStr = "Goodbye \n" + rObj.names + ""
else:
welcStr = "Welcome Back\n" + rObj.names + ""
'''
lcd.message(welcStr)
else:
set_color(color_dict['red'])
if (rObj.withInfo):
lcd.set_cursor(0,0)
lcd.message("No Senior Priv\n" + rObj.names + "")
else:
lcd.set_cursor(0,0)
lcd.message("ID not found")
GPIO.output(row_pins[0], GPIO.HIGH)
GPIO.output(row_pins[1], GPIO.HIGH)
GPIO.output(row_pins[2], GPIO.HIGH)
GPIO.output(row_pins[3], GPIO.HIGH)
start_time = time.time()
while time.time() - start_time < 2:
for col in col_pins:
if (GPIO.input(col)):
GPIO.output(row_pins[0], GPIO.LOW)
GPIO.output(row_pins[1], GPIO.LOW)
GPIO.output(row_pins[2], GPIO.LOW)
GPIO.output(row_pins[3], GPIO.LOW)
return
time.sleep(0.021)
# if (rObj.works):
# set_color(color_dict['green'])
# lcd.set_cursor(0,0)
# welcStr = ''
# if (rObj.leaving):
# welcStr = "Goodbye \n" + rObj.names + ""
# else:
# welcStr = "Welcome back\n" + rObj.names + ""
# lcd.message(welcStr)
# time.sleep(1.5)
# else:
# set_color(color_dict['red'])
# lcd.set_cursor(0,1)
# lcd.message(" ")
# lcd.set_cursor(0,0)
# if (rObj.failed):
# else:
# lcd.message("ID not found")
# time.sleep(2.5)
#sets the color back to normal
set_color(color_dict['null'])
return
def reset():
#resets all variables and the LCD display for the next user
global txt
txt = ""
print("RESETTING")
lcd.set_cursor(0,1)
lcd.message(" ")
lcd.home()
lcd.message("ID: ")
lcd.set_cursor(4, 0)
set_color(color_dict['white'])
return
def submit():
lcd.set_cursor(0,1)
lcd.message("Are you sure?")
GPIO.output(row_pins[3], GPIO.HIGH)
#waits for a second enter or delete press
time.sleep(0.25)
while True:
#if delete is pressed get rid of the message on line 2 and return to id input
if(GPIO.input(col_pins[0])):
lcd.set_cursor(0, 1)
lcd.message(" ")
lcd.set_cursor(4+len(txt), 0)
#waits until delete is released to return to id input so that no number is deleted
while True:
if(not GPIO.input(col_pins[0])):
return
#if enter is pressed send to the server and reset
elif(GPIO.input(col_pins[2])):
send_to_server()
reset()
return
time.sleep(0.021)
def press(id):
global txt
#if enter is pressed and submit the id
if id == 12 and len(txt) == 5:
submit()
return
#if delete is pressed remove one number from input and txt
if len(txt) > 0 and id == 10:
txt = txt[:-1]
lcd.set_cursor(4 + len(txt), 0)
lcd.message(" ")
lcd.set_cursor(4 + len(txt), 0)
#only allow input if there are less than 5 numbers in the input field
if len(txt) <= max_len:
#if any of the number keys save 0 are pressed add them to the text and display them
if id < 10:
txt += str(id)
lcd.message(str(id))
#if zero is pressed add zero to the input field and txt
elif id == 11:
txt += "0"
lcd.message("0")
GPIO.setmode(GPIO.BCM)
GPIO.setup(row_pins, GPIO.OUT)
GPIO.setup(color_pins, GPIO.OUT)
GPIO.setup(col_pins, GPIO.IN, pull_up_down=GPIO.PUD_DOWN )
GPIO.output(row_pins, GPIO.LOW)
buttons_pressed = [False] * 12
pressing = False
current = -1
#comment
#Set up LCD
lcd.show_cursor(True)
lcd.home()
lcd.message("ID: ")
set_color(0)
while True:
button_id = 0
for rp in row_pins:
GPIO.output(rp,GPIO.HIGH)
for cp in col_pins:
button_id += 1
current = GPIO.input(cp)
if (current): print(button_id)
if current and not buttons_pressed[button_id - 1]:
buttons_pressed[button_id - 1] = True
press(button_id)
elif not current and buttons_pressed[button_id - 1]:
buttons_pressed[button_id - 1] = False
GPIO.output(rp, GPIO.LOW)
time.sleep(0.021)
GPIO.cleanup()