[fix] clitools changes

This commit is contained in:
alban 2020-10-09 18:30:28 +02:00
parent f9e0db4499
commit 75b3ae93a2
5 changed files with 213 additions and 5 deletions

View File

@ -66,9 +66,9 @@ red = (41,24,24)
white = (95,95,95) white = (95,95,95)
blue = (0,41,64) blue = (0,41,64)
red = (86,0,0) red = (255,0,0)
blue = (0,55,86) blue = (0,255,255)
white = (125,125,125) white = (255,255,255)
def anaglyph( pl ): def anaglyph( pl ):
debug(name,'--------------- new loop ------------------') debug(name,'--------------- new loop ------------------')

38
clitools/generators/dummy.py Normal file → Executable file
View File

@ -38,11 +38,45 @@ fps=args.fps
verbose=args.verbose verbose=args.verbose
optimal_looptime = 1 / fps optimal_looptime = 1 / fps
debug(name+" optimal looptime "+str(optimal_looptime)) debug(name+" optimal looptime "+str(optimal_looptime))
color = 65280
square = [[100.0, 100.0, color], [100.0, 500.0, color], [500.0, 500.0, color], [500.0, 100.0, color], [100.0, 100.0, color]]
line =[]
for i in range(00,800,int(800/120)):
line.append([i, 400, color])
square = [[100.0, 100.0, color], [100.0, 500.0, color], [500.0, 500.0, color], [500.0, 100.0, color], [100.0, 100.0, color]]
mire = [
[600,600,0],
[600,600,color],
[700,600,color],
[700,700,color],
[600,700,color],
[600,600,color],
[100,100,0],
[100,100,color],
[200,100,color],
[200,200,color],
[100,200,color],
[100,100,color],
[0,0,0],
[0,0,color],
[800,0,color],
[800,800,color],
[0,800,color],
[0,0,color],
[350,400,0],
[350,400,color],
[450,400,color],
[400,350,0],
[400,350,color],
[400,450,color],
]
shape = mire
while True: while True:
start = time.time() start = time.time()
print("[[100.0, 100.0, 65280], [100.0, 500.0, 65280], [500.0, 500.0, 65280], [500.0, 100.0, 65280], [100.0, 100.0, 65280]]", flush=True); print(shape, flush=True);
#print("[[100.0, 100.0, 65280], [110.0, 500.0, 65280], [510.0, 500.0, 65280], [510.0, 100.0, 65280], [100.0, 110.0, 65280]]", flush=True);
looptime = time.time() - start looptime = time.time() - start
if( looptime < optimal_looptime ): if( looptime < optimal_looptime ):
time.sleep( optimal_looptime - looptime) time.sleep( optimal_looptime - looptime)

0
clitools/generators/example.py Normal file → Executable file
View File

View File

@ -0,0 +1,174 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
redilysis_lines
v0.1.0
Add a line on every frame and scroll
see https://git.interhacker.space/teamlaser/redilysis for more informations
about the redilysis project
LICENCE : CC
by cocoa
'''
from __future__ import print_function
import argparse
import ast
import os
import math
import random
import redis
import sys
import time
name = "generator::redilysis_lines"
def debug(*args, **kwargs):
if( verbose == False ):
return
print(*args, file=sys.stderr, **kwargs)
def msNow():
return time.time()
CHAOS = 1
REDIS_FREQ = 33
# General Args
argsparser = argparse.ArgumentParser(description="Redilysis filter")
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
# Redis Args
argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
argsparser.add_argument("-F","--redis-freq",help="Query Redis every x (in milliseconds). Default:{}".format(REDIS_FREQ),default=REDIS_FREQ,type=int)
# General args
argsparser.add_argument("-n","--nlines",help="number of lines on screen",default=60,type=int)
argsparser.add_argument("-x","--centerX",help="geometrical center X position",default=400,type=int)
argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=400,type=int)
argsparser.add_argument("-W","--max-width",help="geometrical max width",default=800,type=int)
argsparser.add_argument("-H","--max-height",help="geometrical max height",default=800,type=int)
argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int)
args = argsparser.parse_args()
verbose = args.verbose
ip = args.ip
port = args.port
fps = args.fps
centerX = args.centerX
centerY = args.centerY
redisFreq = args.redis_freq / 1000
maxWidth = args.max_width
maxHeight = args.max_height
nlines = args.nlines
optimal_looptime = 1 / fps
redisKeys = ["spectrum_120","spectrum_10"]
debug(name,"Redis Keys:{}".format(redisKeys))
redisData = {}
redisLastHit = msNow() - 99999
r = redis.Redis(
host=ip,
port=port)
white = 16777215
lineList = []
scroll_speed = int(maxHeight / nlines )
line_length = int(maxWidth / 10)
line_pattern = []
def rgb2int(rgb):
#debug(name,"::rgb2int rbg:{}".format(rgb))
return int('0x%02x%02x%02x' % tuple(rgb),0)
def spectrum_10( ):
delList = []
spectrum = ast.literal_eval(redisData["spectrum_10"])
debug( name, "spectrum:{}".format(spectrum))
# scroll lines
for i,line in enumerate(lineList):
skip_line = False
new_y = int(line[0][1] + scroll_speed)
if( new_y >= maxHeight ):
debug(name,"{} > {}".format(new_y,maxHeight))
debug(name,"delete:{}".format(i))
delList.append(i)
continue
for j,point in enumerate(line):
line[j][1] = new_y
lineList[i] = line
for i in delList:
del lineList[i]
# new line
currentLine = []
for i in range(0,10):
x = int(i * line_length)
y = 0
# get frequency level
level = spectrum[i]
# get color
comp = int(255*level)
color = rgb2int( (comp,comp,comp))
# new point
currentLine.append( [x,y,color] )
# add line to list
lineList.append( currentLine)
def refreshRedis():
global redisLastHit
global redisData
# Skip if cache is sufficent
diff = msNow() - redisLastHit
if diff < redisFreq :
#debug(name, "refreshRedis not updating redis, {} < {}".format(diff, redisFreq))
pass
else:
#debug(name, "refreshRedis updating redis, {} > {}".format(diff, redisFreq))
redisLastHit = msNow()
for key in redisKeys:
redisData[key] = r.get(key).decode('ascii')
#debug(name,"refreshRedis key:{} value:{}".format(key,redisData[key]))
# Only update the TTLs
if 'bpm' in redisKeys:
redisData['bpm_pttl'] = r.pttl('bpm')
#debug(name,"refreshRedis key:bpm_ttl value:{}".format(redisData["bpm_pttl"]))
#debug(name,"redisData:{}".format(redisData))
return True
def linelistToPoints( lineList ):
pl = []
for i,line in enumerate(lineList):
# add a blank point
pl.append([ line[0][0], line[0][1], 0 ])
# append all the points of the line
pl += line
#debug(name,"pl:{}".format(pl))
debug(name,"pl length:{}".format(len(pl)))
return pl
try:
while True:
refreshRedis()
start = time.time()
# Do the thing
pointsList = spectrum_10()
print( linelistToPoints(lineList), flush=True )
looptime = time.time() - start
# debug(name+" looptime:"+str(looptime))
if( looptime < optimal_looptime ):
time.sleep( optimal_looptime - looptime)
# debug(name+" micro sleep:"+str( optimal_looptime - looptime))
except EOFError:
debug(name+" break")# no more information

0
clitools/generators/tunnel.py Normal file → Executable file
View File