-
Notifications
You must be signed in to change notification settings - Fork 4
/
eyes.py
392 lines (344 loc) · 8.96 KB
/
eyes.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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import time
import random
import argparse
import dcled.core
import curses
# Python program to control the Dream Cheeky USB LED: http://www.dreamcheeky.com/led-message-board
# Code inspired by dcled: http://www.last-outpost.com/~malakai/dcled/
# and by dcled_ruby: https://github.com/Lewis-Clayton/dcled_ruby
# Requires PyUSB 1.0: http://walac.github.io/pyusb/
# Sample data from the hardware developer's manual: makes a diamond
diamond = [
[0x00, 0x00, 0xFF,0xFE,0xFF, 0xFF,0xFD,0x7F,],
[0x00, 0x02, 0xFF,0xFB,0xBF, 0xFF,0xF7,0xDF,],
[0x00, 0x04, 0xFF,0xFB,0xBF, 0xFF,0xFD,0x7F,],
[0x00, 0x06, 0xFF,0xFE,0xFF,],
]
teeth = [
"""
xxxxxxxxxxxxxxxxxxxxx
.xxx.xxx.xxx.xxx.xxx.
.xxx.xxx.xxx.xxx.xxx.
..x.x.x.x.x.x.x.x.x..
..x.x.x.x.x.x.x.x.x..
...xxx.xxx.xxx.xxx...
...xxx.xxx.xxx.xxx...
""",
"""
.xxx.xxx.xxx.xxx.xxx.
.xxx.xxx.xxx.xxx.xxx.
..x...x...x...x...x..
..x.x.x.x.x.x.x.x.x..
....x...x...x...x....
...xxx.xxx.xxx.xxx...
...xxx.xxx.xxx.xxx...
""",
"""
.xxx.xxx.xxx.xxx.xxx.
..x...x...x...x...x..
..x...x...x...x...x..
.....................
....x...x...x...x....
....x...x...x...x....
...xxx.xxx.xxx.xxx...
""",
"""
..x...x...x...x...x..
..x...x...x...x...x..
.....................
.....................
.....................
....x...x...x...x....
....x...x...x...x....
""",
"""
..x...x...x...x...x..
.....................
.....................
.....................
.....................
.....................
....x...x...x...x....
""",
]
kitty = []
kitty.append(
"..xxx...........xxx.." \
".x...x.........x...x." \
"x.....x.......x.....x" \
"x..x..x.......x..x..x" \
"x.....x.......x.....x" \
".x...x...xxx...x...x." \
"..xxx.....x.....xxx.."
)
kitty.append(
"....................." \
".xxxxx.........xxxxx." \
"x.....x.......x.....x" \
"x..x..x.......x..x..x" \
"x.....x.......x.....x" \
".xxxxx...xxx...xxxxx." \
"..........x.........."
)
kitty.append(
"....................." \
"....................." \
".xxxxx.........xxxxx." \
"x..x..x.......x..x..x" \
".xxxxx.........xxxxx." \
".........xxx........." \
"..........x.........."
)
kitty.append(
"....................." \
"....................." \
"....................." \
"xxxxxxx.......xxxxxxx" \
"....................." \
".........xxx........." \
"..........x.........."
)
grumpy = []
grumpy.append(
"..xx.....xxx.....xx.." \
"..x.x.....x.....x.x.." \
".x..x...........x..x." \
".x.x.x.........x.x.x." \
".x...x.........x...x." \
"..x.x....xxx....x.x.." \
"..xxx...x...x...xxx.."
)
grumpy.append(
".........xxx........." \
"..xxx.....x.....xxx.." \
".x...x.........x...x." \
".x.x.x.........x.x.x." \
".x...x.........x...x." \
"..xxx....xxx....xxx.." \
"........x...x........"
)
grumpy.append(
".........xxx........." \
"..........x.........." \
"..xxx...........xxx.." \
".x.x.x.........x.x.x." \
"..xxx...........xxx.." \
".........xxx........." \
"........x...x........"
)
grumpy.append(
".........xxx........." \
"..........x.........." \
"....................." \
".xxxxx.........xxxxx." \
"....................." \
".........xxx........." \
"........x...x........"
)
happy = []
happy.append(
"...x.............x..." \
"..x.x....xxx....x.x.." \
".x...x....x....x...x." \
".x.x.x.........x.x.x." \
".x...x.........x...x." \
"..x.x...x...x...x.x.." \
"...x.....xxx.....x..."
)
happy.append(
"....................." \
"..xxx....xxx....xxx.." \
".x...x....x....x...x." \
".x.x.x.........x.x.x." \
".x...x.........x...x." \
"..xxx...x...x...xxx.." \
".........xxx........."
)
happy.append(
"....................." \
".........xxx........." \
"..xxx.....x.....xxx.." \
".x.x.x.........x.x.x." \
"..xxx...........xxx.." \
"........x...x........" \
".........xxx........."
)
happy.append(
"....................." \
".........xxx........." \
"..........x.........." \
".xxxxx.........xxxxx." \
"....................." \
"........x...x........" \
".........xxx........."
)
human = []
human.append(
"....................." \
".xxxxx.........xxxxx." \
"x.xxx.x.......x.xxx.x" \
"x.xxx.xx.xxx.xx.xxx.x" \
"x.....x..xxx..x.....x" \
".x...x...xxx...x...x." \
"..xxx...x.x.x...xxx.."
)
human.append(
"....................." \
"....................." \
"xxxxxxx.......xxxxxxx" \
"x.xxx.xx.xxx.xx.xxx.x" \
"x.....x..xxx..x.....x" \
".xxxxx...xxx...xxxxx." \
"........x.x.x........"
)
human.append(
"....................." \
"....................." \
"....................." \
"xxxxxxxx.xxx.xxxxxxxx" \
"xxxxxxx..xxx..xxxxxxx" \
".........xxx........." \
"........x.x.x........"
)
human.append(
"....................." \
"....................." \
"....................." \
"xxxxxxxx.xxx.xxxxxxxx" \
".........xxx........." \
".........xxx........." \
"........x.x.x........"
)
single = []
single.append(
".........xxx........." \
"........x...x........" \
".......x..x..x......." \
"......x...x...x......" \
"......xx..x..xx......" \
"........x...x........" \
".........xxx........."
)
single.append(
"........x.x.x........" \
"........xxxxx........" \
".......x..x..x......." \
"......x...x..xx......" \
"......xx..x..xx......" \
"........xxxxx........" \
"........x.x.x........"
)
single.append(
"....................." \
"........x.x.x........" \
"........xxxxx........" \
"......xx..x..xx......" \
".......xxxxxxx......." \
"........x.x.x........" \
"....................."
)
single.append(
"....................." \
"....................." \
"........x.x.x........" \
"......xxxxxxxxx......" \
"........x.x.x........" \
"....................." \
"....................."
)
def blink(led, eyeset, blinktime = 0.05):
for frame in eyeset + eyeset[::-1]:
led.showascii(frame)
time.sleep(blinktime)
######################################
# The available eye sets
eyesets = {
'happy' : happy,
'grumpy' : grumpy,
'kitty' : kitty,
'single' : single,
'teeth' : teeth,
'human' : human
}
# Get the command-line options to decide which set of eyes to display, and open or shut
parser = argparse.ArgumentParser()
parser.add_argument(
'-e', '--eyes',
default = 'kitty',
choices = sorted(eyesets.keys()),
help = 'Which set of eyes to show'
)
parser.add_argument(
'--shut',
action = 'store_true',
help = 'Add this to display with eyes shut'
)
parser.add_argument(
'-i', '--interactive',
action = 'store_true',
help = 'Interactively display the LED content in the shell'
)
args = parser.parse_args()
eyes = eyesets[args.eyes]
# Main control loop; placed in a function call so we can use it with curses
def mainui(cursesscr = False):
eyeswideshut = args.shut
try:
led = dcled.core.LED(cursesscr)
while (True):
if (eyeswideshut):
blinktime = 0.1
# Blink a few times before closing your eyes
for i in range(0, random.randint(2,4)):
blink(led, eyes, blinktime)
# Close your eyes (skip the first frame because we showed it during the blink
for frame in eyes[1:]:
led.showascii(frame)
time.sleep(blinktime)
# Asleep
led.showascii(eyes[-1])
if (cursesscr):
cursesscr.timeout(-1)
while (cursesscr.getch() != ord(' ')):
pass
else:
while (True):
time.sleep(1000)
eyeswideshut = False
else:
blinktime = 0.05
# Open your eyes
for frame in eyes[::-1]:
led.showascii(frame)
time.sleep(blinktime)
# Wake up by blinking a few times
for i in range(0, random.randint(1,3)):
blink(led, eyes, blinktime)
# Awake
while True:
# Blink animation
blink(led, eyes, blinktime)
led.showascii(eyes[0])
# Eyes open for random duration
if (cursesscr):
key = -1
# time in seconds
timeremaining = timeout = random.randint(0,6)
timestart = time.time()
while timeremaining > 0 and key != ord(' '):
# timeout takes milliseconds
cursesscr.timeout(int(timeremaining * 1000))
key = cursesscr.getch()
timeremaining = timeout - (time.time() - timestart)
if (key == ord(' ')):
break
else:
time.sleep(random.randint(0,6))
eyeswideshut = True
except (KeyboardInterrupt, SystemExit):
quit()
# If they want it interactive, use curses.wrapper to reset the shell when the program exits
if args.interactive:
curses.wrapper(mainui)
else:
mainui()