-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightctl.py
executable file
·52 lines (45 loc) · 1.79 KB
/
lightctl.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
#!/usr/bin/env python3
"""
Set the color on a fibre-enabled light controller.
"""
import argparse
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + "/fibre/python")
import fibre
# Parse arguments
parser = argparse.ArgumentParser(description='Set the color on a fibre-enabled light controller.')
parser.add_argument("-v", "--verbose", action="store_true",
help="print debug information")
parser.add_argument("--host", metavar="HOSTNAME", action="store",
help="Specifies the host or IP address of the light controller.")
parser.add_argument("color", metavar="WWRRGGBB", type=str, nargs=1,
help="Specifies the color code.")
parser.add_argument("-t", "--time", metavar="SECONDS", type=float,
help="Fade duration. Defaults to 0.")
parser.add_argument("-l", "--limit-brightness", action="store_true",
help="don't increase brightness")
parser.set_defaults(host="tcp:192.168.178.36:9910", time=0)
args = parser.parse_args()
try:
color = int(args.color[0], 16)
except ValueError:
parser.print_usage(file=sys.stderr)
sys.stderr.write("error: expected hexadecimal color code\n")
sys.exit(1)
# Connect to device
if (args.verbose):
printer = print
else:
printer = lambda x: None
lightcontroller = fibre.find_any(path=(args.host), timeout=100)
# Set color
lightcontroller.set_color(float((color >> 24) & 0xff) / 255,
float((color >> 16) & 0xff) / 255,
float((color >> 8) & 0xff) / 255,
float((color >> 0) & 0xff) / 255,
args.time,
1 if args.limit_brightness else 0)
#lightcontroller.ledstrip1.start_music()
lightcontroller._close()
#import ipdb; ipdb.set_trace()