-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.py
executable file
·131 lines (119 loc) · 4.03 KB
/
consumer.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
#!/usr/bin/env python
from samplebase import SampleBase
from rgbmatrix import graphics,RGBMatrix
from random import randint
import time
import pika
from subprocess import call
class consumer(SampleBase):
def __init__(self, *args, **kwargs):
super(consumer, self).__init__(*args, **kwargs)
def Run(self):
#inicijalizcija varijabli i fonta i pocetnog teksta
self.matrix.brightness = 70
text=[]
sat = 0
text.append("Neo")
uCu=[]
offscreenCanvas = self.matrix.CreateFrameCanvas()
font = graphics.Font()
font.LoadFont("kset.bdf")
textColor = graphics.Color(255, 165, 0)
pos = offscreenCanvas.width
myText=''
#inicijalizacija konekcije na rabbitMQ
con = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
chan = con.channel()
chan.queue_declare(queue='theclock')
#fukcije za gumbice
def penis():
uCu.append('./demo -D1 -t 5 --led-chain=2 penis.ppm')
def kset():
text.append("KSET")
def helloKitty():
uCu.append('./demo -D1 -t 5 --led-chain=2 maca.ppm')
def tux():
uCu.append('./demo -D1 -t 5 --led-chain=2 tux.ppm')
animations={"Penis":penis,"Hello Kitty":helloKitty,"KSET":kset,"Tux":tux}
#funkcija koja se zove kada dodje nesto na queue
def callback(ch, method, properties, body):
body=body.decode("utf-8")
if body in animations:
return animations[body]()
else:
text.append(body)
#konzumacija podatka s queuea
chan.basic_consume(callback,queue='theclock',no_ack=True)
#petlja koja provjerava jel neka od lista sadrzi element i sukladno tome ispisuje element neke liste
ajde,textNova=0,[]
# ispis = ["10","9","8","7","6","5","4","3","2","1","0", "2016...pusi...kurac"]
# potencijalnoVrijeme = ["23:59:47","23:59:48","23:59:50","23:59:49","23:59:51"]
while True:
offscreenCanvas.Clear()
leng = graphics.DrawText(offscreenCanvas, font, pos, 28, textColor, myText)
pos -= 1
#izabire se novi prikaz
if (pos + leng < 0):
pos = offscreenCanvas.width
# if len(textNova)>0:
# myText=textNova.pop(0)
if len(text):
textColor=graphics.Color(0,255,0)
myText = text[0]
del text[0]
sat = 0
elif len(uCu):
#brisanje matrice, jer u suprotnom sve flickera u picku materinu
self.matrix=''
#izvrsavanje c koda u shellu
yay=call(uCu[0],shell=True)
del uCu[0]
self.matrix = RGBMatrix(self.args["rows"], self.args["chain"], self.args["parallel"])
self.matrix.pwmBits = self.args["pwmbits"]
self.matrix.brightness = self.args["brightness"]
offscreenCanvas = self.matrix.CreateFrameCanvas()
myText=time.strftime("%H:%M")
sat = 1
else:
textColor=graphics.Color(255,165,0)
myText=time.strftime("%H:%M")
sat = 1
# if (time.strftime("%H:%M:%S") in potencijalnoVrijeme) and len(textNova)==0:
# textNova = ["10","9","8","7","6","5","4","3","2","1","0","2016...pusi...kurac"]
# continue
#hehe
if myText=="16:20" or myText=="Kpop" or myText=="420":
textColor=graphics.Color(randint(0,255),randint(0,255),randint(0,255))
elif myText=="12:00":
textColor=graphics.Color(255,0,0)
myText="bum!"
elif myText=="16:00":
textColor=graphics.Color(255,255,0)
myText="gdje...je...onaj....cvijetak...zuti"
# elif myText in ispis:
# textColor=graphics.Color(randint(0,255),randint(0,255),randint(0,255))
offscreenCanvas = self.matrix.SwapOnVSync(offscreenCanvas)
#za novu godinu
# if myText in ispis:
# time.sleep(0.0085)
#za kontinuirano prikazivanje slika
# if sat==1 and len(uCu)==0:
# if ajde%5 == 0:
# ajde+=1
# uCu.append('./demo -D1 -t 5 --led-chain=2 chicats.ppm')
# elif ajde%5==1:
# ajde+=1
# uCu.append('./demo -D1 -t 5 --led-chain=2 druga.ppm')
# elif ajde%5==3:
# ajde+=1
# uCu.append('./demo -D1 -t 5 --led-chain=2 prva.ppm')
# else:
# ajde+=1
# uCu.append('./demo -D1 -t 5 --led-chain=2 treca.ppm')
if pos==-2 and sat==1:
chan.connection.process_data_events(time_limit=3)
else:
chan.connection.process_data_events(time_limit=0.03)
if __name__ == "__main__":
display=consumer()
display.process()