-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowassist.py
748 lines (622 loc) · 28.1 KB
/
snowassist.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Run a recognizer using the Google Assistant Library with button support.
The Google Assistant Library has direct access to the audio API, so this Python
code doesn't need to record audio. Hot word detection "OK, Google" is supported.
It is available for Raspberry Pi 2/3 only; Pi Zero is not supported.
"""
import logging
import platform
import sys
import threading
import os
import random
import subprocess
import signal
import time
import re
#import os.path
#from demo_opts import get_device
#from PIL import Image, ImageSequence
#from luma.core.sprite_system import framerate_regulator
from rpi_ws281x import PixelStrip, Color
from google.assistant.library.event import EventType
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1327, ssd1331, sh1106
from PIL import Image, ImageSequence
from luma.core.sprite_system import framerate_regulator
#from demo_opts import get_device
# Box and text rendered in portrait mode
#import os.path
#from demo_opts import get_device
#from PIL import Image, ImageSequence
#from luma.core.sprite_system import framerate_regulator
#Import animated_gif as display
#then call display.main
from aiy.assistant import auth_helpers
from aiy.assistant.library import Assistant
from aiy.board import Board, Led
#from aiy.voice import tts #added-google
import aiy.voice.tts
import mod.snowboydecoder as snowboydecoder #added
#subprocess.init()
LED_COUNT = 12
LED_PIN = 10
LED_FREQ_HZ = 800000
LED_DMA = 10
LED_BRIGHTNESS = 10
LED_INVERT = False
LED_CHANNEL = 0
#added
if len(sys.argv) == 1:
print("Error: need to specify model name")
print("Usage: python demo.py your.model")
sys.exit(-1)
model = sys.argv[1]
#/added
#global variables
strradiopart1 = "rtl_fm -f "
strradiopart2 = " -s 200000 -r 48000 -l 70 | aplay -r 48000 -f S16_LE"
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
serial = i2c(port=1, address=0x3C)
device = ssd1327(serial, width=128, height=128, rotate=0)
class MyAssistant:
"""An assistant that runs in the background.
The Google Assistant Library event loop blocks the running thread entirely.
To support the button trigger, we need to run the event loop in a separate
thread. Otherwise, the on_button_pressed() method will never get a chance to
be invoked.
"""
def __init__(self):
self._task = threading.Thread(target=self._run_task)
self._hotword = threading.Thread(target=self._run_hotword) #added
self._can_start_conversation = False
self._assistant = None
self._board = Board()
self._board.button.when_pressed = self._on_button_pressed
#self._say_omni = threading.Thread(target=self._say_omni)
def start(self):
"""Starts the assistant.
Starts the assistant event loop and begin processing events.
"""
self._task.start()
self._hotword.start()
def _run_task(self):
credentials = auth_helpers.get_assistant_credentials()
with Assistant(credentials) as assistant:
self._assistant = assistant
for event in assistant.start():
self._process_event(event)
#added
def _run_hotword(self):
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.4)
#with aiy.voice.audio.get_recorder():
while True:
if self._can_start_conversation:
#self._board.led.state = Led.ON
detector.start(detected_callback=self._on_button_pressed,
interrupt_check=lambda: not(self._can_start_conversation),
sleep_time=0.03)
detector.terminate()
#/added
def say_omni(self):
aiy.voice.tts.say('words are hard', lang="en-GB", pitch=10, speed=80)
# os.system("mpg321 ignition1.mp3")
# /added
def say_ip(self):
ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True)
aiy.voice.tts.say('My IP address is %s' % ip_address.decode('utf-8'), lang="en-GB", pitch=10, speed=80)
# added
def get_temp(self):
cputemp = subprocess.check_output("vcgencmd measure_temp", shell=True)
#Try adding universal_newlines=False to above, to change to string
cputemp2 = os.popen('vcgencmd measure_temp').readline()
print(os.system('vcgencmd measure_temp'))
cputemp2.replace("temp=","")
#cputemp = cputemp.replace("temp=","")
print(cputemp2)
aiy.voice.tts.say('I am burning up, my %s' % cputemp.decode('utf-8'), lang="en-GB", pitch=10, speed=80)
##Radio Commands
def stop_radio(self):
try:
process = int(subprocess.check_output(["pidof", "rtl_fm"]))
print("Process pid = ", process)
# os.system('kill -9 ' + process)
os.kill(process, signal.SIGINT)
time.sleep(1)
os.system('amixer set Master 85%')
except:
aiy.voice.tts.say('Nothing is playing at the moment', lang="en-GB", pitch=10, speed=80)
def radio_volume(self):
audiolevel = re.sub("\D", "", text)
print('amixer set Master ' + audiolevel + '%')
#aiy.voice.tts.say('setting volume')
os.system('amixer set Master ' + audiolevel + '%')
# def start_radio(self):
##Test Area
def _process_event(self, event):
logging.info(event)
if event.type == EventType.ON_START_FINISHED:
self._board.led.status = Led.BEACON_DARK # Ready.
self._can_start_conversation = True
# Start the voicehat button trigger.
logging.info('Say "OK, Google" or press the button, then speak. '
'Press Ctrl+C to quit...')
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
lightcircle.loadColor(strip, Color(255, 0, 0))
os.system("aplay sfx/red1.wav")
#self.loadColor(strip, Color(0, 0, 255))
#strip.setPixelColor(0, 0, 255, 0)
#strip.show()
self._can_start_conversation = False
self._board.led.state = Led.ON # Listening.
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args:
print('You said:', event.args['text'])
lightcircle.loadColor(strip, Color(0, 255, 0))
text = event.args['text'].lower()
if text == 'power off':
self._assistant.stop_conversation()
power_off_pi()
elif text == 'reboot':
self._assistant.stop_conversation()
reboot_pi()
elif text == 'local ip':
self._assistant.stop_conversation()
print('localip')
# ip_address = os.system('hostname -I')
# print(ip_address + "derp")
# ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True)
# aiy.voice.tts.say('My IP address is %s' % ip_address.decode('utf-8'), lang="en-GB", pitch=10, speed=80)
# print("worked")
# aiy.voice.tts.say('My IP address is %s' % ip_address.decode('utf-8'))
self.say_ip()
elif text == 'get temp':
self._assistant.stop_conversation()
self.get_temp()
#Mechanicus Quotes
elif text == 'tell me a quote':
self._assistant.stop_conversation()
#for x in range(10):
randnum = random.randint(1, 10)
print(randnum)
if randnum == 1:
print('Playing Omni2')
os.system("mpg321 ./quotes/quote_servo_allpraiseomni.mp3")
elif randnum == 2:
print('Playing igintion')
os.system("mpg321 ./quotes/quote_ignition1.mp3")
elif randnum == 3:
print('Playing greatbell_de')
os.system("mpg321 ./quotes/quote_greatbell_de.mp3")
elif randnum == 4:
print('Playing greaterwork aus')
os.system("mpg321 ./quotes/quote_greater_work_aus.mp3")
elif randnum == 5:
print('Playing korielzeth')
os.system("mpg321 ./quotes/quote_koriel_zeth.mp3")
elif randnum == 6:
print('Playing lordofengines')
os.system("mpg321 ./quotes/quote_lordoftheengines.mp3")
elif randnum == 7:
print('Playing stealandwire')
os.system("mpg321 ./quotes/quote_steelandwire.mp3")
elif randnum == 8:
print('Playing warnings')
os.system("mpg321 ./quotes/quote_warnings_adeptusmechanicus.mp3")
else:
#os.system("mpg321 ./quotes/quote_servo_allpraiseomni.mp3")
aiy.voice.tts.say('I have nothing to say at the moment',lang="en-GB", pitch=10, speed=80 )
# RTL-SDR Control
elif 'turn on radio' in text:
self._assistant.stop_conversation()
#Splits up sentance
#textlist = text.split()
#print("last word" + textlist[0] + textlist[-1] + textlist[3])
#freq = input('Enter freq ') + "M"
#Gets Numbers for frequency
freq = re.sub("\D", "", text)
print(freq)
numcount = len(freq)
print(numcount)
if numcount == 3:
freq = freq + "000K"
elif numcount == 4:
freq = freq + "00K"
elif numcount == 5:
freq = freq + "0K"
else:
freq = freq + "K"
#freq = textlist[-1] + "M"
print("it worked " + freq)
part1 = "rtl_fm -f "
part2 = " -M wbfm -p 59 -r 48k -s 210K -r 48000 - | aplay -r 48000 -f S16_LE"
cmd = part1 + freq + part2
print(cmd)
thevolume = 30
print('amixer set Master ' + str(thevolume) + '%')
os.system('amixer set Master ' + str(thevolume) + '%')
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
#self._assistant.start_conversation()
#if text == "list frequency":
# text = event.args['text'].lower()
# print(text + " is it working? " + freq)
#Figure out how to do nested commands
#self._assistant.stop_conversation()
#print()
elif text == 'air band':
self._assistant.stop_conversation()
#print(part1)
abscan = "rtl_fm -M am -f 118M:137M:25k -s 12k -g 50 -l 100 | aplay -r 12000 -f S16_LE"
os.system('amixer set Master 50%')
subprocess.Popen(abscan, stdout=subprocess.PIPE, shell=True)
elif "ham radio" in text :
self._assistant.stop_conversation()
os.system('amixer set Master 30%')
freq = re.sub("\D", "", text)
print(freq)
numcount = len(freq)
print(numcount)
if numcount == 3:
freq = freq + "000K"
elif numcount == 4:
freq = freq + "00K"
elif numcount == 5:
freq = freq + "0K"
else:
freq = freq + "K"
print("Selected Frequency: " + freq)
part1 = "rtl_fm -f "
part2 = " -M wbfm -p 59 -r 48k -s 210K -r 48000 -l 150 | aplay -r 48000 -f S16_LE"
cmd = part1 + freq + part2
print(cmd)
#thevolume = 30
#print('amixer set Master ' + str(thevolume) + '%')
#os.system('amixer set Master ' + str(thevolume) + '%')
subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
elif text == 'scan ham band':
self._assistant.stop_conversation()
#print(part1)
hamscan = "rtl_fm -f 145M:148M:5k -M wbfm -p 59 -r 48k -s 210K -r 48000 -l 150 | aplay -r 48000 -f S16_LE"
os.system('amixer set Master 50%')
subprocess.Popen(hamscan, stdout=subprocess.PIPE, shell=True)
elif text == 'terminate radio':
self._assistant.stop_conversation()
self.stop_radio()
#process = int(subprocess.check_output(["pidof", "rtl_fm"]))
#print("Process pid = ", process)
##os.system('kill -9 ' + process)
#os.kill(process,signal.SIGINT)
#subprocess.Popen.terminate()
elif text == "reset audio":
self._assistant.stop_conversation()
os.system('amixer set Master 85%')
#Playing Mechanicus Music
elif "play music" in text:
self._assistant.stop_conversation()
os.system("amixer set Master 30%")
#subprocess.Popen('mpg321 /mnt/nas_store/Music/Mechanicus/*', stdout=subprocess.PIPE, shell=True)
#Music needs to terminate before switching types
#last word, playlist outrun, warhammer, all
textlist = text.split()
print(textlist[-1])
lastword = textlist[-1]
if "warhammer" in lastword:
subprocess.Popen('mpg321 /mnt/nas_store/Music/Mechanicus/*', stdout=subprocess.PIPE, shell=True)
elif "outrun" in lastword:
subprocess.Popen('mpg321 -B /mnt/nas_store/Music/Outrun/*', stdout=subprocess.PIPE, shell=True)
elif "folder" in lastword:
#Insert Test MP3 and test MP3 in sub folder
subprocess.Popen('mpg321 -B /mnt/nas_store/Music/Outrun/*', stdout=subprocess.PIPE, shell=True)
elif "terminate music" in text:
self._assistant.stop_conversation()
try:
self._assistant.stop_conversation()
process = int(subprocess.check_output(["pidof", "mpg321"]))
print("Process pid = ", process)
#os.system('kill ' + process)
os.kill(process,signal.SIGQUIT)
#os.kill(process, signal.SIGINT)
time.sleep(1)
os.system('amixer set Master 85%')
except:
self._assistant.stop_conversation()
aiy.voice.tts.say('nothing is playing at the moment',lang="en-GB", pitch=10, speed=80 )
#Test Area
elif 'set audio level' in text:
self._assistant.stop_conversation()
#self.radio_volume()
audiolevel = re.sub("\D", "", text)
os.system('amixer set Master ' + audiolevel + '%')
print(text+" workies?")
elif 'lights' in text:
self._assistant.stop_conversation()
#display_oled.cleardisplay()
#time.sleep(10)
#display_oled.aquila('decal5.png')
display_oled.display_decal()
#strip.setPixelColor(1, Color(255, 0, 0))
#strip.show()
#loadColor(strip, Color(255,0,0))
print("startlights")
lightcircle.loadColor(strip, Color(0, 255, 0))
time.sleep(1)
#lightcircle.pulse(self)
elif "terminate display" in text:
self._assistant.stop_conversation()
print("terminating display")
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
elif "testing" in text:
self._assistant.stop_conversation()
print(text+" workies?")
elif text.startswith("world"):
self._assistant.stop_conversation()
print("hello you're an idiot" + text)
textlist = text.split()
print("last word" + textlist[0] + textlist[-1] + textlist[3])
elif "get numbers" in text:
self._assistant.stop_conversation()
print(text)
numbs = re.sub("\D", "", text)
print("numbers are " + numbs)
numcount = len(numbs)
print(numcount)
if numcount == 4:
numbs = numbs + "00K"
else:
numbs = numbs + "0K"
#numbs = filter(lambda x: x.isdigit(), text)
#numbs = int(filter(text.isdigit(), str1))
print(numbs)
elif text == 'litany of ignition':
self._assistant.stop_conversation()
say_words()
elif text == 'something':
self._assistant.stop_conversation()
print("helloworld")
aiy.voice.tts.say('hello', lang="en-GB", pitch=10, speed=80)
# os.system("aplay red1.wav")
self.say_omni()
#/added
elif event.type == EventType.ON_END_OF_UTTERANCE:
self._board.led.state = Led.PULSE_QUICK # Thinking.
elif (event.type == EventType.ON_CONVERSATION_TURN_FINISHED
or event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT
or event.type == EventType.ON_NO_RESPONSE):
self._board.led.state = Led.BEACON_DARK # Ready.
self._can_start_conversation = True
elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']:
sys.exit(1)
def _on_button_pressed(self):
# Check if we can start a conversation. 'self._can_start_conversation'
# is False when either:
# 1. The assistant library is not yet ready; OR
# 2. The assistant library is already in a conversation.
if self._can_start_conversation:
self._assistant.start_conversation()
class lightcircle:
def loadColor(strip, color, wait_ms=5000):
# for i in range(strip.numPixels()):
strip.setPixelColor(0, color)
strip.setPixelColor(1, color)
strip.setPixelColor(2, color)
strip.setPixelColor(3, color)
strip.setPixelColor(4, color)
strip.setPixelColor(5, color)
strip.setPixelColor(6, color)
strip.setPixelColor(7, color)
strip.setPixelColor(8, color)
strip.setPixelColor(9, color)
strip.setPixelColor(10, color)
strip.setPixelColor(11, color)
strip.show()
#time.sleep(wait_ms / 1000.0)
def pulse(self):
for i in range(10):
for i in range(5, 20, 2):
time.sleep(.2)
strip.setBrightness(i)
#print(i)
strip.show()
# fade out
for i in range(20, 5, -2):
time.sleep(.2)
strip.setBrightness(i)
#print(i)
strip.show()
class display_oled:
def aquila(img):
device.show()
# img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
# 'images', img))
# Image.open(img_path)
# background = Image.new("RGBA", device.size, "black")
# device.display(background.convert(device.mode))
regulator = framerate_regulator(fps=0)
img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'images', img))
banana = Image.open(img_path)
size = [min(*device.size)] * 2
posn = ((device.width - size[0]) // 2, device.height - size[1])
while True:
for frame in ImageSequence.Iterator(banana):
with regulator:
background = Image.new("RGB", device.size, "white")
background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
device.display(background.convert(device.mode))
def cleardisplay():
#device.display.clear(self)
background = Image.new("RGBA", device.size, "black")
device.display(background.convert(device.mode))
print("clearing oled")
device.clear()
print("hide oled")
device.hide()
def showpic():
img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'images', 'pi_logo.png'))
logo = Image.open(img_path).convert("RGBA")
fff = Image.new(logo.mode, logo.size, (255,) * 4)
background = Image.new("RGBA", device.size, "white")
posn = ((device.width - logo.width) // 2, 0)
while True:
for angle in range(0, 360, 2):
rot = logo.rotate(angle, resample=Image.BILINEAR)
img = Image.composite(rot, fff, rot)
background.paste(img, posn)
device.display(background.convert(device.mode))
def display_decal():
os.killpg(os.getpgid(display_oled.display_aquila().proc.pid), signal.SIGTERM)
time.sleep(1)
display_oled.cleardisplay()
proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True,
preexec_fn=os.setsid)
# try:
# print("killing process2")
# os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
#
# print("displaying decal")
# proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128',
# stdout=subprocess.PIPE, shell=True,
# preexec_fn=os.setsid)
# except:
# proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True,
# preexec_fn=os.setsid)
def display_aquila():
proc = subprocess.Popen('./aquila.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE,
shell=True, preexec_fn=os.setsid)
# proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True,
# preexec_fn=os.setsid)
#fgprocid = os.getpgid(aqproc.pid)
#print("aquila", proc.pid)
#print("decal", proc.pid)
#time.sleep(10)
#print("killing process")
#os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
#device.hide()
#device.show()
# display_oled.cleardisplay()
#time.sleep(10)
#display_oled.display_decal()
# proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True,
# preexec_fn=os.setsid)
# try:
# print("displaying aquila")
# aqproc = subprocess.Popen('./aquila.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE,
# shell=True, preexec_fn=os.setsid)
# #print(os.getpgid(aqproc.pid))
# #os.killpg(os.getpgid(aqproc.pid), signal.SIGTERM)
#
# print("displaying decal")
# # proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128',
# # stdout=subprocess.PIPE, shell=True,
# # preexec_fn=os.setsid)
# except:
# print("error")
# # proc = subprocess.Popen('./disp_decal.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True,
# # preexec_fn=os.setsid)
def main():
logging.basicConfig(level=logging.INFO)
#Add random quotes here, and movements
#strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()
#loadColor(strip, Color(255, 0, 255))
#strip.setPixelColor(11, Color(255, 0, 255))
#strip.show()
MyAssistant().start()
# strip.setPixelColor(1, Color(255, 0, 0))
# strip.show()
# loadColor(strip, Color(255,0,0))
#print("starlights")
#while True:
# for frame in ImageSequence.Iterator(banana):
# with regulator:
# background = Image.new("RGB", device.size, "white")
# background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
# device.display(background.convert(device.mode))
#display_oled.aquila(self)
# aqproc = subprocess.Popen('./aquila.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE,
# shell=True, preexec_fn=os.setsid)
display_oled.display_aquila()
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0, 255, 0))
strip.show()
time.sleep(.05)
strip.setPixelColor(0, Color(0, 255, 0))
strip.setPixelColor(1, Color(0, 255, 0))
strip.setPixelColor(2, Color(0, 255, 0))
strip.setPixelColor(3, Color(0, 255, 0))
strip.setPixelColor(4, Color(0, 255, 0))
strip.setPixelColor(5, Color(0, 255, 0))
strip.setPixelColor(6, Color(0, 255, 0))
strip.setPixelColor(7, Color(0, 255, 0))
strip.setPixelColor(8, Color(0, 255, 0))
strip.setPixelColor(9, Color(0, 255, 0))
strip.setPixelColor(10, Color(0, 255, 0))
strip.setPixelColor(11, Color(0, 255, 0))
strip.show()
for x in range(5):
for i in range(5, 10, 2):
time.sleep(.1)
strip.setBrightness(i)
#print(i)
strip.show()
# fade out
for i in range(10, 5, -2):
time.sleep(.1)
strip.setBrightness(i)
#print(i)
strip.show()
#display_oled.aquila()
#time.sleep(100)
#print("putting to sleepclear screen")
#display_oled.cleardisplay()
#procid = subprocess.Popen.pid
#print("killing aquila")
#os.killpg(os.getpgid(aqproc.pid), signal.SIGTERM)
#display_oled.cleardisplay()
# process = int(subprocess.check_output(["pidof", "mpg321"]))
# print("Process pid = ", process)
# # os.system('kill ' + process)
# os.kill(process, signal.SIGQUIT)
#print('displaying mechanicus')
#proc = subprocess.Popen('./piquila.py --display ssd1327 --width 128 --height 128', stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
#time.sleep(10)
#print("killing mech")
#os.killpg(os.getpgid(mechproc.pid), signal.SIGTERM)
#display_oled.aquila('mechanicus.png')
# print("display oled")
# regulator = framerate_regulator(fps=0)
# img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
# 'images', 'aquila_mono_fix.gif'))
# banana = Image.open(img_path)
# size = [min(*device.size)] * 2
# posn = ((device.width - size[0]) // 2, device.height - size[1])
# index = 1
# while True:
# for frame in ImageSequence.Iterator(banana):
# with regulator:
# background = Image.new("RGB", device.size, "white")
# background.paste(frame.resize(size, resample=Image.LANCZOS), posn)
# device.display(background.convert(device.mode))
# print(index)
# index = index + 1
#with canvas(device) as draw:
# draw.rectangle(device.bounding_box, outline="white", fill="black")
# draw.text((10, 40), "Hello World", fill="white")
#lightcircle.loadColor(strip, Color(0, 255, 255))
#loadColor(strip, Color(0, 0, 255))
if __name__ == '__main__':
main()