-
Notifications
You must be signed in to change notification settings - Fork 5
/
set_colour_multizone.py
executable file
·78 lines (55 loc) · 2.07 KB
/
set_colour_multizone.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
#!/usr/bin/env python
"""
Simple implementation of colour-sending functionality,
without the ACK/retry functionality. Send only, no listen.
Author: Petr Klus
"""
import socket
import time
import sys
import random
import tools
from tools import gen_packet, get_colour_zones_packet
RETRIES = 2
DELAY = 0.05
UDP_PORT = 56700
SEQ_NUM = random.randint(0, 255)
def set_colour_zones(bulb_ip, start_index, end_index,
hue, sat, bri, kel, apply_changes, retries=RETRIES):
print(start_index, end_index, hue, sat, bri, kel, apply_changes)
for _ in range(retries):
sock.sendto(get_colour_zones_packet(start_index, end_index,
hue, sat, bri, kel, apply_changes, SEQ_NUM),
(bulb_ip, UDP_PORT))
time.sleep(DELAY)
if __name__ == "__main__":
print(sys.argv)
# different for each execution
print("Using sequence number:", SEQ_NUM)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
bulb_ip = sys.argv[1]
if len(sys.argv) == 2:
# demo
set_colour_zones(bulb_ip, 0, 255, 60, 100, 100, 3500, tools.APPLY)
time.sleep(1)
for i in range(15):
set_colour_zones(bulb_ip, i, i, 30 if i%2 == 0 else 120, 100, 100, 2500, tools.NO_APPLY, 1)
set_colour_zones(bulb_ip, 15, 15, 60, 100, 100, 3500, tools.NO_APPLY)
set_colour_zones(bulb_ip, 14, 14, 60, 0, 100, 6000, tools.APPLY_ONLY)
time.sleep(1)
# moving cursor
def draw_thingy(position):
# solid colour
set_colour_zones(bulb_ip, 0, 255, 10, 100, 60, 3500, tools.NO_APPLY)
# "cursor"
set_colour_zones(bulb_ip, position, position, 242, 100, 100, 3500, tools.APPLY)
for i in range(16):
draw_thingy(i)
time.sleep(0.1)
for i in range(16):
draw_thingy(15-i)
time.sleep(0.05)
else:
bulb_ip = sys.argv[1]
start_index, end_index, hue, sat, bri, kel, apply_changes = map(int, sys.argv[2:])
set_colour_zones(bulb_ip, start_index, end_index, hue, sat, bri, kel, apply_changes)