This commit is contained in:
j 2024-01-15 12:55:05 +01:00
parent c2852838dd
commit 4071b2156c

View file

@ -45,6 +45,19 @@ 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
@ -102,15 +115,75 @@ def fade_to(target, duration):
sender.stop() sender.stop()
def switch(state): 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
steps = int(duration * 10)
if not steps:
steps = 1
step = duration/steps
delta = distance/steps
current = start
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)]
time.sleep(step)
steps -= 1
step = duration / flashes
if step < 0:
step = 0
while flashes:
fade_to(base, brightness, flash_duration)
sender[1].dmx_data = [0] * 16
time.sleep(step)
flashes -= 1
sender[1].dmx_data = [0] * 16
time.sleep(0.1)
sender.stop()
def switch(state, seq):
if config.lanbox: if config.lanbox:
import lanbox import lanbox
lb = lanbox.Lanbox() lb = lanbox.Lanbox()
lb.layerGo(state) lb.layerGo(state)
else: else:
lights, duration = LIGHTS[state] brightness, duration = FLASHES[state]
brightness = lights['7'] brightness = int(brightness * 255)
fade_to(brightness, duration) #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__':
path = sys.argv[1] path = sys.argv[1]
@ -135,5 +208,5 @@ 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)
switch(light + letter_offset) switch(light + letter_offset, seq)
pos += sleep pos += sleep