2017-08-29 17:27:06 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
|
|
|
import ox
|
2017-10-16 18:31:44 +00:00
|
|
|
import lanbox
|
2023-10-06 22:21:26 +00:00
|
|
|
import sacn
|
2017-10-16 18:31:44 +00:00
|
|
|
|
|
|
|
from .pi import random
|
2023-10-06 22:21:26 +00:00
|
|
|
from . import config
|
2017-10-16 18:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Screen 1-5, Control, 6,7
|
|
|
|
'''
|
|
|
|
> _*10 patterns / cues that correspond to 10 digit:*_
|
|
|
|
> 0 = Screen LED @ 100% fade time = 9s (cue list 1)
|
|
|
|
> 1 = LED Control @ 10% fade time = 8s (cue list 2)
|
|
|
|
> 2 = LED Control @ 20% fade time = 7s (cue list 3)
|
|
|
|
> 3 = LED Control @ 30% fade time = 6s (cue list 4)
|
|
|
|
> 4 = LED Control @ 40% fade time = 5s (cue list 5)
|
|
|
|
> 5 = LED Control @ 50% fade time = 4s (cue List 6)
|
|
|
|
> 6 = LED Control @ 60% fade time = 3s (cue list 7)
|
|
|
|
> 7 = LED Control @ 70% fade time = 2s (cue list 8)
|
|
|
|
> 8 = LED Control @ 80% fade time = 1s (cue list 9)
|
|
|
|
> 9 = LED Control @ 90% fade time = 0s (cue list 10)
|
|
|
|
'''
|
|
|
|
def channels(screen, control):
|
|
|
|
screen = int(screen * 255)
|
|
|
|
control = int(control * 255)
|
|
|
|
return {'1': screen, '2': screen, '3': screen, '4': screen, '5': screen, '6': control, '7': control}
|
|
|
|
|
|
|
|
|
|
|
|
LIGHTS = {
|
|
|
|
0: (channels(1, 0.0), 9),
|
|
|
|
1: (channels(0, 0.1), 8),
|
|
|
|
2: (channels(0, 0.2), 7),
|
|
|
|
3: (channels(0, 0.3), 6),
|
|
|
|
4: (channels(0, 0.4), 5),
|
|
|
|
5: (channels(0, 0.5), 4),
|
|
|
|
6: (channels(0, 0.6), 3),
|
|
|
|
7: (channels(0, 0.7), 2),
|
|
|
|
8: (channels(0, 0.8), 1),
|
|
|
|
9: (channels(0, 0.9), 0.1),
|
|
|
|
}
|
|
|
|
|
2023-10-06 22:21:26 +00:00
|
|
|
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
|
2017-10-16 18:31:44 +00:00
|
|
|
|
|
|
|
|
2023-10-06 22:21:26 +00:00
|
|
|
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
|
2023-10-12 09:10:22 +00:00
|
|
|
switch = 0
|
2023-10-06 22:21:26 +00:00
|
|
|
while steps:
|
2023-10-12 09:10:22 +00:00
|
|
|
switch += 1
|
2023-10-06 22:21:26 +00:00
|
|
|
value += delta
|
|
|
|
n = int(round(value))
|
|
|
|
if n != current:
|
|
|
|
current = n
|
2023-10-12 09:10:22 +00:00
|
|
|
old = sender[1].dmx_data[:16]
|
|
|
|
target = [n] * 16
|
|
|
|
if switch % 2:
|
|
|
|
a = target
|
|
|
|
b = old
|
|
|
|
else:
|
|
|
|
a = old
|
|
|
|
b = target
|
|
|
|
sender[1].dmx_data = [a[x] if x % 2 else b[x] for x in range(16)]
|
2023-10-06 22:21:26 +00:00
|
|
|
CURRENT_STATE = sender[1].dmx_data[:16]
|
|
|
|
time.sleep(step)
|
|
|
|
steps -= 1
|
|
|
|
time.sleep(1)
|
|
|
|
sender.stop()
|
|
|
|
|
|
|
|
|
|
|
|
def switch(state):
|
|
|
|
lights, duration = LIGHTS[state]
|
|
|
|
if config.lanbox:
|
|
|
|
lb = lanbox.Lanbox()
|
|
|
|
#lb.getChannels(lights)
|
|
|
|
#lb.fadeTo(lights, fade)
|
|
|
|
lb.layerGo(state)
|
|
|
|
else:
|
2023-10-12 09:10:22 +00:00
|
|
|
brightness = lights['7']
|
2023-10-06 22:21:26 +00:00
|
|
|
fade_to(brightness, duration)
|
2017-10-16 18:31:44 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
path = sys.argv[1]
|
2017-10-16 19:31:13 +00:00
|
|
|
no_sleep = len(sys.argv) > 2
|
2017-10-16 18:31:44 +00:00
|
|
|
|
|
|
|
n = int(os.path.getctime(path) - 1495280000)
|
|
|
|
info = ox.avinfo(path)
|
|
|
|
duration = info.get('duration', 0)
|
|
|
|
|
|
|
|
seq = random(n * 1000)
|
|
|
|
pos = 0
|
|
|
|
lights = []
|
|
|
|
while pos < duration - 15:
|
|
|
|
sleep = seq() + 15
|
|
|
|
light = seq()
|
|
|
|
if pos + sleep > duration:
|
|
|
|
break
|
2017-10-16 19:31:13 +00:00
|
|
|
if not no_sleep:
|
|
|
|
time.sleep(sleep)
|
2017-10-16 18:31:44 +00:00
|
|
|
switch(light)
|
|
|
|
pos += sleep
|