Flackern fixen
Das Problem ist Reload=True, was forked und dadurch Threads dupliziert. Verschiendene kleinere Verbesserungen, inkl. Parametrisierung
This commit is contained in:
parent
94377a6945
commit
9687886832
5 changed files with 338 additions and 27 deletions
54
dmx.py
54
dmx.py
|
|
@ -1,6 +1,7 @@
|
|||
import colorsys
|
||||
import socket
|
||||
import struct
|
||||
import threading
|
||||
from threading import Thread
|
||||
from time import sleep, time
|
||||
|
||||
|
|
@ -10,6 +11,10 @@ def hsv_to_rgb(h, s, v):
|
|||
return [int(r * 255), int(g * 255), int(b * 255)]
|
||||
|
||||
|
||||
def ledlog(value):
|
||||
# return int(pow(float(value)/255.0, 2))*255
|
||||
return value
|
||||
|
||||
|
||||
class RGB:
|
||||
def __init__(self, dmx, slot, offset=0):
|
||||
|
|
@ -19,9 +24,9 @@ class RGB:
|
|||
|
||||
def rgb(self, color):
|
||||
(r, g, b) = color
|
||||
self.dmx.set(self.slot+self.offset+0, r)
|
||||
self.dmx.set(self.slot+self.offset+1, g)
|
||||
self.dmx.set(self.slot+self.offset+2, b)
|
||||
self.dmx.set(self.slot+self.offset+0, ledlog(r))
|
||||
self.dmx.set(self.slot+self.offset+1, ledlog(g))
|
||||
self.dmx.set(self.slot+self.offset+2, ledlog(b))
|
||||
|
||||
class Bar252(RGB):
|
||||
def __init__(self, dmx, slot=1):
|
||||
|
|
@ -30,6 +35,12 @@ class Bar252(RGB):
|
|||
dmx.set(self.slot+1, 0)
|
||||
|
||||
|
||||
class REDSpot18RGB(RGB):
|
||||
def __init__(self, dmx, slot=1):
|
||||
super(REDSpot18RGB, self).__init__(dmx, slot, 1)
|
||||
dmx.set(self.slot+0, 0)
|
||||
|
||||
|
||||
class StairvilleLedPar56(RGB):
|
||||
def __init__(self, dmx, slot=1):
|
||||
super(StairvilleLedPar56, self).__init__(dmx, slot, 0)
|
||||
|
|
@ -68,37 +79,55 @@ class FadeTo(Steady):
|
|||
|
||||
|
||||
class RotatingRainbow:
|
||||
def __init__(self):
|
||||
def __init__(self, looptime=10.0):
|
||||
self.looptime = looptime
|
||||
pass
|
||||
|
||||
def update(self, index, count):
|
||||
"""
|
||||
One full round takes 10 seconds, each RGB is offset in a circle
|
||||
One full round takes self.looptime seconds, each RGB is offset in a circle
|
||||
:param index:
|
||||
:param count:
|
||||
:return:
|
||||
"""
|
||||
hue = (time() / 10.0 + (index + 0.0) / count) % 1.0
|
||||
hue = (time() / self.looptime + (index + 0.0) / count) % 1.0
|
||||
rgb = hsv_to_rgb(hue, 1, 1)
|
||||
return rgb
|
||||
|
||||
def __str__(self):
|
||||
return "RotatingRainbow"
|
||||
|
||||
|
||||
class Chase(Steady):
|
||||
def __init__(self, r, g, b, looptime=1.0):
|
||||
super(Chase, self).__init__(r, g, b)
|
||||
self.looptime = looptime
|
||||
|
||||
def update(self, index, count):
|
||||
angle = (time() / self.looptime + (index + 0.0) / count) % 1.0
|
||||
l = 1 - min(abs(angle - 2.0 / count), 1.0 / count) * count
|
||||
# print(f"f({index}, {angle:.2f}) -> {l:.2f}")
|
||||
return (int(self.r * l), int(self.g * l), int(self.b * l))
|
||||
|
||||
def __str__(self):
|
||||
return f"fadeTo({self.r}, {self.g}, {self.b})"
|
||||
|
||||
|
||||
class DMX:
|
||||
def __init__(self, host, port=0x1936, universe=1):
|
||||
def __init__(self, host, port=0x1936, universe=1, maxchan=512):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.universe = universe
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
|
||||
self.socket.setblocking(False)
|
||||
self.data = bytearray(512)
|
||||
self.data = bytearray(maxchan)
|
||||
packet = bytearray()
|
||||
packet.extend(map(ord, "Art-Net"))
|
||||
packet.append(0x00) # Null terminate Art-Net
|
||||
packet.extend([0x00, 0x50]) # Opcode ArtDMX 0x5000 (Little endian)
|
||||
packet.extend([0x00, 0x0e]) # Protocol version 14
|
||||
self.header = packet
|
||||
self.sequence = 1
|
||||
self.animation = FadeTo(255, 255, 255)
|
||||
self.rgbs = []
|
||||
self.thread = None
|
||||
|
|
@ -122,14 +151,19 @@ class DMX:
|
|||
|
||||
def update(self):
|
||||
packet = self.header[:]
|
||||
packet.append(0) # Sequence,
|
||||
packet.append(self.sequence) # Sequence,
|
||||
packet.append(0x00) # Physical
|
||||
packet.append(self.universe & 0xFF) # Universe LowByte
|
||||
packet.append(self.universe >> 8 & 0xFF) # Universe HighByte
|
||||
|
||||
packet.extend(struct.pack('>h', 512)) # Pack the number of channels Big endian
|
||||
packet.extend(struct.pack('>h', len(self.data))) # Pack the number of channels Big endian
|
||||
packet.extend(self.data)
|
||||
self.socket.sendto(packet, (self.host, self.port))
|
||||
# print(f"sent {len(packet)} bytes, {threading.get_native_id()}")
|
||||
|
||||
self.sequence += 1
|
||||
if self.sequence > 255:
|
||||
self.sequence = 1
|
||||
|
||||
def set(self, slot, value):
|
||||
self.data[slot-1] = value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue