trigger lights

This commit is contained in:
j 2017-10-16 20:31:44 +02:00
parent 64718a7c61
commit 02b06c6581
7 changed files with 100 additions and 29 deletions

View file

@ -1,16 +1,17 @@
import os
import json import json
import os
import sys
base = 'https://cdosea.0x2620.org/static/render/' base = 'https://cdosea.0x2620.org/static/render/'
lang = '1080p' lang = '1080p'
start = '' start = ''
lights = False
conf = os.path.expanduser('~/.config/cdosea.json') conf = os.path.expanduser('~/.config/cdosea.json')
if os.path.exists(conf): if os.path.exists(conf):
with open(conf) as fd: with open(conf) as fd:
config = json.load(fd) config = json.load(fd)
if 'lang' in config: _this = sys.modules[__name__]
lang = config['lang'] for key in config:
if 'base' in config: setattr(_this, key, config[key])
base = config['base']
if 'start' in config:
start = config['start']

View file

@ -5,22 +5,67 @@ import os
import time import time
import ox import ox
from pi import random import lanbox
path = sys.argv[1] from .pi import random
n = int(os.path.getctime(path) - 1495280000)
duration = ox.avinfo(path)['duration']
seq = random(n * 1000) # Screen 1-5, Control, 6,7
pos = 0 '''
lights = [] > _*10 patterns / cues that correspond to 10 digit:*_
while pos < duration - 15: > 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),
}
def switch(state):
lights, fade = LIGHTS[state]
lb = lanbox.LanboxMethods()
#lb.getChannels(lights)
lb.fadeTo(lights, fade)
if __name__ == '__main__':
path = sys.argv[1]
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 sleep = seq() + 15
light = seq() + 1 light = seq()
if pos + sleep > duration: if pos + sleep > duration:
break break
time.sleep(sleep) time.sleep(sleep)
cmd = ['/opt/LanBox-JSONRPC/fade.py', str(light)] switch(light)
subprocess.Popen(cmd)
pos += sleep pos += sleep

20
cdoseaplay/pi.py Normal file
View file

@ -0,0 +1,20 @@
from mpmath import mp
mp.dps = 10000
PI = str(mp.pi).replace('.', '')
class random(object):
PI = str(mp.pi).replace('.', '')
def __init__(self, offset=0):
self.position = offset
self.numbers = list(map(int, self.PI[offset:]))
def __call__(self):
if not self.numbers:
offset = mp.dps
mp.dps += 1000
self.PI = str(mp.pi).replace('.', '')
self.numbers = list(map(int, self.PI[offset:]))
self.position += 1
return self.numbers.pop(0)

View file

@ -4,7 +4,7 @@ from glob import glob
import os import os
import sys import sys
from .utils import update_playlist, get_player from .utils import update_playlist, get_player, trigger_lights
from .subtitleserver import SubtitleServer from .subtitleserver import SubtitleServer
from . import config from . import config
@ -57,6 +57,8 @@ def main():
player.pause = True player.pause = True
while True: while True:
if config.lights and player.path:
trigger_lights(player.path.decode())
try: try:
player.wait_for_playback() player.wait_for_playback()
except: except:

View file

@ -13,7 +13,7 @@ from queue import Queue
from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler
from threading import Thread from threading import Thread
from .utils import mpv_log, update_playlist from .utils import mpv_log, update_playlist, trigger_lights
import logging import logging
logger = logging.getLogger('cdosea') logger = logging.getLogger('cdosea')
@ -22,10 +22,6 @@ DEFAULT_PORT = 2680
DEBUG = False DEBUG = False
def trigger_lights(path):
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
subprocess.Popen(cmd)
class ThreadingUDPServer(ThreadingMixIn, UDPServer): class ThreadingUDPServer(ThreadingMixIn, UDPServer):
pass pass

View file

@ -5,6 +5,7 @@ import datetime
import time import time
import string import string
import random import random
import subprocess
import ox import ox
@ -78,3 +79,7 @@ def update_playlist(playlist, prefix, position=None, shift=True):
f.write('\n'.join(files)) f.write('\n'.join(files))
f.write('\n') f.write('\n')
return position, len(files) return position, len(files)
def trigger_lights(path):
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
subprocess.Popen(cmd)

View file

@ -18,6 +18,8 @@ setup(
'ox >= 2.1.541,<3', 'ox >= 2.1.541,<3',
'requests >= 1.1.0', 'requests >= 1.1.0',
'tornado', 'tornado',
'mpmath',
'lanbox',
], ],
keywords=[], keywords=[],
classifiers=[ classifiers=[