generated from Synteraction-Lab/TemplateRepository
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_icons.py
More file actions
283 lines (252 loc) · 6.4 KB
/
test_icons.py
File metadata and controls
283 lines (252 loc) · 6.4 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# coding=utf-8
import participant_config
import device_config
import utilities
from pynput import keyboard
from random import shuffle
DEVICE_IP = device_config.get_device_ip()
DISPLAY_URL = 'http://' + DEVICE_IP + ':8080/displays/10/'
current_index = -1
participant = 'p0'
MAX_RETRY_ATTEMPT = 3
def get_next_icon():
global current_index
if current_index == -1:
shuffle(ALL_ICONS)
current_index += 1
if current_index < len(ALL_ICONS):
return ALL_ICONS[current_index].copy()
else:
return None
def send_until_success(display_data):
attempt = 0
success = False
while not success and attempt < MAX_RETRY_ATTEMPT:
success = utilities.send_request(DISPLAY_URL, display_data)
attempt += 1
if not success and attempt < MAX_RETRY_ATTEMPT:
utilities.sleep_seconds(0.5)
return success
current_icon = None
def send_next_icon():
global current_icon
if current_icon is None:
current_icon = get_next_icon()
if current_icon is None:
send_until_success({"subheading": ""})
return False
else:
# update icon
icon_info = current_icon.get("image").split() # <color> <icon_name>
updated_icon_info = f'{icon_info[0]} {icon_info[1]}{participant_config.get_icon_suffix(participant, icon_info[1])}'
current_icon["image"] = updated_icon_info
icon_copy = current_icon.copy()
icon_copy["subheading"] = " ? "
send_until_success(icon_copy)
return True
else:
send_until_success(current_icon)
current_icon = None
return True
def on_press(key):
# print("Key: ", key)
if key == keyboard.Key.down:
return send_next_icon()
# return False # stop listener
ALL_ICONS = [
# {
# "subheading": " Message",
# "image": "#FF00FF7D img_message"
# },
# {
# "subheading": " Meet (at location)",
# "image": "#FF00FF7D img_meet"
# },
# {
# "subheading": " PIN (transaction)",
# "image": "#FF00FF7D img_pin"
# },
# {
# "subheading": " Send",
# "image": "#FF00FF7D img_send"
# },
# {
# "subheading": " Forward",
# "image": "#FF00FF7D img_forward"
# },
# {
# "subheading": " Cleaning",
# "image": "#FF00FF7D img_cleaning"
# },
# {
# "subheading": " Yoga",
# "image": "#FF00FF7D img_yoga"
# },
# {
# "subheading": " Cycling",
# "image": "#FF00FF7D img_cycling"
# },
# {
# "subheading": " Buy (Add to cart)",
# "image": "#FF00FF7D img_buy"
# },
# {
# "subheading": " Ticket",
# "image": "#FF00FF7D img_ticket"
# },
# {
# "subheading": " Pay (mobile)",
# "image": "#FF00FF7D img_pay_mobile"
# },
# {
# "subheading": " Identity card",
# "image": "#FF00FF7D img_id_card"
# },
# {
# "subheading": " Delete",
# "image": "#FF00FF7D img_delete"
# },
{
"subheading": " Birthday",
"image": "#FF00FF7D img_birthday"
},
{
"subheading": " Alarm",
"image": "#FF00FF7D img_alarm"
},
{
"subheading": " Meeting",
"image": "#FF00FF7D img_meeting"
},
{
"subheading": " Lunch",
"image": "#FF00FF7D img_lunch"
},
{
"subheading": " Coffee",
"image": "#FF00FF7D img_coffee"
},
{
"subheading": " Milk and eggs",
"image": "#FF00FF7D img_milk_eggs"
},
{
"subheading": " Credit card",
"image": "#FF00FF7D img_credit_card"
},
{
"subheading": " Delivery",
"image": "#FF00FF7D img_delivery"
},
{
"subheading": " Email",
"image": "#FF00FF7D img_email"
},
{
"subheading": " Reply",
"image": "#FF00FF7D img_reply"
},
{
"subheading": " Leave",
"image": "#FF00FF7D img_leave"
},
{
"subheading": " Visitor",
"image": "#FF00FF7D img_visitor"
},
{
"subheading": " Presentation",
"image": "#FF00FF7D img_presentation"
},
{
"subheading": " Doctor (appointment)",
"image": "#FF00FF7D img_doctor"
},
{
"subheading": " Exercise",
"image": "#FF00FF7D img_exercise"
},
{
"subheading": " Standup",
"image": "#FF00FF7D img_standup"
},
{
"subheading": " Swimming",
"image": "#FF00FF7D img_swimming"
},
{
"subheading": " Take (photo)",
"image": "#FF00FF7D img_take_photo"
},
{
"subheading": " Sync (photos)",
"image": "#FF00FF7D img_sync_photos"
},
{
"subheading": " Download",
"image": "#FF00FF7D img_download"
},
{
"subheading": " Order (online)",
"image": "#FF00FF7D img_order_online"
},
{
"subheading": " Call",
"image": "#FF00FF7D img_call"
},
{
"subheading": " Movie",
"image": "#FF00FF7D img_movie"
},
{
"subheading": " Valentine's day",
"image": "#FF00FF7D img_valentine_day"
},
{
"subheading": " Mother's day",
"image": "#FF00FF7D img_mom_day"
},
{
"subheading": " Battery (low)",
"image": "#FF00FF7D img_battery_low"
},
{
"subheading": " Car (arrival)",
"image": "#FF00FF7D img_car"
},
{
"subheading": " Bus (arrival)",
"image": "#FF00FF7D img_bus"
},
{
"subheading": " Flight",
"image": "#FF00FF7D img_flight"
},
{
"subheading": " Top-up (cash)",
"image": "#FF00FF7D img_topup_cash"
},
{
"subheading": " Rental (pay)",
"image": "#FF00FF7D img_pay_rent"
},
{
"subheading": " Pay (cash)",
"image": "#FF00FF7D img_pay_cash"
},
{
"subheading": " License (driving)",
"image": "#FF00FF7D img_licence"
},
{
"subheading": " Backup (computer)",
"image": "#FF00FF7D img_backup_computer"
},
]
_participant = input("Participant id (e.g. p0) ? ")
if _participant == '':
_participant = 'p0'
participant = _participant
listener = keyboard.Listener(on_press=on_press)
listener.start()
listener.join() # remove if main thread is polling self.keys