flash lights
This commit is contained in:
parent
4071b2156c
commit
fa4387a187
2 changed files with 48 additions and 115 deletions
|
@ -13,6 +13,7 @@ font_size = 28
|
||||||
# 30 for chinese
|
# 30 for chinese
|
||||||
|
|
||||||
letter_offset = False
|
letter_offset = False
|
||||||
|
lights_brightness = 255
|
||||||
|
|
||||||
conf = os.path.expanduser('~/.config/cdosea.json')
|
conf = os.path.expanduser('~/.config/cdosea.json')
|
||||||
if os.path.exists(conf):
|
if os.path.exists(conf):
|
||||||
|
|
|
@ -14,17 +14,22 @@ from . import config
|
||||||
|
|
||||||
# Screen 1-5, Control, 6,7
|
# Screen 1-5, Control, 6,7
|
||||||
'''
|
'''
|
||||||
> _*10 patterns / cues that correspond to 10 digit:*_
|
>
|
||||||
> 0 = Screen LED @ 100% fade time = 9s (cue list 1)
|
_*10 patterns / cues that correspond to 10 digit:*_
|
||||||
> 1 = LED Control @ 10% fade time = 8s (cue list 2)
|
0 = Cue list 1 = 1x flash (on, off)
|
||||||
> 2 = LED Control @ 20% fade time = 7s (cue list 3)
|
1 = Cue list 2 = 2x flashes (on, off, on, off)
|
||||||
> 3 = LED Control @ 30% fade time = 6s (cue list 4)
|
2 = Cue list 3 = 3x flashes (on, off, on, off, on, off)
|
||||||
> 4 = LED Control @ 40% fade time = 5s (cue list 5)
|
...and so on...
|
||||||
> 5 = LED Control @ 50% fade time = 4s (cue List 6)
|
8 = Cue list 9 = 9x flashes
|
||||||
> 6 = LED Control @ 60% fade time = 3s (cue list 7)
|
9 = Cue list 10 = 10x flashes
|
||||||
> 7 = LED Control @ 70% fade time = 2s (cue list 8)
|
|
||||||
> 8 = LED Control @ 80% fade time = 1s (cue list 9)
|
The basic timing for 1x flash is:
|
||||||
> 9 = LED Control @ 90% fade time = 0s (cue list 10)
|
|
||||||
|
- Flash on over 0s
|
||||||
|
- Hold on for 0.2s
|
||||||
|
- Flash off over 0s
|
||||||
|
- Hold off for 0.2s
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def channels(screen, control):
|
def channels(screen, control):
|
||||||
screen = int(screen * 255)
|
screen = int(screen * 255)
|
||||||
|
@ -45,89 +50,16 @@ LIGHTS = {
|
||||||
9: (channels(0, 0.9), 0.1),
|
9: (channels(0, 0.9), 0.1),
|
||||||
}
|
}
|
||||||
|
|
||||||
FLASHES = {
|
|
||||||
0: (0.0, 9),
|
|
||||||
1: (0.1, 8),
|
|
||||||
2: (0.2, 7),
|
|
||||||
3: (0.3, 6),
|
|
||||||
4: (0.4, 5),
|
|
||||||
5: (0.5, 4),
|
|
||||||
6: (0.6, 3),
|
|
||||||
7: (0.7, 2),
|
|
||||||
8: (0.8, 1),
|
|
||||||
9: (0.9, 0.1),
|
|
||||||
}
|
|
||||||
|
|
||||||
CURRENT_STATE = [0] * 16
|
CURRENT_STATE = [0] * 16
|
||||||
|
|
||||||
|
|
||||||
def send(state):
|
# avoid overload and turn light on with a fade
|
||||||
sender = sacn.sACNsender()
|
def fade_to(sender, start, end, duration, channels=16, universe=1):
|
||||||
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
|
|
||||||
switch = 0
|
|
||||||
while steps:
|
|
||||||
switch += 1
|
|
||||||
value += delta
|
|
||||||
n = int(round(value))
|
|
||||||
if n != current:
|
|
||||||
current = n
|
|
||||||
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)]
|
|
||||||
CURRENT_STATE = sender[1].dmx_data[:16]
|
|
||||||
time.sleep(step)
|
|
||||||
steps -= 1
|
|
||||||
sender[1].dmx_data = [0] * 16
|
|
||||||
CURRENT_STATE = [0] * 16
|
|
||||||
time.sleep(0.1)
|
|
||||||
sender.stop()
|
|
||||||
|
|
||||||
|
|
||||||
def flash(brightness, duration, flashes, flash_duration=1, base=0):
|
|
||||||
sender = sacn.sACNsender()
|
|
||||||
sender.start()
|
|
||||||
universe = 1
|
|
||||||
sender.activate_output(universe)
|
|
||||||
sender[1].multicast = True
|
|
||||||
sender[1].dmx_data = [0] * 16
|
|
||||||
|
|
||||||
def fade_to(start, end, duration):
|
|
||||||
distance = end - start
|
distance = end - start
|
||||||
steps = int(duration * 10)
|
steps = int(duration * 10)
|
||||||
if not steps:
|
if not steps:
|
||||||
steps = 1
|
steps = 2
|
||||||
step = duration/steps
|
step = duration/steps
|
||||||
delta = distance/steps
|
delta = distance/steps
|
||||||
current = start
|
current = start
|
||||||
|
@ -139,50 +71,47 @@ def flash(brightness, duration, flashes, flash_duration=1, base=0):
|
||||||
n = int(round(value))
|
n = int(round(value))
|
||||||
if n != current:
|
if n != current:
|
||||||
current = n
|
current = n
|
||||||
old = sender[1].dmx_data[:16]
|
old = sender[1].dmx_data[:channels]
|
||||||
target = [n] * 16
|
target = [n] * channels
|
||||||
if switch % 2:
|
if switch % 2:
|
||||||
a = target
|
a = target
|
||||||
b = old
|
b = old
|
||||||
else:
|
else:
|
||||||
a = old
|
a = old
|
||||||
b = target
|
b = target
|
||||||
sender[1].dmx_data = [a[x] if x % 2 else b[x] for x in range(16)]
|
sender[universe].dmx_data = [a[x] if x % 2 else b[x] for x in range(channels)]
|
||||||
time.sleep(step)
|
time.sleep(step)
|
||||||
steps -= 1
|
steps -= 1
|
||||||
|
|
||||||
step = duration / flashes
|
|
||||||
if step < 0:
|
def flash(flashes):
|
||||||
step = 0
|
step = 0.2
|
||||||
|
flash_duration = 0.02
|
||||||
|
base = 0
|
||||||
|
brightness = config.lights_brightness
|
||||||
|
universe = 1
|
||||||
|
channels = 16
|
||||||
|
|
||||||
|
sender = sacn.sACNsender()
|
||||||
|
sender.start()
|
||||||
|
sender.activate_output(universe)
|
||||||
|
sender[universe].multicast = True
|
||||||
|
sender[universe].dmx_data = [0] * channels
|
||||||
while flashes:
|
while flashes:
|
||||||
fade_to(base, brightness, flash_duration)
|
fade_to(sender, base, brightness, flash_duration, channels, universe)
|
||||||
sender[1].dmx_data = [0] * 16
|
time.sleep(step)
|
||||||
|
sender[1].dmx_data = [0] * channels
|
||||||
time.sleep(step)
|
time.sleep(step)
|
||||||
flashes -= 1
|
flashes -= 1
|
||||||
sender[1].dmx_data = [0] * 16
|
sender[universe].dmx_data = [0] * channels
|
||||||
time.sleep(0.1)
|
time.sleep(step)
|
||||||
sender.stop()
|
sender.stop()
|
||||||
|
|
||||||
|
|
||||||
def switch(state, seq):
|
def switch(state, seq):
|
||||||
if config.lanbox:
|
|
||||||
import lanbox
|
import lanbox
|
||||||
lb = lanbox.Lanbox()
|
lb = lanbox.Lanbox()
|
||||||
lb.layerGo(state)
|
lb.layerGo(state)
|
||||||
else:
|
|
||||||
brightness, duration = FLASHES[state]
|
|
||||||
brightness = int(brightness * 255)
|
|
||||||
#fade_to(brightness, duration)
|
|
||||||
flashes = seq()
|
|
||||||
if flashes:
|
|
||||||
base = seq()
|
|
||||||
if base:
|
|
||||||
base = brightness/base
|
|
||||||
flash_duration = 0.01+seq()/24
|
|
||||||
while flashes * flash_duration > duration:
|
|
||||||
flash_duration = flash_duration/2
|
|
||||||
print("flash brightness: %s duration: %s flashes: %s flash duration %s base: %s" % (brightness, duration, flashes, flash_duration, base))
|
|
||||||
flash(brightness, duration, flashes, flash_duration, base=base)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -208,5 +137,8 @@ if __name__ == '__main__':
|
||||||
if not no_sleep:
|
if not no_sleep:
|
||||||
time.sleep(sleep)
|
time.sleep(sleep)
|
||||||
print("letter", letter, "offset", letter_offset, "light", light, "cue", letter_offset + light)
|
print("letter", letter, "offset", letter_offset, "light", light, "cue", letter_offset + light)
|
||||||
|
if config.lanbox:
|
||||||
switch(light + letter_offset, seq)
|
switch(light + letter_offset, seq)
|
||||||
|
else:
|
||||||
|
flash(light + 1)
|
||||||
pos += sleep
|
pos += sleep
|
||||||
|
|
Loading…
Add table
Reference in a new issue