LJ/libs3/cli.py

161 lines
4.0 KiB
Python
Raw Permalink Normal View History

2018-12-13 11:05:32 +00:00
# coding=UTF-8
"""
LJay/LJ
v0.8
Command line arguments parser
by Sam Neurohack
from /team/laser
"""
2020-09-19 12:28:56 +00:00
from libs3 import gstt
2018-12-13 11:05:32 +00:00
import argparse
2020-09-19 12:28:56 +00:00
import subprocess
2020-09-30 10:05:04 +00:00
from libs3 import settings as Settings
2018-12-13 11:05:32 +00:00
def handle():
#have to be done before importing bhorosc.py to get correct port assignment
2019-01-16 00:50:24 +00:00
argsparser = argparse.ArgumentParser(description="LJ v0.8")
argsparser.add_argument("-r","--redisIP",help="IP address to bind builtin servers (OSC and websocket) also must be the Redis server IP ",type=str)
2020-09-27 23:04:05 +00:00
argsparser.add_argument("-L","--Lasers",help="Number of lasers requested (1 by default).",type=int)
2019-03-10 22:06:04 +00:00
argsparser.add_argument("-v","--verbose",help="Debug mode 0,1 or 2 (0 by default)",type=int)
2018-12-13 11:05:32 +00:00
argsparser.add_argument("-x","--invx",help="Invert laser 0 X axis again",action="store_true")
argsparser.add_argument("-y","--invy",help="Invert laser 0 Y axis again",action="store_true")
2019-01-16 00:50:24 +00:00
argsparser.add_argument("-d","--display",help="Point List number displayed in simulator",type=int)
2018-12-13 11:05:32 +00:00
argsparser.add_argument("-a","--align",help="Reset laser 0 alignement values",action="store_true")
2019-01-16 00:50:24 +00:00
argsparser.add_argument("-i","--iport",help="port number for builtin LJ OSC server (8002 by default)",type=int)
argsparser.add_argument("-n","--nozoidIP",help="IP for llstr' Nozoid OSC server port 8003 ('127.0.0.1' by default)",type=str)
2023-06-03 12:43:53 +00:00
argsparser.add_argument("-b","--oscserverip",help="IP for OSC output ('127.0.0.1' by default)",type=str)
2019-01-16 00:50:24 +00:00
argsparser.add_argument("-o","--oport",help="OSC output port number (8001 by default)",type=int)
2020-09-19 12:28:56 +00:00
argsparser.add_argument("-w","--webui",help="Regen the webui",action="store_true")
2018-12-13 11:05:32 +00:00
# Keep it ! if new features of cli.py is used in a monolaser program
# argsparser.add_argument("-l","--laser",help="Last digit of etherdream ip address 192.168.1.0/24 (4 by default). Localhost if digit provided is 0.",type=int)
args = argsparser.parse_args()
# Verbose = debug
if args.verbose != None:
#print "setting gstt.debug to", args.verbose
gstt.debug = args.verbose
2019-03-10 22:06:04 +00:00
else:
gstt.debug = 0
2018-12-13 11:05:32 +00:00
2020-09-19 12:28:56 +00:00
# Webui regen
if args.webui == True:
subprocess.call(['python','webui/build.py'])
2018-12-13 11:05:32 +00:00
# Ports arguments
if args.iport:
iport = args.iport
gstt.iport = iport
else:
iport = gstt.iport
if args.oport:
oport = args.oport
gstt.oport = oport
else:
oport = gstt.oport
if gstt.debug > 0:
2024-08-15 15:04:23 +00:00
print("Accept OSC port arg : ",gstt.oport)
print("Send OSC to port arg :",gstt.iport)
2018-12-13 11:05:32 +00:00
# X Y inversion arguments
if args.invx == True:
gstt.swapX[0] = -1 * gstt.swapX[0]
gstt.centerx[0] = 0
gstt.centery[0] = 0
#WriteSettings()
print("laser 0 X new invertion Asked")
if gstt.swapX[0] == 1:
print ("X not Inverted")
else:
print ("X Inverted")
if args.invy == True:
gstt.swapY[0] = -1 * gstt.swapY[0]
gstt.centerx[0] = 0
gstt.centery[0] = 0
#WriteSettings()
print("laser 0 Y new invertion Asked")
if gstt.swapY[0] == 1:
print ("Y not Inverted")
else:
print("Y inverted")
# Redis Computer IP
if args.redisIP != None:
2023-06-03 12:43:53 +00:00
gstt.RediServerIP = args.redisIP
2018-12-13 11:05:32 +00:00
# Point list number used by simulator
if args.display != None:
gstt.simuPL = args.display
2020-09-19 12:28:56 +00:00
print("Display : " + str(gstt.simuPL))
2018-12-13 11:05:32 +00:00
2020-09-19 12:28:56 +00:00
# Lasers = number of laser connected otherwise will be autodetected with one minimum
2018-12-13 11:05:32 +00:00
if args.Lasers != None:
gstt.LaserNumber = args.Lasers
2020-09-29 22:15:40 +00:00
Settings.Write()
2019-03-24 16:24:52 +00:00
2018-12-13 11:05:32 +00:00
2023-06-03 12:43:53 +00:00
if args.oscserverip != None:
gstt.oscIPin = args.oscserverip
2018-12-13 11:05:32 +00:00
else:
2019-03-24 16:24:52 +00:00
gstt.oscIPin = '127.0.0.1'
2018-12-13 11:05:32 +00:00
2019-01-16 00:50:24 +00:00
if args.nozoidIP != None:
gstt.nozoscIP = args.nozoidIP
2018-12-13 11:05:32 +00:00
else:
gstt.nozoscIP = '127.0.0.1'
# Etherdream target for mono laser program
'''
if args.laser != None:
lstdgtlaser = args.laser
if lstdgtlaser == 0:
etherIP = "127.0.0.1"
else:
etherIP = "192.168.1."+str(lstdgtlaser)
else:
etherIP = "192.168.1.4"
#print ("Laser 1 etherIP:",etherIP)
'''
# Reset alignment values
if args.align == True:
gstt.centerx[0] = 0
gstt.centery[0] = 0
gstt.zoomx[0] = 15
gstt.zoomy[0] = 15
gstt.sizex[0] = 32000
gstt.sizey[0] = 32000
gstt.finangle[0] = 0.0
gstt.swapx[0] = 1
gstt.swapy[0] = 1
#Settings.Write()
2020-09-19 12:28:56 +00:00
handle()