diff --git a/cdoseaplay/config.py b/cdoseaplay/config.py index c83db96..391ec84 100644 --- a/cdoseaplay/config.py +++ b/cdoseaplay/config.py @@ -6,6 +6,7 @@ base = 'https://cdosea.0x2620.org/static/render/' lang = '1080p' start = '' lights = False +lanbox = False font = 'Menlo' # SimHei for chinese font_size = 28 diff --git a/cdoseaplay/lights.py b/cdoseaplay/lights.py index 533c8a2..008433e 100755 --- a/cdoseaplay/lights.py +++ b/cdoseaplay/lights.py @@ -6,8 +6,10 @@ import time import ox import lanbox +import sacn from .pi import random +from . import config # Screen 1-5, Control, 6,7 @@ -43,14 +45,61 @@ LIGHTS = { 9: (channels(0, 0.9), 0.1), } +CURRENT_STATE = [0] * 16 + + +def send(state): + sender = sacn.sACNsender() + sender.start() + universe = 1 + sender.activate_output(universe) + sender[1].multicast = True + n = 16 + while n: + sender[1].dmx_data = [value] * n + time.sleep(1) + n -= 1 + + sender[1].dmx_data = [0] + time.sleep(10) # send the data for 10 seconds + + +def fade_to(target, duration): + global CURRENT_STATE + sender = sacn.sACNsender() + sender.start() + universe = 1 + sender.activate_output(universe) + sender[1].multicast = True + current = CURRENT_STATE[0] + distance = target - current + steps = int(duration * 10) + step = duration/steps + delta = distance/steps + value = current + while steps: + value += delta + n = int(round(value)) + if n != current: + current = n + sender[1].dmx_data = [n] * 16 + CURRENT_STATE = sender[1].dmx_data[:16] + time.sleep(step) + steps -= 1 + time.sleep(1) + sender.stop() + def switch(state): - lights, fade = LIGHTS[state] - lb = lanbox.Lanbox() - #lb.getChannels(lights) - #lb.fadeTo(lights, fade) - lb.layerGo(state) - + lights, duration = LIGHTS[state] + if config.lanbox: + lb = lanbox.Lanbox() + #lb.getChannels(lights) + #lb.fadeTo(lights, fade) + lb.layerGo(state) + else: + brightness = round(lights['7'] / 255 * 50) + fade_to(brightness, duration) if __name__ == '__main__': path = sys.argv[1] diff --git a/setup.py b/setup.py index 3f1def4..aa5950d 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ setup( 'tornado', 'mpmath', 'lanbox', + 'sacn', 'mpv', ], keywords=[],