FireStar/firestar.py

91 lines
2.7 KiB
Python

#!/usr/bin/python3
from phue import Bridge
import time
b = Bridge('172.18.152.190')
Nedges = 30;
edgecode = [None] * Nedges;
# The edges are numbered as in info/SSDedges.obj; enter the two-letter code for
# the lightstrip inserted through each edge in the block below:
edgecode[ 0] = 'XX';
edgecode[ 1] = 'XX';
edgecode[ 2] = 'XX';
edgecode[ 3] = 'XX';
edgecode[ 4] = 'XX';
edgecode[ 5] = 'XX';
edgecode[ 6] = 'XX';
edgecode[ 7] = 'XX';
edgecode[ 8] = 'XX';
edgecode[ 9] = 'XX';
edgecode[10] = 'XX';
edgecode[11] = 'XX';
edgecode[12] = 'XX';
edgecode[13] = 'XX';
edgecode[14] = 'XX';
edgecode[15] = 'XX';
edgecode[16] = 'XX';
edgecode[17] = 'XX';
edgecode[18] = 'XX';
edgecode[19] = 'XX';
edgecode[20] = 'XX';
edgecode[21] = 'XX';
edgecode[22] = 'XX';
edgecode[23] = 'XX';
edgecode[24] = 'XX';
edgecode[25] = 'XX';
edgecode[26] = 'XX';
edgecode[27] = 'XX';
edgecode[28] = 'XX';
edgecode[29] = 'XX';
# End of edge codes; show automation follows
edges = [ b[code] for code in edgecode ]
def hueint(frac): return int(frac*65535)
# A "setting" is a pair of a list of N lists of edges, and a list of N dicts
# understandable by Bridge.set_light,
# e.g. {'bri' : 127, 'hue' : 43690, 'sat' : 224},
# which means to set the ith list of edges to the ith dict.
# Note the list of lists does not have to be a partition; edges not mentioned
# in any list will be left alone.
alltogether = [range(0,Nedges)];
thevoid = (alltogether, ['bri' : 0])
deepblue = (alltogether, [{'hue' : hueint(2/3), 'bri' : 254, 'sat' : 254}])
yelorng = (alltogether, [{'hue' : hueint(1/6), 'bri' : 254, 'sat' : 254}])
redred = (alltogether, [{'hue' : 0, 'bri' : 254, 'sat' : 254}])
# A "simpleshow" is a pair of a list of settings, and a list of triples of
# integers: (setting_index, transition_to, hold_time)
# where setting_index is an index into the list of settings, and transition_to
# and hold_time are times in deciseconds to take to morph to the given
# setting, and then hold at the given setting before the next step of the
# simpleshow.
intro = ([thevoid, deepblue, yelorng, redred],
[(0,1,0), (1,30,20),
(2,1,3), (1,1,3), (2,1,3), (1,1,3), (2,1,3), (1,1,3), (2,1,0),
(3,50,20), (0,30,5)]
)
def runsimple(ss):
'''Takes one argument, a simple show; causes the simple show to be
executed on the FireStar
'''
settings = ss[0]
for (setting_index, transition_to, hold_time) in ss[1]:
theset = settings[setting_index]
subs = theset[0]
cmds = theset[1]
nsubs = length(subs)
for i in range(0,nsubs):
thiscmd = cmds[i].copy()
thiscmd['transitiontime'] = transition_to
b.set_light([edges[e].light_id for e in subs[i]], thiscmd)
time.sleep(hold_time/10)
runsimple(intro)