initial implementation for extern_cmd

This commit is contained in:
Marc Planard 2024-08-19 21:22:38 +02:00
parent a9a89f86c5
commit 7e2d7c4afb
6 changed files with 266 additions and 227 deletions

View file

@ -14,13 +14,13 @@ Commands reference. Use commands from websocket (webUI) or OSC, do not set value
DAChecks()
UpdateAllwww()
/forwardui "htmlid args"
/forwardui "htmlid args"
/scale/X/lasernumber value (0-200)
/scale/Y/lasernumber value (0-200)
/client or note on < 8 : change client displayed for Current Laser
23 < /noteon < 32 : PL number displayed on webUI simulator
23 < /noteon < 32 : PL number displayed on webUI simulator
/grid/lasernumber value (0 or 1) : switch given laser with grid display on or off
@ -34,15 +34,15 @@ Live change of kpps is not implemented in newdac.py. Change will effect next sta
/angle/lasernumber value : angle correction for given laser by value (0-360)
/intens/lasernumber value : increase/decrease intensity for given laser by value
/intens/lasernumber value : increase/decrease intensity for given laser by value
/resampler/lasernumber lsteps : change resampling strategy (glitch art) for given laser
lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
/mouse/lasernumber value (0 or 1)
/swap/X/lasernumber value (0 or 1)
/swap/Y/lasernumber value (0 or 1)
/mouse/lasernumber value (0 or 1)
/swap/X/lasernumber value (0 or 1)
/swap/Y/lasernumber value (0 or 1)
/loffset/X/lasernumber value : change X offset of given laser to value (-32000/32000)
/loffset/Y/lasernumber value : change Y offset of given laser to value (-32000/32000)
@ -50,10 +50,10 @@ lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
/order value : instruct tracer what to do.
0 : display user pointlist with current client key. See below for client key.
1 : pull in redis a new correction matrix (EDH)
2 : display black
1 : pull in redis a new correction matrix (EDH)
2 : display black
3 : display grid
4 : resampler
4 : resampler
5 : pull in redis a new client key
6 : Max Intensity Change = reread redis key /intensity
7 : kpps change = reread redis key /kpps
@ -74,12 +74,12 @@ lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
Example : client 0 send 2 point lists one for laser 0 and one for laser 1 by sending in redis :
/pl/0/0 and /pl/0/1
The "client key" when client 0 is selected to be displayed by lasers is "/pl/0/".
Each tracer pull its pointlist by using the current client key "/pl/0/"
The "client key" when client 0 is selected to be displayed by lasers is "/pl/0/".
Each tracer pull its pointlist by using the current client key "/pl/0/"
and add its laser number at startup : /pl0/0 ant /pl/0/1
"Client" is a concept. Imagine in a demoparty there is 4 lasers.
John and Paul want to draw on all lasers.
"Client" is a concept. Imagine in a demoparty there is 4 lasers.
John and Paul want to draw on all lasers.
Let's give John client 0, he will send points to /pl/0/0, /pl/0/1, /pl/0/2 and /pl/0/3.
Paul is client 1, so he will use /pl/1/0, /pl/1/1, /pl/1/2 and /pl/1/3.
@ -87,7 +87,7 @@ Paul is client 1, so he will use /pl/1/0, /pl/1/1, /pl/1/2 and /pl/1/3.
Both can send their pointlists to redis server.
When John get the lasers switch to client 0, when it's Paul turn switch to client 1.
But say Bob and Lisa needs only 2 lasers each. Give them client 2.
But say Bob and Lisa needs only 2 lasers each. Give them client 2.
Bob could use /pl/2/0 and /pl/2/1 and Lisa could use /pl/2/2 and /pl/2/3.
@ -96,17 +96,18 @@ Bob could use /pl/2/0 and /pl/2/1 and Lisa could use /pl/2/2 and /pl/2/3.
import types, time, socket, math
from libs3 import gstt
import redis
from libs3 import OSC3
from libs3 import OSC3
from libs3 import settings, plugins, homographyp,log
r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0)
#r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0, password='-+F816Y+-')
workers = []
GenericCommands = ["start", "align", "ljclient", "scene", "addest", "deldest", "dest", "clientnumber", "vcvrack", "fft", "mitraille", "faceosc", "midigen", "viewgen", "audiogen", "noteon", "cc", "ljpong", "ljwars", "mouse", "emergency", "simu", "status", "run", "nozoid", "planet", "live", "words", "ai", "bank0", "pose", "lj", "cycl", "glyph", "pong", "maxw", "custom1", "square", "regen", "trckr", "aurora", "line1", "ForwardUI", "settings", "debug", "pl", "plugins"]
def UserOn(laser):
print("User for laser ", laser)
@ -130,7 +131,7 @@ def BlackOn(laser):
plugins.sendWSall("/status Black on laser " + str(laser))
sendOSCUI('/black/'+str(laser),1)
r.set('/order/'+str(laser), 2)
def GridOn(laser):
@ -164,7 +165,7 @@ def LasClientChange(clientnumber):
r.set('/order/'+str(laserid), 5)
else:
print("ERROR : Maximum number of scenes is set to ", gstt.MaxScenes)
def SceneChange(newscene):
@ -190,7 +191,7 @@ def NoteOn(note):
# Change laser client
if note < 8:
LasClientChange(note)
# Change PL displayed on webui
if note > 23 and note < 32:
if note - 24 > gstt.LaserNumber -1:
@ -198,8 +199,8 @@ def NoteOn(note):
plugins.sendWSall("/redstatus No Laser"+str(note-24))
plugins.sendWSall("/laser "+str(gstt.LaserNumber-1))
plugins.SendAll("/laser "+str(gstt.LaserNumber-1))
else:
else:
gstt.Laser = note -24
print("Current Laser switched to", gstt.Laser)
plugins.sendWSall("/status Laser " + str(gstt.Laser))
@ -209,7 +210,7 @@ def NoteOn(note):
plugins.sendWSall("/loffset/Y/" + str(gstt.Laser) +" " +str(gstt.centerY[gstt.Laser]))
plugins.sendWSall("/scale/X/" + str(gstt.Laser) +" " + str(gstt.zoomX[gstt.Laser]))
plugins.sendWSall("/scale/Y/" + str(gstt.Laser) +" " +str(gstt.zoomY[gstt.Laser]))
def Scim(path, tags, args, source):
@ -223,7 +224,7 @@ def Scim(path, tags, args, source):
plugins.sendWSall("/redstatus No Laser"+str(note-24))
plugins.sendWSall("/laser "+str(gstt.LaserNumber-1))
else:
else:
gstt.Laser = laser -24
plugins.sendWSall("/status Laser " + str(gstt.Laser))
print("Current Laser switched to", gstt.Laser)
@ -232,15 +233,15 @@ def Scim(path, tags, args, source):
def Line1(path, tags, args, source):
line1 = args[0]
print("OSC /line1", line1)
print("OSC /line1", line1)
plugins.sendWSall("/line1 " +"Fx "+line1)
# forward
# forward
def ForwardUI(path, tags, args, source):
line = args[0]
print("OSC /forwardui to WebUI :", line)
print("OSC /forwardui to WebUI :", line)
print('from path', path, 'args', args)
plugins.sendWSall(line)
sendOSCUI('/status',line)
@ -264,12 +265,12 @@ def handler(oscpath, args):
# 2 incoming cases : generic or specific for a given lasernumber :
#
# Generic : Commands without a laser number
#
if oscpath[1] in GenericCommands:
if oscpath[1] in GenericCommands:
if gstt.debug > 0:
print("GenericCommand :", oscpath[1], "with args", args)
@ -286,7 +287,7 @@ def handler(oscpath, args):
r.set("/"+oscpath[1]+"/"+oscpath[2]+"/"+oscpath[3], args[0])
if oscpath[0] == "pl" :
if oscpath[0] == "pl" :
r.set(oscpath, args[0])
@ -314,7 +315,7 @@ def handler(oscpath, args):
if gstt.debug >0:
print(("/" + args[0] + "/start 1"))
print(("/status got pong from "+ args[0] +"."))
plugins.sendWSall("/" + args[0] + "/start 1")
#plugins.sendWSall("/status got pong from "+ args[0] +".")
@ -333,25 +334,25 @@ def handler(oscpath, args):
elif oscpath[1] == "mouse":
Mouse(int(args[0]),int(args[1]),int(args[2]),int(args[3]))
# /emergency value (0 or 1)
# /emergency value (0 or 1)
elif oscpath[1] == "emergency":
if args[0] == "1":
for laser in range(gstt.lasernumber):
print("Black requested for laser ", laser)
BlackOn(laser)
print("EMERGENCY MODE")
plugins.sendWSall("/status EMERGENCY MODE")
plugins.sendWSall("/status EMERGENCY MODE")
else:
for laser in range(gstt.lasernumber):
print("Back to normal for laser ", laser)
UserOn(laser)
# Plugins commands :
# Plugins commands :
elif oscpath[1] == "plugins":
# /plugins/start pluginame
if oscpath[2] == "start":
@ -373,9 +374,9 @@ def handler(oscpath, args):
print("Restarting plugin :",args[0])
print()
plugins.Restart(args[0])
# Settings commands :
# Settings commands :
elif oscpath[1] == "settings":
if oscpath[2] == "lasers":
print()
@ -420,7 +421,7 @@ def handler(oscpath, args):
print("** RESTART LJ **")
#LJautokill()
if oscpath[2] == "restart":
print()
print("Restarting", args[0], "...")
@ -457,25 +458,25 @@ def handler(oscpath, args):
else:
laser = int(oscpath[3])
#print "args[0] :",args[0]," ", type(args[0])
# /black/lasernumber value (0 or 1)
# /black/lasernumber value (0 or 1)
if oscpath[1] == "black":
if args[0] == "1":
print("Black requested for laser ", laser)
BlackOn(laser)
BlackOn(laser)
else:
print("User mode for laser ", laser)
UserOn(laser)
# /grid/lasernumber value (0 or 1)
# /grid/lasernumber value (0 or 1)
if oscpath[1] == "grid":
if args[0] == "1":
print("Grid requested for laser ", laser)
GridOn(laser)
GridOn(laser)
else:
print("No grid for laser ", laser)
UserOn(laser)
@ -485,7 +486,7 @@ def handler(oscpath, args):
print("New IP for laser ", laser)
gstt.lasersIPS[laser]= args[0]
settings.Write()
# /kpps/lasernumber value
# Live change of kpps is not implemented in newdac.py. Change will effect next startup.
if oscpath[1] == "kpps":
@ -495,59 +496,59 @@ def handler(oscpath, args):
sendOSCUI('/kpps/' + str(laser), args[0])
r.set('/kpps/' + str(laser), str(args[0]))
r.set('/order/'+str(laser), 7)
# /angle/lasernumber value
# /angle/lasernumber value
if oscpath[1] == "angle":
print("New Angle modification for laser ", oscpath[2], ":", float(args[0]))
gstt.finANGLE[laser] = math.radians(float(args[0]))
sendOSCUI('/angle/' + str(laser), gstt.finANGLE[laser])
NewEDH(laser)
print("New angle", gstt.finANGLE[laser])
# /intens/lasernumber value
# /intens/lasernumber value
if oscpath[1] == "intens":
print("LJ2 : New intensity requested for laser ", laser, ":", int(args[0]))
plugins.sendWSall("/status Intensity " + str(args[0]))
sendOSCUI('/intens/' + str(laser), args[0])
r.set('/intensity/' + str(laser), str(args[0]))
r.set('/order/'+str(laser), 6)
# /resampler/lasernumber lsteps
# lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]"
if oscpath[1] == "resampler":
#print"resampler with args", args
Resampler(laser,args)
# /mouse/lasernumber value (0 or 1)
# /mouse/lasernumber value (0 or 1)
if oscpath[1] == "mouse":
if args[0] == "1":
print("Mouse requested for laser ", oscpath[2])
gstt.Laser = oscpath[2]
else:
print("No mouse for laser ", oscpath[2])
# /swap/X/lasernumber value (0 or 1)
# /swap/X/lasernumber value (0 or 1)
if oscpath[1] == "swap" and oscpath[2] == "X":
print("swapX was", gstt.swapX[laser])
if args[0] == "0":
print("swap X -1 for laser ", laser)
gstt.swapX[laser]= -1
NewEDH(laser)
else:
print("swap X 1 for laser ", laser)
gstt.swapX[laser]= 1
NewEDH(laser)
# /swap/Y/lasernumber value (0 or 1)
# /swap/Y/lasernumber value (0 or 1)
if oscpath[1] == "swap" and oscpath[2] == "Y":
print("swapY was", gstt.swapX[laser])
if args[0] == "0":
print("swap Y -1 for laser ", laser)
@ -557,7 +558,7 @@ def handler(oscpath, args):
print("swap Y 1 for laser ", laser)
gstt.swapY[laser]= 1
NewEDH(laser)
# /loffset/X/lasernumber value
if oscpath[1] == "loffset" and oscpath[2] == "X":
@ -565,7 +566,7 @@ def handler(oscpath, args):
print("offset/X laser", laser, "modified to", args[0])
gstt.centerX[laser] = float(args[0])
NewEDH(laser)
# /loffset/Y/lasernumber value
if oscpath[1] == "loffset" and oscpath[2] == "Y":
@ -573,18 +574,18 @@ def handler(oscpath, args):
print("offset/Y laser", laser, "modified to", args[0])
gstt.centerY[laser] = float(args[0])
NewEDH(laser)
# /scale/X/lasernumber value
if oscpath[1] == "scale" and oscpath[2] == "X":
gstt.zoomX[laser] = float(args[0])
print("scale/X laser", laser , "modified to", gstt.zoomX[laser])
NewEDH(laser)
# /scale/Y/lasernumber value
if oscpath[1] == "scale" and oscpath[2] == "Y":
gstt.zoomY[laser] = float(args[0])
print("scale/Y laser", laser, "modified to", gstt.zoomY[laser])
NewEDH(laser)
@ -592,22 +593,22 @@ def handler(oscpath, args):
# OSC UI feedback
def sendOSCUI(oscaddress,oscargs=''):
if gstt.TouchOSCUI == True:
oscmsg = OSC3.OSCMessage()
oscmsg.setAddress(oscaddress)
oscmsg.append(oscargs)
oscui = OSC3.OSCClient()
oscui.connect((gstt.TouchOSCIP, 8001))
oscui.connect((gstt.TouchOSCIP, 8001))
#print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
if gstt.debug >0:
print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
try:
oscui.sendto(oscmsg, (gstt.TouchOSCIP, 8001))
oscmsg.clearData()
except:
print ('Connection to OSC UI refused : died ?')
pass
@ -639,7 +640,7 @@ def UpdateOSCUI(laserid):
sendOSCUI("/swap/Y/" + str(laserid), 0)
#
#
# Different useful codes for some commands
#
@ -700,7 +701,7 @@ def isOpen(ip):
time.sleep(1)
finally:
dacksock.close()
return istate
@ -726,22 +727,27 @@ def LJautokill():
print('Shutdown order for tracer '+str(laser), 9)
r.set('/order/'+str(laser), 9)
for (n,dac_worker) in enumerate(workers):
log.warn(f'Entering tracer{n} ...')
dac_worker.join()
lasernumber= gstt.LaserNumber -1
log.warn("Ending tracer0...")
worker0.join()
if lasernumber >0:
log.warn("Ending tracer1...")
worker1.join()
if lasernumber >1:
log.warn("Ending tracer2...")
worker2.join()
if lasernumber >2:
log.warn("Ending tracer3...")
worker3.join()
# log.warn("Ending tracer0...")
# worker0.join()
# if lasernumber >0:
# log.warn("Ending tracer1...")
# worker1.join()
# if lasernumber >1:
# log.warn("Ending tracer2...")
# worker2.join()
# if lasernumber >2:
# log.warn("Ending tracer3...")
# worker3.join()
log.warn("Laser feedbacks resetting...")
for laserid in range(0,lasernumber+1):
r.set('/lack/'+str(laserid),64)
r.set('/lstt/'+str(laserid),64)
r.set('/cap/'+str(laserid),0)
@ -759,9 +765,9 @@ def DAChecks():
if isOpen(gstt.lasersIPS[dac]):
print("DAC", dac, "at", gstt.lasersIPS[dac], ": UP")
gstt.dacs[gstt.dacnumber] = dac
gstt.dacs[gstt.dacnumber] = dac
gstt.dacnumber +=1
else:
print("DAC", dac, "at", gstt.lasersIPS[dac], ": DOWN")
@ -786,19 +792,19 @@ For reference values of EDH modifier if assign to keyboard keys (was alignp)
gstt.zoomX[gstt.Laser] += 0.1
gstt.zoomY[gstt.Laser] -= 0.1
gstt.zoomY[gstt.Laser] += 0.1
gstt.sizeX[gstt.Laser] -= 50
gstt.sizeX[gstt.Laser] += 50
gstt.sizeY[gstt.Laser] -= 50
gstt.sizeY[gstt.Laser] += 50
gstt.finANGLE[gstt.Laser] -= 0.001
gstt.finANGLE[gstt.Laser] += 0.001
Code for bit analysis 2 bits / laser to encode order.
@ -813,7 +819,7 @@ Code for bit analysis 2 bits / laser to encode order.
#order = r.get('/order')
#neworder = order & ~(1<< laser*2)
#neworder = neworder & ~(1<< 1+ laser*2)
#r.set('/order', str(neworder))
#r.set('/order', str(neworder))
# Laser bit 0 = 0 and bit 1 = 1 : New EDH
#order = r.get('/order')

View file

@ -49,13 +49,13 @@ Laser = 0
# Can be changed with /noteon 24-31
simuPL = 1
# gstt.laserIPS.
# gstt.laserIPS.
lasersIPS = ['192.168.1.5','192.168.1.6','192.168.1.3','192.168.1.4']
maxdacs = 4
# Autodetected by DAChecks() in main3 :
# Store connected dacs. Maybe laser 1 in LJ.conf is not connected but Laser 2 is.
# Store connected dacs. Maybe laser 1 in LJ.conf is not connected but Laser 2 is.
dacs = [-1, -1, -1, -1]
# Actual number of connected DACs
dacnumber = 0
@ -63,8 +63,9 @@ dacnumber = 0
# gstt.kpps stores kpps for each laser.
# ** Will be overridden by LJ.conf file values **
kpps = [25000,25000,25000,25000]
lasertype = ["LOCAL","LOCAL","LOCAL","LOCAL"]
dacfamily = ["etherdream","etherdream","etherdream","etherdream"]
lasertype = ["LOCAL","LOCAL","LOCAL","LOCAL"]
dacfamily = ["etherdream","etherdream","etherdream","etherdream"]
cmd = [None,None,None,None]
intensity = [-1,-1,-1,-1]
intens = [-1,-1,-1,-1]
red = [100,100,100,100]
@ -74,17 +75,17 @@ blue = [100,100,100,100]
# gstt.GridDisplay : if = 1 Curve points actually sent to PL are replaced by a grid
GridDisplay = [0,0,0,0]
# Transformation Matrix for each laser
# Transformation Matrix for each laser
EDH = [[], [], [], []]
# Etherdreams reports
# Etherdreams reports
# ipconn is initial newdac to its etherdream
lstt_ipconn = [[-1], [-1], [-1], [-1]]
# dacstt is dac light engine state
lstt_dacstt = [[-1], [-1], [-1], [-1]]
# store last dac answers : ACK, not ACK,...
# store last dac answers : ACK, not ACK,...
lstt_dacanswers = [[-1], [-1], [-1], [-1]]
# store last number of points sent to etherdreams buffer
# store last number of points sent to etherdreams buffer
lstt_points = [[0], [0], [0], [0]]
swapX = [1,1,1,-1]
@ -93,7 +94,7 @@ swapY = [1,1,1,-1]
lsteps = [[],[],[],[]]
# For glitch art : change position and number of points added by tracer.py
# shortline is for distance with next point, shorter than 4000 (in etherdream coordinates)
# shortline is for distance with next point, shorter than 4000 (in etherdream coordinates)
# i.e (0.25,3) means add 3 points at 25% on the line.
stepshortline = [(1.0, 8)]
stepslongline = [(0.25, 3), (0.75, 3), (1.0, 10)]
@ -114,7 +115,7 @@ knob = [0] * 33
cc[21]=60
viewer_distance = cc[21] * 8
# fov (cc 22)
# fov (cc 22)
cc[22]= 60
fov = 4 * cc[22]
@ -130,7 +131,7 @@ nozoport=8001 #nozosc.py sending port to LJay (main.py)
nozuport=0 #linux serial usb port connecting nozoid devices ACM0 by default
angleX = 0
angleX = 0
angleY = 0
angleZ = 0

View file

@ -16,7 +16,7 @@ import ast
import numpy as np
def Write():
def Write():
config.set('General', 'lasernumber', str(gstt.LaserNumber))
config.set('General', 'rediserverip', str(gstt.RediServerIP))
@ -51,8 +51,8 @@ def Write():
def Read():
def Read():
gstt.LaserNumber = config.getint('General', 'lasernumber')
gstt.RediServerIP= config.get('General', 'rediserverip')
gstt.wwwIP= config.get('General', 'wwwip')
@ -69,6 +69,8 @@ def Read():
gstt.lasersIPS[i]= config.get(laser, 'ip')
gstt.lasertype[i]= config.get(laser, 'type')
gstt.dacfamily[i] = config.get(laser, 'dac_family')
if gstt.dacfamily[i] == "extern_cmd":
gstt.cmd[i] = config.get(laser, 'cmd')
gstt.kpps[i] = config.getint(laser, 'kpps')
gstt.intens[i] = config.getfloat(laser, 'intens')
gstt.red[i] = config.getint(laser, 'red')
@ -90,4 +92,3 @@ def Read():
config = configparser.ConfigParser()
config.read(gstt.ConfigName)