Update test controller

This commit is contained in:
Kai Vogelgesang 2021-08-29 12:18:48 +02:00
parent 3237a9bf6a
commit 406c628810
Signed by: kai
GPG Key ID: 0A95D3B6E62C0879

View File

@ -1,5 +1,6 @@
import serial
import time
import colorsys
channels = [
192, # pan
@ -18,18 +19,35 @@ start_addr = 10
with serial.Serial("/dev/ttyUSB0", 115200) as ser:
payload = bytearray(512)
# payload.extend(channels)
payload[(start_addr - 1) : (start_addr - 1 + len(channels))] = channels
print(payload)
FPS = 20
FRAME_TIME = 1 / FPS
t = 0
while True:
loop_start = time.time()
r, g, b = colorsys.hls_to_rgb(t, 0.5, 1)
channels[3] = int(255 * r)
channels[4] = int(255 * g)
channels[5] = int(255 * b)
payload[(start_addr - 1) : (start_addr - 1 + len(channels))] = channels
ser.write(payload)
ser.flush()
time.sleep(1/50)
t += FRAME_TIME
t %= 1
loop_time = time.time() - loop_start
if loop_time < FRAME_TIME:
time.sleep(FRAME_TIME - loop_time)
else:
print("loop took too long!")
print(f"loop time: {1000 * loop_time:0.2f}ms busy, {1000 * (time.time() - loop_start):0.2f}ms total")
print(".")
#print(ser.read_all())
# print(ser.read_all())