add sacn support

This commit is contained in:
j 2023-10-06 23:21:26 +01:00
parent ae30d09dc6
commit 1f4959d351
3 changed files with 57 additions and 6 deletions

View File

@ -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

View File

@ -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]

View File

@ -20,6 +20,7 @@ setup(
'tornado',
'mpmath',
'lanbox',
'sacn',
'mpv',
],
keywords=[],