forked from muccc/acab-streetlife
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acabx.py
executable file
·64 lines (48 loc) · 1.31 KB
/
acabx.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
#!/usr/bin/env python
import socket
import exceptions
# Color system
def _filter_data_normalize(value):
try:
value = int(value)
except exceptions.ValueError:
return 0
if value < 0:
return 0
elif value > 255:
return 255
else:
return value
def get_filter_data(argv):
return (_filter_data_normalize(argv[0]), _filter_data_normalize(argv[1]), _filter_data_normalize(argv[2]))
def colorfilter(r, g, b, filter_data):
r_out = (r/255.0) * filter_data[0]
g_out = (g/255.0) * filter_data[1]
b_out = (b/255.0) * filter_data[2]
return (r_out, g_out, b_out)
# Sound system
sock = None
dest = None
# Init port
def init_beat_client(port, timeout = None):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0",port))
if timeout != None:
sock.settimeout(timeout)
return (sock, None, None)
# Init port
def init_beat_server(host, port, timeout = None):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if timeout != None:
sock.settimeout(timeout)
return (sock, host, port)
# Wait for beat
def wait_beat(data):
try:
data[0].recv(1)
except socket.timeout:
return False
return True
# Send beat to port
def send_beat(data):
data[0].sendto("1", (data[1], data[2]))