-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlights.py
90 lines (72 loc) · 2.34 KB
/
lights.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
import SocketServer
import datetime
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(28, GPIO.OUT)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(30, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)
## 4 of lights one and they are the first 4 lights in the chain. Each of the lights takes 4 inputs, brightness, red,green,blue
##the 5th light is a special case
import array
from ola.ClientWrapper import ClientWrapper
wrapper = ClientWrapper()
def DmxSent(state):
wrapper.Stop()
def lights_start(bright,red,green,blue,rotate,sp):
lights_do(0,0,0,0,0,1)
lights_do(bright,red,green,blue,rotate,sp)
def lights_do(bright,red,green,blue,rotate,sp): # 255, 0,0,255, 175, 206
universe = 1
GPIO.output(29,True)
f = open('/tmp/myfile','w')
f.write('hi')
data = array.array('B')
light_data = [bright,red,green,blue,rotate]
normal_light = light_data[:-1]
tmp = [data.append(x) for x in normal_light*4]
if sp == 1 :
tmp = [data.append(x) for x in light_data]
# data = array.array('B')
# data.append(bright)
# data.append(red)
# data.append(green)
# data.append(blue)
# data.append(bright)
# data.append(red)
# data.append(green)
# data.append(blue)
# data.append(bright)
# data.append(red)
# data.append(green)
# data.append(blue)
# data.append(bright)
# data.append(red)
# data.append(green)
# data.append(blue)
# data.append(bright)
# data.append(red)
# data.append(green)
# data.append(blue)
# data.append(rotate)
#wrapper = ClientWrapper()
client = wrapper.Client()
client.SendDmx(universe, data, DmxSent)
wrapper.Run()
class MyTCPHandler(SocketServer.StreamRequestHandler):
def handle(self):
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
self.data = self.rfile.readline().strip()
print self.data
list_vals = [int(x) for x in self.data.split(",")]
lights_start(*list_vals)
# Likewise, self.wfile is a file-like object used to write back
# to the client
self.wfile.write("YES")
HOST, PORT = "0.0.0.0", 9999
###lights(255, 0,0,255,255)
# Create the server, binding to localhost on port 9999
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()