diff --git a/LJ.conf b/LJ.conf index a842d13..b7e6daa 100644 --- a/LJ.conf +++ b/LJ.conf @@ -1,5 +1,5 @@ [General] -lasernumber = 4 +lasernumber = 1 debug = 0 ljayserverip = 127.0.0.1 nozoscip = 127.0.0.1 @@ -26,7 +26,7 @@ warpdest = [[-1500., 1500.], [laser1] color = -1 -ip = 192.168.1.5 +ip = 192.168.1.3 kpps = 25000 centerx = 506 centery = 413 @@ -39,9 +39,9 @@ swapx = -1 swapy = -1 lsteps = [ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)] warpdest = [[-1500., 1500.], - [ 1500., 1500.], - [ 1500.,-1500.], - [-1500.,-1500.]] + [ 1500., 1500.], + [ 1500.,-1500.], + [-1500.,-1500.]] [laser2] color = -1 @@ -58,15 +58,15 @@ swapx = 1 swapy = 1 lsteps = [(1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)] warpdest = [[-1500., 1500.], - [ 1500., 1500.], - [ 1500.,-1500.], - [-1500.,-1500.]] + [ 1500., 1500.], + [ 1500.,-1500.], + [-1500.,-1500.]] [laser3] color = -1 ip = 192.168.1.4 kpps = 25000 -centerx = 0 +centerx = -12 centery = 0 zoomx = 38.0 zoomy = 26.0 @@ -77,7 +77,7 @@ swapx = -1 swapy = -1 lsteps = [(1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)] warpdest = [[-1500., 1500.], - [ 1500., 1500.], - [ 1500.,-1500.], - [-1500.,-1500.]] + [ 1500., 1500.], + [ 1500.,-1500.], + [-1500.,-1500.]] diff --git a/clients/lj.py b/clients/lj.py index 37c8900..d8505d4 100644 --- a/clients/lj.py +++ b/clients/lj.py @@ -20,7 +20,7 @@ Sam Neurohack import math import redis -from OSC import OSCServer, OSCClient, OSCMessage +#from OSC import OSCServer, OSCClient, OSCMessage redisIP = '127.0.0.1' r = redis.StrictRedis(host=redisIP, port=6379, db=0) @@ -39,6 +39,7 @@ oscmsg = OSCMessage() osclientlj.connect((redisIP, 8002)) ''' +''' def Send(oscaddress,oscargs=''): oscmsg = OSCMessage() @@ -53,7 +54,7 @@ def Send(oscaddress,oscargs=''): print ('Connection to LJ refused : died ?') pass #time.sleep(0.001 - +''' def WebStatus(message): Send("/status",message) @@ -249,7 +250,7 @@ def rPolyLineOneColor(xy_list, c, PL , closed, xpos = 0, ypos =0, resize =0.7, r def LinesPL(PL): - print "Stupido !! your code is to old : use DrawPL() instead of LinesPL()" + print ("Stupido !! your code is to old : use DrawPL() instead of LinesPL()") DrawPL(PL) def DrawPL(PL): @@ -311,4 +312,4 @@ def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz): - \ No newline at end of file + diff --git a/clients/planetarium/hipnames b/clients/planetarium/hipnames new file mode 100644 index 0000000..5b56e86 --- /dev/null +++ b/clients/planetarium/hipnames @@ -0,0 +1,96 @@ +Acamar, 13847 +Groombridge 1830, 57939 +Achernar, 7588 +Hadar, 68702 +Acrux, 60718 +Hamal, 9884 +Adhara, 33579 +Izar, 72105 +Agena, 68702 +Kapteyn's star, 24186 +Albireo, 95947 +Kaus Australis, 90185 +Alcor, 65477 +Kocab, 72607 +Alcyone, 17702 +Kruger,60, 110893 +Aldebaran, 21421 +Luyten's star, 36208 +Alderamin, 105199 +Markab, 113963 +Algenib, 1067 +Megrez, 59774 +Algieba, 50583 +Menkar, 14135 +Algol, 14576 +Merak, 53910 +Alhena, 31681 +Mintaka, 25930 +Alioth, 62956 +Mira, 10826 +Alkaid, 67301 +Mirach, 5447 +Almaak, 9640 +Mirphak, 15863 +Alnair, 109268 +Mizar, 65378 +Alnath, 25428 +Nihal, 25606 +Alnilam, 26311 +Nunki, 92855 +Alnitak, 26727 +Phad, 58001 +Alphard, 46390 +Pleione, 17851 +Alphekka, 76267 +Polaris, 11767 +Alpheratz, 677 +Pollux, 37826 +Alshain, 98036 +Procyon, 37279 +Altair, 97649 +Proxima, 70890 +Ankaa, 2081 +Rasalgethi, 84345 +Antares, 80763 +Rasalhague, 86032 +Arcturus, 69673 +Red,Rectangle, 30089 +Arneb, 25985, +Regulus, 49669 +Babcock's star, 112247 +Rigel, 24436 +Barnard's,star, 87937 +Rigil Kent, 71683 +Bellatrix, 25336 +Sadalmelik, 109074 +Betelgeuse, 27989 +Saiph, 27366 +Campbell's star, 96295 +Scheat, 113881 +Canopus, 30438 +Shaula, 85927 +Capella, 24608 +Shedir, 3179 +Caph, 746 +Sheliak, 92420 +Castor, 36850 +Sirius, 32349 +Cor Caroli, 63125 +Spica, 65474 +Cyg X-1, 98298 +Tarazed, 97278 +Deneb, 102098 +Thuban, 68756 +Denebola, 57632 +Unukalhai, 77070 +Diphda, 3419 +Van,Maanen 2, 3829 +Dubhe, 54061 +Vega, 91262 +Enif, 107315 +Vindemiatrix, 63608 +Etamin, 87833 +Zaurak, 18543 +Fomalhaut, 113368 +3C 273, 60936 \ No newline at end of file diff --git a/clients/planetarium/lj3.py b/clients/planetarium/lj3.py index 7f47e5f..6791c54 100644 --- a/clients/planetarium/lj3.py +++ b/clients/planetarium/lj3.py @@ -46,6 +46,7 @@ def OSCstart(): #osc_udp_client(redisIP, 8002, "LJ 8002") def OSCframe(): + #print("OSCprocess") osc_process() # Properly close the system. Todo @@ -55,14 +56,11 @@ def OSCstop(): def Send(oscaddress,oscargs=''): - oscmsg = OSCMessage() - oscmsg.setAddress(oscaddress) - oscmsg.append(oscargs) - - #print ("sending to bhorosc : ",oscmsg) try: msg = oscbuildparse.OSCMessage(oscaddress, None, [oscargs]) osc_send(msg, "LJ 8002") + OSCframe() + except: print ('Connection to LJ refused : died ?') pass @@ -82,11 +80,6 @@ osc_udp_server("0.0.0.0", 3724, "anotherserver") - - - - - ASCII_GRAPHICS = [ # caracteres corrects @@ -341,4 +334,4 @@ def Text(message,c, PL, xpos, ypos, resize, rotx, roty, rotz): - \ No newline at end of file + diff --git a/clients/planetarium/main.py b/clients/planetarium/main.py index c6bfae6..ab3f946 100755 --- a/clients/planetarium/main.py +++ b/clients/planetarium/main.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 # coding=UTF-8 ''' @@ -5,7 +6,7 @@ Multi Laser planetarium in python3 for LJ. v0.01 Sam Neurohack -Accuracy tested against apparent data and starchart at https://www.calsky.com/cs.cgi?cha=7&sec=3&sub=2 +Accuracy could be tested against apparent data and starchart at https://www.calsky.com/cs.cgi?cha=7&sec=3&sub=2 Remember to set the same observer position and time. See Readme for more information @@ -13,8 +14,10 @@ See Readme for more information Todo: +- use debug mode and check altaz calculated values against online sites. - Validate aa2radec() with online calculator. Rewrite it to remove need for Astropy. - Findout how to use OSC in python 3. +- - Code WebUI page. - UpdateStars() in each laser sky. Get magnitude. See UpdateSolar for example. - All Draw operations should also check visibility in the given laser altitude range. @@ -39,7 +42,11 @@ from skyfield.data import hipparcos from osc4py3.as_eventloop import * from osc4py3 import oscbuildparse -from osc4py3 import oscmethod as osm +#from osc4py3 import oscmethod as osm +from osc4py3.oscmethod import * + + + import json @@ -65,8 +72,8 @@ print ("Arguments parsing if needed...") argsparser = argparse.ArgumentParser(description="Planetarium for LJ") argsparser.add_argument("-r","--redisIP",help="IP of the Redis server used by LJ (127.0.0.1 by default) ",type=str) argsparser.add_argument("-c","--client",help="LJ client number (0 by default)",type=int) -argsparser.add_argument("-l","--laser",help="Laser number to be displayed (0 by default)",type=int) -argsparser.add_argument("-d","--debug",help="Verbosity level (0 by default)",type=int) +argsparser.add_argument("-L","--Lasers",help="Number of lasers connected (1 by default).",type=int) +argsparser.add_argument("-v","--verbose",help="Verbosity level (0 by default)",type=int) argsparser.add_argument("-i","--input",help="inputs OSC Port (8005 by default)",type=int) #argsparser.add_argument("-n","--name",help="City Name of the observer",type=str) #argsparser.add_argument("-r","--redisIP",help="Country code of the observer ",type=str) @@ -79,13 +86,13 @@ if args.client: else: ljclient = 0 -if args.laser: - lasernumber = args.laser +if args.Lasers: + lasernumber = args.Lasers else: - lasernumber = 0 + lasernumber = 1 -if args.debug: - debug = args.laser +if args.verbose: + debug = args.verbose else: debug = 0 @@ -322,7 +329,7 @@ def DrawSolar(laser): # Stars # -StarsObjectShape = [(-50,30), (-30,-30), (30,-30), (10,30), (-50,30)] +StarsObjectShape = [(-10,10), (-10,-10), (10,-10), (10,10), (-10,10)] def LoadHipparcos(ts): global hipdata @@ -543,6 +550,26 @@ def InitObserver(SkyCity, SkyCountryCode, time,ts): RadecSkies(LaserSkies, AstroSkyTime) +# Change Observer position by adding deltas (Gpslong, gpslat, elevation in decimal degree/meters) +def UpdateObserver(gpslatdelta, gpslongdelta, elevationdelta,time,ts): + global LaserSkies, Skylat, Skylong, SkyfieldTime, AstrObserver, SkyObserver + + Skylat += gpslatdelta + Skylong += gpslongdelta + Skyelevation += elevationdelta + AstroSkyTime = time + print ("AstroPy time", AstroSkyTime) + SkyfieldTime = ts.from_astropy(AstroSkyTime) + print("SkyfieldTime from AstropyUTC",SkyfieldTime.utc_iso()) + + AstrObserver = EarthLocation(lat = Skylat * u.deg, lon = Skylong * u.deg, height = Skyelevation * u.m,) + SkyObserver = earth + Topos(Skylat, Skylong) + RadecSkies(LaserSkies, AstroSkyTime) + + UpdateSolar() + UpdateStars() + UpdateAnything() + def NewTime(timeshift): SkyfieldTime += timeshift @@ -555,60 +582,60 @@ def NewTime(timeshift): UpdateAnything() -#def handlerfunction(s, x, y): - # Will receive message data unpacked in s, x, y -# pass - -def OSChandler(address, s, x, y): +def OSCstart(value): # Will receive message address, and message data flattened in s, x, y - print("Planetarium OSC server got address", address,"s",s,"x",x,"y",y) - pass - + print("Planetarium OSC server got /planet/start with value", value) + +def OSCUI(value): + # Will receive message address, and message data flattened in s, x, y + print("Planetarium OSC server got /planet/planetUI with value", value) def WebStatus(message): lj3.Send("/status",message) - # # Main part # try: - lj3.OSCstart() - # Make server channels to receive packets. - #osc_udp_server("127.0.0.1", 3721, "localhost") - osc_udp_server("0.0.0.0", OSCinPort, "InPort") - - # Associate Python functions with message address patterns, using default - # argument scheme OSCARG_DATAUNPACK. - #osc_method("/planet/*", handlerfunction) - # Too, but request the message address pattern before in argscheme - osc_method("/planet/*", OSChandler, argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATAUNPACK) + WebStatus("Planetarium") + # OSC Server callbacks + print("Starting OSC at 127.0.0.1 port",OSCinPort,"...") + osc_startup() + osc_udp_server("127.0.0.1", OSCinPort, "InPort") + osc_method("/planet/start*", OSCstart) + osc_method("/planet/planetUI*", OSCUI) + + WebStatus("Load Cities.") ts = load.timescale() LoadCities() + SkyCity = 'Paris' SkyCountryCode = 'FR' + WebStatus(SkyCity) + + WebStatus("Solar System..") LoadSolar() + + WebStatus("Observer..") InitObserver(SkyCity, SkyCountryCode, Time.now(),ts) - + WebStatus("Load Stars..") LoadHipparcos(ts) - - StarSelect() - #print() - #print ("Updating Sky Objects for current observer...") - #print() + WebStatus("Updating...") print("Updating solar system (de421) objects position for observer at", Skylat, Skylong, "time", SkyfieldTime.utc_iso()) UpdateSolar() - #print ("Done.") - #print() + print("Updating stars for observer at", Skylat, Skylong, "time", SkyfieldTime.utc_iso()) UpdateStars(ts) + + WebStatus("Ready") + lj3.Send("/planet/start",1) print ("Done.") # UpdateStars() Todo @@ -617,19 +644,28 @@ try: DisplaySolar = False DisplayOrientation = True DisplayAnything = False + print("Start displaying on",lasernumber,"lasers") while 1: for laser in range(lasernumber): + #print ("Drawing laser",lasernumber) if DisplayOrientation: DrawOrientation(laser) + lj3.OSCframe() + if DisplaySolar: DrawSolar(laser) + lj3.OSCframe() + if DisplayStars: DrawStars(laser) + lj3.OSCframe() + if DisplayAnything: DrawAnything() + lj3.OSCframe() lj3.DrawPL(laser) lj3.OSCframe() @@ -644,6 +680,8 @@ except KeyboardInterrupt: finally: + WebStatus("Planet Exit") + print("Stopping OSC...") lj3.OSCstop() print ("Fin du planetarium.") diff --git a/commands.py b/commands.py index fce97a2..ae489c0 100644 --- a/commands.py +++ b/commands.py @@ -73,7 +73,7 @@ Bob could use /pl/2/0 and /pl/2/1 and Lisa could use /pl/2/2 and /pl/2/3. """ - +from __future__ import absolute_import import types, time import gstt import homographyp @@ -159,144 +159,153 @@ def Mouse(x1,y1,x2,y2): def handler(oscpath, args): print "" - print "Handler" + print "OSC handler in commands.py got oscpath[1] :",oscpath[1], "with args :",args - if oscpath[1] == "client" or oscpath[1] =="noteon" or oscpath[1]=="mouse": + # 2 incoming cases : generic or specific for a given lasernumber + # Need better programming + if oscpath[1] == "client" or oscpath[1] =="noteon" or oscpath[1]=="mouse" or oscpath[1]=="emergency" or oscpath[1]=="simu" or oscpath[1]=="status" or oscpath[1]=="run" or oscpath[1]=="nozoid" or oscpath[1]=="planet" or oscpath[1]=="live" or oscpath[1]=="planet" : + if oscpath[1] == "client": LasClientChange(int(args[0])) + elif oscpath[1] == "noteon": NoteOn(int(args[0])) + elif oscpath[1] == "mouse": Mouse(int(args[0]),int(args[1]),int(args[2]),int(args[3])) + + # /emergency value (0 or 1) + if oscpath[1] == "emergency": + + if args[0] == "1": + print "EMERGENCY MODE" + for laser in range(gstt.lasernumber): + print "Black requested for laser ", laser + BlackOn(laser) + else: + for laser in range(gstt.lasernumber): + print "Back to normal for laser ", laser + UserOn(laser) + else: pathlength = len(oscpath) + if pathlength == 3: laser = int(oscpath[2]) else: laser = int(oscpath[3]) - - print "args[0] :",args[0]," ", type(args[0]) - # /grid/lasernumber value (0 or 1) - if oscpath[1] == "grid": - - if args[0] == "1": - print "Grid requested for laser ", laser - GridOn(laser) - else: - print "No grid for laser ", laser - UserOn(laser) - - - # /black/lasernumber value (0 or 1) - if oscpath[1] == "black": - - if args[0] == "1": - print "Black requested for laser ", laser - BlackOn(laser) - else: - print "No black for laser ", laser - UserOn(laser) - - - # /ip/lasernumber value - if oscpath[1] == "ip": - 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": - print "New kpps for laser ", laser, " next startup", int(args[0]) - gstt.kpps[laser]= int(args[0]) - settings.Write() - - # /angle/lasernumber value - if oscpath[1] == "angle": - print "New Angle modification for laser ", oscpath[2], ":", float(args[0]) - gstt.finANGLE[laser] += float(args[0]) - NewEDH(laser) - "New angle", gstt.finANGLE[laser] + print "args[0] :",args[0]," ", type(args[0]) - # /intens/lasernumber value - if oscpath[1] == "intens": - print "New intensity requested for laser ", laser, ":", int(args[0]) - print "Change not implemented yet" - - - - # /resampler/lasernumber lsteps - # lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]" - if oscpath[1] == "resampler": - Resampler(laser,args[0]) + # /grid/lasernumber value (0 or 1) + if oscpath[1] == "grid": - - # /mouse/lasernumber value (0 or 1) - if oscpath[1] == "mouse": + if args[0] == "1": + print "Grid requested for laser ", laser + GridOn(laser) + else: + print "No grid for laser ", laser + UserOn(laser) + + + # /ip/lasernumber value + if oscpath[1] == "ip": + print "New IP for laser ", laser + gstt.lasersIPS[laser]= args[0] + settings.Write() - 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) - 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) - 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 - gstt.swapY[laser]= -1 - NewEDH(laser) - else: - 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": - print "offset/X laser", laser, "modified to", args[0] - gstt.centerX[laser] -= int(args[0]) - NewEDH(laser) + # /kpps/lasernumber value + # Live change of kpps is not implemented in newdac.py. Change will effect next startup. + if oscpath[1] == "kpps": + print "New kpps for laser ", laser, " next startup", int(args[0]) + gstt.kpps[laser]= int(args[0]) + settings.Write() - # /loffset/Y/lasernumber value - if oscpath[1] == "loffset" and oscpath[2] == "Y": - print "offset/Y laser", laser, "modified to", args[0] - gstt.centerY[laser] -= int(args[0]) - NewEDH(laser) - - - # /scale/X/lasernumber value - if oscpath[1] == "scale" and oscpath[2] == "X": - if gstt.zoomX[laser] + int(args[0]) > 0: - gstt.zoomX[laser] += int(args[0]) - print "scale/X laser", laser , "modified to", gstt.zoomX[laser] + # /angle/lasernumber value + if oscpath[1] == "angle": + print "New Angle modification for laser ", oscpath[2], ":", float(args[0]) + gstt.finANGLE[laser] += float(args[0]) NewEDH(laser) - - # /scale/Y/lasernumber value - if oscpath[1] == "scale" and oscpath[2] == "Y": - if gstt.zoomY[laser] + int(args[0]) > 0: - gstt.zoomY[laser] += int(args[0]) - print "scale/Y laser", laser, "modified to", gstt.zoomY[laser] + "New angle", gstt.finANGLE[laser] + + # /intens/lasernumber value + if oscpath[1] == "intens": + print "New intensity requested for laser ", laser, ":", int(args[0]) + print "Change not implemented yet" + + + + # /resampler/lasernumber lsteps + # lsteps is a string like "[ (1.0, 8),(0.25, 3), (0.75, 3), (1.0, 10)]" + if oscpath[1] == "resampler": + Resampler(laser,args[0]) + + + # /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) + 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) + 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 + gstt.swapY[laser]= -1 + NewEDH(laser) + else: + 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": + print "offset/X laser", laser, "modified to", args[0] + gstt.centerX[laser] -= int(args[0]) NewEDH(laser) + + # /loffset/Y/lasernumber value + if oscpath[1] == "loffset" and oscpath[2] == "Y": + print "offset/Y laser", laser, "modified to", args[0] + gstt.centerY[laser] -= int(args[0]) + NewEDH(laser) + + + # /scale/X/lasernumber value + if oscpath[1] == "scale" and oscpath[2] == "X": + if gstt.zoomX[laser] + int(args[0]) > 0: + gstt.zoomX[laser] += int(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": + if gstt.zoomY[laser] + int(args[0]) > 0: + gstt.zoomY[laser] += int(args[0]) + print "scale/Y laser", laser, "modified to", gstt.zoomY[laser] + NewEDH(laser) ''' For reference values of EDH modifier if assign to keyboard keys (was alignp) diff --git a/gstt.py b/gstt.py index 541b1c9..f8982d1 100644 --- a/gstt.py +++ b/gstt.py @@ -74,11 +74,13 @@ swapY = [1,1,1,-1] # 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) # 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)] + +#stepslongline = [(0.25,1), (0.75, 1), (1.0, 1)] #stepshortline = [(1.0, 8)] -#stepslongline = [(0.25, 3), (0.75, 3), (1.0, 10)] -stepslongline = [(0.25,1), (0.75, 1), (1.0, 1)] -#stepshortline = [(1.0, 8)] -stepslongline = [(1.0, 1)] +#stepslongline = [(1.0, 1)] +#stepshortline = [(1.0, 1)] point = [0,0,0] diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 33eba79..7885de2 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ todo : ''' -from __future__ import absolute_import + import time import gstt import redis @@ -78,8 +78,8 @@ print "Laser client number :",gstt.LasClientNumber serverIP = gstt.LjayServerIP print "Redis IP :", serverIP -bhoroscIP = gstt.oscIPin -print "Bhorosc IP :", bhoroscIP +extoscIP = gstt.oscIPin +print "extosc IP :", extoscIP nozoscIP = gstt.nozoscip print "Nozosc IP :", nozoscIP @@ -94,15 +94,15 @@ print "Lasers requested :", gstt.LaserNumber # Websocket listening port wsPORT = 9001 -# With Bhorosc +# With extosc # OSC Server : accept OSC message on port 8002 #oscIPin = "192.168.1.10"s -bhoroscIPin = serverIP -bhoroscPORTin = 8002 +extoscIPin = serverIP +extoscPORTin = 8002 # OSC Client : to send OSC message to an IP port 8001 -bhoroscIPout = bhoroscIP -bhoroscPORTout = 8001 +extoscIPout = extoscIP +extoscPORTout = 8001 # With Nozoid @@ -110,9 +110,14 @@ bhoroscPORTout = 8001 NozoscIPout = nozoscIP NozoscPORTout = 8003 -#print bhoroscIPin -oscserver = OSCServer( (bhoroscIPin, bhoroscPORTin) ) +# With Planetarium +# OSC Client : to send OSC message to planetarium inport 8005 +planetIPout = nozoscIP +planetPORTout = 8005 + + +oscserver = OSCServer( (extoscIPin, extoscPORTin) ) oscserver.timeout = 0 OSCRunning = True @@ -122,64 +127,90 @@ def handle_timeout(self): oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver) -osclientbhorosc = OSCClient() +osclientext = OSCClient() oscmsg = OSCMessage() -osclientbhorosc.connect((bhoroscIPout, bhoroscPORTout)) +osclientext.connect((extoscIPout, extoscPORTout)) -# send UI string as OSC message to Bhorosc 8001 -# sendbhorosc(oscaddress, [arg1, arg2,...]) +# send UI string as OSC message to extosc 8001 +# sendextosc(oscaddress, [arg1, arg2,...]) -def sendbhorosc(oscaddress,oscargs=''): +def sendextosc(oscaddress,oscargs=''): oscmsg = OSCMessage() oscmsg.setAddress(oscaddress) oscmsg.append(oscargs) - #print ("sending to bhorosc : ",oscmsg) + #print ("sending to extosc : ",oscmsg) try: - osclientbhorosc.sendto(oscmsg, (bhoroscIPout, bhoroscPORTout)) + osclientext.sendto(oscmsg, (extoscIPout, extoscPORTout)) oscmsg.clearData() except: - print ('Connection to bhorosc refused : died ?') + print ('Connection to extosc IP', extoscIPout, 'port', extoscPORTout,'refused : died ?') sendWSall("/on 0") sendWSall("/status NoLJay") - pass + #time.sleep(0.001) # send UI string as OSC message to Nozosc 8003 # sendnozosc(oscaddress, [arg1, arg2,...]) +osclientnozoid = OSCClient() +osclientnozoid.connect((NozoscIPout, NozoscPORTout)) + def sendnozosc(oscaddress,oscargs=''): oscmsg = OSCMessage() oscmsg.setAddress(oscaddress) oscmsg.append(oscargs) - #print ("sending to nozosc : ",oscmsg) + print "Sending OSC to Nozosc server :", oscaddress,'with args', oscargs try: - osclientnozosc.sendto(oscmsg, (NozoscIPout, NozoscPORTout)) + osclientnozoid.sendto(oscmsg, (NozoscIPout, NozoscPORTout)) oscmsg.clearData() except: - print ('Connection to nozosc refused : died ?') + print 'Connection to nozosc IP', NozoscIPout,'port', NozoscPORTout,' refused : died ?' sendWSall("/on 0") sendWSall("/status No Nozosc ") - pass + #time.sleep(0.001) +# send UI string as OSC message to Planet 8005 +# sendplanet(oscaddress, [arg1, arg2,...]) + +osclientplanet = OSCClient() +osclientplanet.connect((planetIPout, planetPORTout)) + +def sendplanet(oscaddress,oscargs=''): + + oscmsg = OSCMessage() + oscmsg.setAddress(oscaddress) + oscmsg.append(oscargs) + + print "Sending OSC to Planet server :", oscaddress,'with args :', oscargs + try: + osclientplanet.sendto(oscmsg, (planetIPout, planetPORTout)) + oscmsg.clearData() + except: + print 'OSC send to planet IP', planetIPout, 'port', planetPORTout, "refused : died ?" + sendWSall("/planet/start 0") + sendWSall("/status No Planet") + + #time.sleep(0.001) # OSC default path handler : send incoming OSC message to UI via websocket 9001 def handler(path, tags, args, source): oscpath = path.split("/") print "" - print "OSC said : ", path, oscpath, args + print "OSC default handler in main said : path", path," oscpath ", oscpath," args", args #print "debug", gstt.debug - if gstt.debug >0: - print "" - print "default handler" - print "OSC said : ", path, oscpath, args + #if gstt.debug >0: + # print "default handler" + # print "OSC said path", path," oscpath ", oscpath," args", args + sendWSall(path + " " + str(args[0])) + commands.handler(oscpath,args) @@ -216,8 +247,8 @@ def osc_thread(): lack= r.get('/lack/'+str(laserid)) - if gstt.debug >0: - print "laserid", laserid,"lack",lack + if gstt.debug >1: + print "laserid", laserid, "lack", lack if lack == 'a': # Dac sent ACK ("a") -> led is green (1) sendWSall("/lack/" + str(laserid) +" 1") if lack == 'F': # Dac sent FULL ("F") -> led is orange (5) @@ -280,27 +311,61 @@ def client_left(client, server): print("WS Client(%d) disconnected" % client['id']) -# Called when a WS client sends a message +# Called for each ws received message. def message_received(client, server, message): if len(message) > 200: message = message[:200]+'..' - if gstt.debug >0: - print ("") - print("WS Client(%d) said: %s" % (client['id'], message)) + #if gstt.debug >0: + # print ("") + # print("WS Client(%d) said: %s" % (client['id'], message)) - print("WS Client(%d) said: %s" % (client['id'], message)) + print("") + oscpath = message.split(" ") - args[0] = str(oscpath[1]) - #print oscpath[0].split("/"),oscpath[1] - commands.handler(oscpath[0].split("/"),args) - - # current UI has no dedicated off button so /on 0 trigs /off to bhorosc - if oscpath[0] == "/on": - if oscpath[1] == "1": - sendbhorosc("/on") + print "WS Client", client['id'], "said :", message, "splitted in an oscpath :", oscpath + + # If message included "planet" forward the message as OSC to planet IP port 8005 + if oscpath[0].find("planet") != -1: + if len(oscpath) == 1: + sendplanet(oscpath[0], oscargs='noargs') else: - sendbhorosc("/off") + sendplanet(oscpath[0], oscargs=oscpath[1]) + + # If message included "nozoid" forward the message as OSC to nozoid IP port 8003 + elif oscpath[0].find("nozoid") != -1: + if len(oscpath) == 1: + sendnozosc(oscpath[0], oscargs='noargs') + else: + sendnozosc(oscpath[0], oscargs=oscpath[1]) + + # If message included "ai" do something + elif oscpath[0].find("ai") != -1: + print "ai order ", oscpath + + # If message included "lissa" do something + elif oscpath[0].find("lissa") != -1: + print "lissa order ", oscpath + + # If message included "vj" do something + elif oscpath[0].find("vj") != -1: + print "VJ order ", oscpath + + elif len(oscpath) > 1: + args[0] = str(oscpath[1]) + #print oscpath[0].split("/"),oscpath[1] + + # current UI has no dedicated off button so /on 0 trigs /off to extosc + elif oscpath[0] == "/on": + if oscpath[1] == "1": + sendextosc("/on") + else: + sendextosc("/off") + + else: + args[0] = "noargs" + commands.handler(oscpath[0].split("/"),args) + # if needed a loop back : WS Client -> server -> WS Client #sendWSall("ws"+message) @@ -367,10 +432,10 @@ try: # Websocket startup server = WebsocketServer(wsPORT,host=serverIP) - # Launch OSC thread listening to Bhorosc + # Launch OSC thread listening to extosc print "" print "Launching OSC server..." - print "at", bhoroscIPin, "port",str(bhoroscPORTin) + print "at", extoscIPin, "port",str(extoscPORTin) print "Will update webUI dac status every second" oscserver.addMsgHandler( "/noteon", commands.NoteOn ) # Default OSC handler for all OSC incoming message diff --git a/webui/LJ.js b/webui/LJ.js index a86b44a..2769bba 100644 --- a/webui/LJ.js +++ b/webui/LJ.js @@ -1,23 +1,25 @@ // -// LJ.js v0.7.0 +// LJ.js v0.7.1 // - +// +// Central horizontal menu +// function noMenu() { - // Set all menu button with normal button style - var x = document.getElementById("showalign"); - x.className = "button"; - var x = document.getElementById("showrun"); - x.className = "button"; - var x = document.getElementById("showcanvas"); - x.className = "button"; - var x = document.getElementById("showlive"); - x.className = "button"; - var x = document.getElementById("shownozoid"); - x.className = "button"; - var x = document.getElementById("showplanet"); - x.className = "button"; + // Set all central menu buttons with normal button style + var x = document.getElementById("align"); + x.value = 0 ; + var x = document.getElementById("run"); + x.value = 0 ; + var x = document.getElementById("simu"); + x.value = 0 ; + var x = document.getElementById("live"); + x.value = 0 ; + var x = document.getElementById("nozoid"); + x.value = 0 ; + var x = document.getElementById("planet"); + x.value = 0 ; // Hide all possible main central grids. var x = document.getElementById("mgalign"); @@ -37,103 +39,188 @@ } function showAlign() { - noMenu(); + noMenu(); var x = document.getElementById("mgalign"); x.style.display = "grid"; - var x = document.getElementById("showalign"); - x.className = "button:checked"; + var x = document.getElementById("align"); + x.value = 1 ; } - function showRun() { - noMenu(); - var x = document.getElementById("mgrun"); - x.style.display = "grid"; - var x = document.getElementById("showrun"); - x.className = "button:checked"; - } + function showRun() { + noMenu(); + var x = document.getElementById("mgrun"); + x.style.display = "grid"; + var x = document.getElementById("run"); + x.value = 1 ; + } - function showCanvas() { - noMenu(); - var x = document.getElementById("mgsimu"); - x.style.display = "grid"; - var x = document.getElementById("cnvbuttons"); - x.style.display = "grid"; - var x = document.getElementById("showcanvas"); - x.className = "button:checked"; - } + function showCanvas() { + noMenu(); + var x = document.getElementById("mgsimu"); + x.style.display = "grid"; + var x = document.getElementById("cnvbuttons"); + x.style.display = "grid"; + var x = document.getElementById("simu"); + x.value = 1 ; + } - function showLive() { - noMenu(); - var x = document.getElementById("mglive"); - x.style.display = "grid"; - var x = document.getElementById("showlive"); - x.className = "button:checked"; - } + function showLive() { + noMenu(); + var x = document.getElementById("mglive"); + x.style.display = "grid"; + var x = document.getElementById("live"); + x.value = 1 ; + } - function showNozoid() { + function showNozoid() { noMenu(); var x = document.getElementById("mgnozoid"); x.style.display = "grid"; - var x = document.getElementById("shownozoid"); - x.className = "button:checked"; - } + var x = document.getElementById("nozoid"); + x.value = 1 ; + } - function showPlanet() { + function showPlanet() { noMenu(); var x = document.getElementById("mgplanet"); - x.style.display = "grid"; + x.style.display = "grid"; var x = document.getElementById("cnvbuttons"); x.style.display = "grid"; - var x = document.getElementById("showplanet"); - x.className = "button:checked"; - } + var x = document.getElementById("planet"); + x.value = 1 ; + } - function buttonClicked(clicked_id) { - _WS.send("/" + clicked_id); - } + function buttonClicked(clicked_id) { - function onSubmit(clicked_id) { - var input = document.getElementById(clicked_id); - console.log("/" + clicked_id + " " + input.value); - _WS.send("/" + clicked_id + " " + input.value); - _WS.showout("/" + clicked_id + " " + input.value); + _WS.send("/" + clicked_id); + + // update Canvas right part of maingrid + if (clicked_id === "planet/planetUI") { + showplanetUI(); + } + if (clicked_id === "nozoid/nozoidUI") { + shownozoidUI(); + } + if (clicked_id === "ai/aiUI") { + showaiUI(); + } + if (clicked_id === "lissa/lissaUI") { + showlissaUI(); + } + if (clicked_id === "vj/vjUI") { + showlissaUI(); + } + if (clicked_id === "nozoid/down 50") { + var x = document.getElementById("nozoid/down 50"); + x.value = 0 ; + } + } + + +// +// SimuUIs +// + + function nosimuUI() { + // Hide all possible main central grids. + var x = document.getElementById("planetUI"); + x.style.display = "none"; + var x = document.getElementById("nozoidUI"); + x.style.display = "none"; + var x = document.getElementById("aiUI"); + x.style.display = "none"; + var x = document.getElementById("lissaUI"); + x.style.display = "none"; + var x = document.getElementById("vjUI"); + x.style.display = "none"; + } + + function showplanetUI() { + nosimuUI(); + var x = document.getElementById("planetUI"); + x.style.display = "grid"; + } + + function shownozoidUI() { + nosimuUI(); + var x = document.getElementById("nozoidUI"); + x.style.display = "grid"; + } + + function showaiUI() { + nosimuUI(); + var x = document.getElementById("aiUI"); + x.style.display = "grid"; + } + + function showlissaUI() { + nosimuUI(); + var x = document.getElementById("lissaUI"); + x.style.display = "grid"; + } + + function showvjUI() { + nosimuUI(); + var x = document.getElementById("vjUI"); + x.style.display = "grid"; + } + + + +// +// Forms submits +// + + function onSubmit(clicked_id) { + var input = document.getElementById(clicked_id); + console.log("/" + clicked_id + " " + input.value); + _WS.send("/" + clicked_id + " " + input.value); + _WS.showout("/" + clicked_id + " " + input.value); } +// +// Websocket handler +// var pl = ""; var pl2 = new Array(); - var _WS = { - uri: 'ws://127.0.0.1:9001/', - ws: null, - init : function (e) { - _WS.s = new WebSocket(_WS.uri); - _WS.s.onopen = function (e) { _WS.onOpen(e); }; - _WS.s.onclose = function (e) { _WS.onClose(e); }; - _WS.s.onmessage = function (e) { _WS.onMessage(e); }; - _WS.s.onerror = function (e) { _WS.onError(e); }; - }, - onOpen: function () { - _WS.showout(_WS.uri); - _WS.showout('CONNECTED'); - document.getElementById("on").value = 1; - }, - onClose: function () { - _WS.showout('DISCONNECTED'); - document.getElementById("on").value = 0; - document.getElementById("lstt/0").value = 0; - document.getElementById("lstt/1").value = 0; - document.getElementById("lstt/2").value = 0; - document.getElementById("lstt/3").value = 0; - document.getElementById("lack/0").value = 0; - document.getElementById("lack/1").value = 0; - document.getElementById("lack/2").value = 0; - document.getElementById("lack/3").value = 0; - }, - onMessage: function (e) { - var res = e.data.split(" "); - //console.log(e.data) - //console.log(res[0].substring(0,6)) + var _WS = { + uri: 'ws://127.0.0.1:9001/', + ws: null, + + init : function (e) { + _WS.s = new WebSocket(_WS.uri); + _WS.s.onopen = function (e) { _WS.onOpen(e); }; + _WS.s.onclose = function (e) { _WS.onClose(e); }; + _WS.s.onmessage = function (e) { _WS.onMessage(e); }; + _WS.s.onerror = function (e) { _WS.onError(e); }; + }, + + onOpen: function () { + _WS.showout(_WS.uri); + _WS.showout('CONNECTED'); + document.getElementById("on").value = 1; + }, + + onClose: function () { + _WS.showout('DISCONNECTED'); + document.getElementById("on").value = 0; + document.getElementById("lstt/0").value = 0; + document.getElementById("lstt/1").value = 0; + document.getElementById("lstt/2").value = 0; + document.getElementById("lstt/3").value = 0; + document.getElementById("lack/0").value = 0; + document.getElementById("lack/1").value = 0; + document.getElementById("lack/2").value = 0; + document.getElementById("lack/3").value = 0; + }, + + onMessage: function (e) { + var res = e.data.split(" "); + //console.log(e.data) + //console.log(res[0].substring(0,6)) + switch (res[0].substring(0,6)) { case "/statu": _WS.showstatus(e.data.slice(8)); @@ -149,39 +236,44 @@ document.getElementById(res[0].slice(1)).value = res[1]; _WS.showin(e.data); } - - }, - onError: function (e) { - _WS.showin('ERROR: ' + e.data); - }, - showin: function (message) { - var divtext = document.getElementById('showin'); - divtext.innerHTML=""; - divtext.innerHTML= message.toString(); - }, - showout: function (message) { - var divtext = document.getElementById('showout'); - divtext.innerHTML=""; - divtext.innerHTML= message.toString(); - }, - showstatus: function (message) { - var divtext = document.getElementById('showstatus'); - divtext.innerHTML=""; - divtext.innerHTML= message.toString(); - }, - send: function (message) { - if (!message.length) { - alert('Empty message not allowed !'); - } else { - _WS.showout(message); - _WS.s.send(message); - } - }, - close: function () { - _WS.showout('GOODBYE !'); - _WS.s.close(); - } - }; + }, - window.addEventListener('load', _WS.init, false); + onError: function (e) { + _WS.showin('ERROR: ' + e.data); + }, + + showin: function (message) { + var divtext = document.getElementById('showin'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + showout: function (message) { + var divtext = document.getElementById('showout'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + showstatus: function (message) { + var divtext = document.getElementById('showstatus'); + divtext.innerHTML=""; + divtext.innerHTML= message.toString(); + }, + + send: function (message) { + if (!message.length) { + alert('Empty message not allowed !'); + } else { + _WS.showout(message); + _WS.s.send(message); + } + }, + + close: function () { + _WS.showout('GOODBYE !'); + _WS.s.close(); + } + }; + + window.addEventListener('load', _WS.init, false); diff --git a/webui/LJgrid.css b/webui/LJgrid.css index c8550f2..2f45c9e 100644 --- a/webui/LJgrid.css +++ b/webui/LJgrid.css @@ -11,7 +11,7 @@ .mgtitle { display: grid; height: 90px; - grid-template-columns: 130px 70px 80px 600px; + grid-template-columns: 130px 70px 80px 70px 530px; background-color: #111; transition: all .3s ease; padding-top: 10px; @@ -21,13 +21,13 @@ } .mgstatus { display: grid; - grid-template-columns: 300px 150px 1fr; + grid-template-columns: 470px 80px 1fr; grid-template-raw: 30px; grid-column-gap: 1px; grid-row-gap: 1px; border-color: #334; border-style: groove; - border-width: 1px; + border-width: 0px; background-color: #111; font-size: small; color:#444; @@ -37,7 +37,7 @@ font-family: 'hobeaux-rococeaux-background', Helvetica; } .mgalign { - display: grid; + display: none; height: 400px; grid-template-columns: 144px 144px 138px 138px 10px 326px; grid-template-rows: 1Fr; @@ -47,13 +47,12 @@ border-width: 1px; } .mgsimu { - display: none; + display: grid; height: 400px; width: 900px; grid-template-columns: 500px 400px; grid-template-rows: 400px; background-color: #151515; - } .cnvbuttons { display: none; @@ -133,7 +132,7 @@ display: grid; height: 80px; grid-template-columns: 60px 75px 40px 60px 75px 60px 75px 60px 75px; - background-color: #111; + background-color: #000; justify-items: center; align-items: center; grid-gap: 1px; @@ -303,10 +302,7 @@ vertical-align: middle; padding: 8px 5px; border: 1px solid #404040; - background: #141414; - background: -webkit-gradient(linear, left top, left bottom, from(#141414), to(#141414)); - background: -moz-linear-gradient(top, #141414, #141414); - background: linear-gradient(to bottom, #141414, #141414); + background: #000; font: normal normal normal 11px arial; color: #ffffff; text-decoration: none; @@ -343,15 +339,22 @@ text-decoration: none; } .submit { - background: #0c0c0c; + background: #000; color: #c0c0c0; width: 90px; text-align: center; vertical-align: middle; height: 15px; - background: -webkit-gradient(linear, left top, left bottom, from(#0c0c0c), to(#141414)); - background: -moz-linear-gradient(top, #0c0c0c, #141414); - background: linear-gradient(to bottom, #0c0c0c, #141414); + border: 1px solid #445; +} +.submitsmall { + background: #000; + color: #c0c0c0; + width: 45px; + text-align: center; + vertical-align: middle; + height: 15px; border: 1px solid #445; } + diff --git a/webui/index.html b/webui/index.html index 075ee21..4dc23fa 100644 --- a/webui/index.html +++ b/webui/index.html @@ -1,5 +1,10 @@ + + +
@@ -50,6 +55,8 @@