configure UI and more leapmotion examples

This commit is contained in:
Sam 2023-07-19 23:05:06 +02:00
parent 9b0c8ffc86
commit ebe188592e
4 changed files with 392 additions and 1 deletions

295
configureUI.py Executable file
View File

@ -0,0 +1,295 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
LJay/LJ
v0.7.0
Config HI
LICENCE : CC
'''
import os
import configparser as cp
import tkinter as tk
import configparser
from libs3 import gstt
import ast
import numpy as np
import fileinput
from shutil import copyfile
config = configparser.ConfigParser()
config.read(gstt.ConfigName)
ljpath = r'%s' % os.getcwd().replace('\\','/')
def Write():
print('Saving ',gstt.ConfigName)
updateJSConfig(config)
config.set('General', 'lasernumber', lasernumberVal.get())
config.set('General', 'rediserverip', rediserveripVal.get())
config.set('General', 'wwwip', wwwipVal.get())
config.set('General', 'oscserverip', str(gstt.oscIPin))
config.set('General', 'nozoscip', str(gstt.nozoscIP))
config.set('General', 'debug',debugVal.get())
config.set('General', 'autostart', autostartVal.get())
for i in range(gstt.LaserNumber):
laser = 'laser' + str(i)
config.set(laser, 'ip', str(gstt.lasersIPS[i]))
config.set(laser, 'type', str(gstt.lasertype[i]))
config.set(laser, 'dac_family', str(gstt.dacs[i]))
config.set(laser, 'kpps', str(gstt.kpps[i]))
config.set(laser, 'centerx', str(gstt.centerX[i]))
config.set(laser, 'centery', str(gstt.centerY[i]))
config.set(laser, 'zoomx', str(gstt.zoomX[i]))
config.set(laser, 'zoomy', str(gstt.zoomY[i]))
config.set(laser, 'sizex', str(gstt.sizeX[i]))
config.set(laser, 'sizey', str(gstt.sizeY[i]))
config.set(laser, 'finangle', str(gstt.finANGLE[i]))
config.set(laser, 'swapx', str(gstt.swapX[i]))
config.set(laser, 'swapy', str(gstt.swapY[i]))
config.set(laser, 'warpdest', np.array2string(gstt.warpdest[i], precision=2, separator=',',suppress_small=True))
config.write(open(gstt.ConfigName,'w'))
def Read():
gstt.LaserNumber = config.getint('General', 'lasernumber')
gstt.RediServerIP= config.get('General', 'rediserverip')
gstt.wwwIP= config.get('General', 'wwwip')
gstt.oscIPin = config.get('General', 'oscserverip')
gstt.nozoscIP = config.get('General', 'nozoscip')
gstt.debug = config.get('General', 'debug')
gstt.plugins = ast.literal_eval(config.get('plugins', 'plugins'))
gstt.autostart = config.get('General', 'autostart')
for i in range(4):
laser = 'laser' + str(i)
gstt.lasersIPS[i]= config.get(laser, 'ip')
gstt.lasertype[i]= config.get(laser, 'type')
gstt.kpps[i] = config.getint(laser, 'kpps')
gstt.dacs[i] = config.get(laser, 'dac_family')
#gstt.lasersPLcolor[i] = config.getint(laser, 'color')
gstt.centerX[i]= config.getfloat(laser, 'centerx')
gstt.centerY[i] = config.getfloat(laser, 'centery')
gstt.zoomX[i] = config.getfloat(laser, 'zoomx')
gstt.zoomY[i] = config.getfloat(laser, 'zoomy')
gstt.sizeX[i] = config.getfloat(laser, 'sizex')
gstt.sizeY[i] = config.getfloat(laser, 'sizey')
gstt.finANGLE[i] = config.getfloat(laser, 'finangle')
gstt.swapX[i] = config.getint(laser, 'swapx')
gstt.swapY[i] = config.getint(laser, 'swapy')
gstt.lsteps[i] = ast.literal_eval(config.get(laser, 'lsteps'))
gstt.warpdest[i]= np.array(ast.literal_eval(config.get(laser, 'warpdest')))
#
# UI
#
def UIelements(currentLaser):
tk.Label(UI, text='Lasers', fg='#FFFFB0',width = 10).grid(row=0, column=0)
tk.Label(UI, text='LJ IP',fg='#FFFF90').grid(row=0, column=2)
tk.Label(UI, text='www IP',fg='#FFFF80').grid(row=1, column=0)
tk.Label(UI, text='debug',fg='#FFFF90').grid(row=1, column=2)
tk.Label(UI, text='autostart',fg='#FFFF90').grid(row=2, column=0)
tk.Label(UI, text='Laser').grid(row=3, column=0)
tk.Label(UI, text='IP').grid(row=3, column=2)
tk.Label(UI, text='type').grid(row=4, column=0)
tk.Label(UI, text='dac').grid(row=4, column=2)
tk.Label(UI, text='kpps').grid(row=5, column=0)
tk.Label(UI, text='finangle').grid(row=5, column=2)
tk.Label(UI, text='centerx').grid(row=6, column=0)
tk.Label(UI, text='centery').grid(row=6, column=2)
tk.Label(UI, text='zoomx').grid(row=7, column=0)
tk.Label(UI, text='zoomy').grid(row=7, column=2)
tk.Label(UI, text='sizex').grid(row=8, column=0)
tk.Label(UI, text='sizey').grid(row=8, column=2)
tk.Label(UI, text='swapx').grid(row=9, column=0)
tk.Label(UI, text='swapy').grid(row=9, column=2)
tk.Label(UI, text='lsteps').grid(row=10, column=0)
tk.Label(UI, text='warpdest').grid(row=10, column=2)
tk.Label(UI, text='color').grid(row=11, column=0)
lasernumberVal.set(str(gstt.LaserNumber))
rediserveripVal.set(str(gstt.RediServerIP))
wwwipVal.set(str(gstt.wwwIP))
debugVal.set(str(gstt.debug))
autostartVal.set(str(gstt.autostart))
laserVal.set(str(currentLaser))
lasernumber = tk.Entry(UI,fg='#FFFFA0', textvariable = lasernumberVal)
rediserverip = tk.Entry(UI,textvariable =rediserveripVal)
wwwip = tk.Entry(UI, textvariable =wwwipVal)
oscserverip = tk.Entry(UI)
nozoscip = tk.Entry(UI)
debug = tk.Entry(UI, textvariable =debugVal)
autostart = tk.Entry(UI, textvariable =autostartVal)
dac = tk.Entry(UI, textvariable =dacVal)
laser = tk.Entry(UI, textvariable =laserVal)
#laser.bind('<Return>', validate(laserVal.get()))
#laser.bind('<Enter>', validate(laserVal.get()))
laser.bind('<Return>', (lambda _: validate(laserVal.get())))
laser.bind('<Enter>', (lambda _: validate(laserVal.get())))
#ipVal = tk.StringVar()
ip = tk.Entry(UI, textvariable =ipVal)
ip.bind('<Return>', (lambda _: Update('ip', ipVal.get())))
type = tk.Entry(UI, textvariable =typeVal)
dac = tk.Entry(UI, textvariable =dacVal)
kpps = tk.Entry(UI, textvariable =kppsVal)
color = tk.Entry(UI, textvariable =colorVal)
centerx = tk.Entry(UI, textvariable =centerxVal)
centery = tk.Entry(UI, textvariable =centeryVal)
zoomxVal.set(str(gstt.zoomX[currentLaser]))
zoomx = tk.Entry(UI, textvariable =zoomxVal)
zoomy = tk.Entry(UI, textvariable =zoomyVal)
sizexVal.set(str(gstt.sizeX[currentLaser]))
sizex = tk.Entry(UI, textvariable =sizexVal)
sizey = tk.Entry(UI, textvariable =sizeyVal)
finangle = tk.Entry(UI, textvariable =finangleVal)
swapx = tk.Entry(UI, textvariable =swapxVal)
swapy = tk.Entry(UI, textvariable =swapyVal)
lsteps = tk.Entry(UI, textvariable =lstepsVal)
warpdest = tk.Entry(UI, textvariable =warpdestVal)
lasernumber.grid(row=0, column=1,padx=10)
rediserverip.grid(row=0, column=3,padx=10)
wwwip.grid(row=1, column=1)
debug.grid(row=1, column=3)
autostart.grid(row=2, column=1)
laser.grid(row=3, column=1)
ip.grid(row=3, column=3)
type.grid(row=4, column=1)
dac.grid(row=4, column=3)
kpps.grid(row=5, column=1)
finangle.grid(row=5, column=3)
centerx.grid(row=6, column=1)
centery.grid(row=6, column=3)
zoomx.grid(row=7, column=1)
zoomy.grid(row=7, column=3)
sizex.grid(row=8, column=1)
sizey.grid(row=8, column=3)
swapx.grid(row=9, column=1)
swapy.grid(row=9, column=3)
lsteps.grid(row=10, column=1)
warpdest.grid(row=10, column=3)
color.grid(row=11, column=1)
save = tk.Button(UI, text="Save", command=Write).grid(row=12, column=1)
ok = tk.Button(UI, text="Ok", command=Exit).grid(row=12, column=3)
UI.title(string='LJ2 config')
def Exit():
UI.destroy()
def validate(input):
data =str(input)
if data.isdigit():
#print(input+" is digit")
UIpdateLaser(int(data))
return True
elif input == "":
print(input+ "is null")
return True
else:
print(input)
return False
def updateJSConfig(config):
global ljpath
wwwip = config.get('General','wwwip')
wstype = config.get('General','wstype')
wsport = config.get('General','wsport')
# copy template
src = ljpath + "/templates/config.js"
dst = ljpath + "/www/config.js"
copyfile(src, dst)
# Interpolate variables
with fileinput.FileInput(dst, inplace=True) as file:
for line in file:
line = line.replace("%wstype%", wstype)
line = line.replace("%wsport%", wsport)
line = line.replace("%wwwip%", wwwip)
print(line, end='')
print('www UI updated.')
def Updategstt(var, value):
print("modify ",var," with ",value)
#var=value
config.set('laser' + laserVal.get(), var, value)
config.write
def Update(var, value):
print("modify ",var," with ",value)
#var=value
config.set('laser' + laserVal.get(), var, value)
config.write
def UIpdateLaser(number):
#print('updating with laser : ', number)
ipVal.set(str(gstt.lasersIPS[number]))
typeVal.set(str(gstt.lasertype[number]))
dacVal.set(str(gstt.dacs[number]))
kppsVal.set(str(gstt.kpps[number]))
colorVal.set("Not implemented")
dacVal.set(str(gstt.dacs[number]))
centerxVal.set(str(gstt.centerX[number]))
centeryVal.set(str(gstt.centerY[number]))
zoomxVal.set(str(gstt.zoomX[number]))
zoomyVal.set(str(gstt.zoomY[number]))
sizexVal.set(str(gstt.sizeX[number]))
sizeyVal.set(str(gstt.sizeY[number]))
finangleVal.set(str(gstt.finANGLE[number]))
swapxVal.set(str(gstt.swapX[number]))
swapyVal.set(str(gstt.swapY[number]))
lstepsVal.set(str(gstt.lsteps[number]))
warpdestVal.set(str(gstt.warpdest[number]))
UI = tk.Tk()
lasernumberVal = tk.StringVar()
rediserveripVal = tk.StringVar()
wwwipVal = tk.StringVar()
debugVal = tk.StringVar()
autostartVal = tk.StringVar()
laserVal = tk.StringVar()
ipVal = tk.StringVar()
typeVal = tk.StringVar()
dacVal = tk.StringVar()
kppsVal = tk.StringVar()
colorVal = tk.StringVar()
centerxVal = tk.StringVar()
centeryVal = tk.StringVar()
zoomxVal = tk.StringVar()
zoomyVal = tk.StringVar()
sizexVal = tk.StringVar()
sizeyVal = tk.StringVar()
finangleVal = tk.StringVar()
swapxVal = tk.StringVar()
swapyVal = tk.StringVar()
lstepsVal = tk.StringVar()
warpdestVal = tk.StringVar()
currentLaser =0
Read()
UIelements(currentLaser)
UIpdateLaser(currentLaser)
#UI.update_lasernumber(str(gstt.LaserNumber))
UI.mainloop()

View File

@ -0,0 +1,54 @@
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;
LeapMotionP5 leap;
ArrayList<PVector> points = new ArrayList<PVector>();
int rgb2int(int r, int g, int b) {
return (r << 16) + (g << 8) + b;
}
void setup() {
size(640, 360);
leap = new LeapMotionP5(this);
}
void draw() {
background(51);
stroke(255);
strokeWeight(2); // adjust the thickness of the circle outline
for (Finger finger : leap.getFingerList()) {
PVector fingerPos = leap.getTip(finger);
points.add(fingerPos);
}
if (points.size() > 0) {
String pointList = "["; // initialize the point list string
for (int i = 0; i < points.size(); i++) {
PVector center = points.get(i);
pointList += "(" + center.x + "," + center.y + ",0),";
int[] rgb = {254, 254, 254};
for (int j = 0; j < 15; j++) { // Update the loop to generate 30 points per circle
float angle = map(j, 0, 15, 0, TWO_PI);
float x = center.x + cos(angle) * 5;
float y = center.y + sin(angle) * 5;
pointList += "(" + x + "," + y + "," + rgb2int(rgb[0], rgb[1], rgb[2]) + "),";
if (j > 0) {
float prevX = center.x + cos(map(j - 1, 0, 15, 0, TWO_PI)) * 10;
float prevY = center.y + sin(map(j - 1, 0, 15, 0, TWO_PI)) * 10;
line(prevX, prevY, x, y);
}
}
}
points.clear();
pointList = pointList.substring(0, pointList.length() - 1); // remove the last comma
pointList += "]"; // close the point list string
System.out.println(pointList);
Jedis jedis = new Jedis("localhost");
jedis.set("/pl/0/0", pointList);
jedis.close();
}
}

View File

@ -0,0 +1,40 @@
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
ArrayList<PVector> points = new ArrayList<PVector>();
int rgb2int(int[] rgb) {
return color(rgb[0], rgb[1], rgb[2]);
}
void setup() {
size(640, 360);
}
void draw() {
background(51);
stroke(255);
strokeWeight(2); // adjust the thickness of the circle outline
if (mousePressed) {
PVector p = new PVector(mouseX, mouseY);
points.add(p);
noFill(); // disable filling
ellipse(p.x, p.y, 10, 10); // draw a circle with lines at the point
}
if (points.size() > 0) {
String pointList = "[";
for (int i = 0; i < points.size(); i++) {
PVector p = points.get(i);
int[] rgb = {255, 255, 255};
pointList += "(" + p.x + "," + p.y + "," + rgb2int(rgb) + "),";
}
pointList = pointList.substring(0, pointList.length() - 1); // remove the last comma
pointList += "]";
System.out.println(pointList);
Jedis jedis = new Jedis("localhost");
jedis.set("/pl/0/0", pointList);
jedis.close();
}
}

View File

@ -8,7 +8,7 @@ int rgb2int(int r, int g, int b) {
}
void setup() {
size(640, 360);
size(400, 200);
noStroke();
rectMode(CENTER);
}
@ -29,6 +29,7 @@ void draw() {
points.add(new PVector(mouseX-rect1Width/2, height/2-rect1Height/2));
points.add(new PVector(mouseX+rect1Width/2, height/2-rect1Height/2));
points.add(new PVector(mouseX+rect1Width/2, height/2+rect1Height/2));
points.add(new PVector(mouseX-rect1Width/2, height/2+rect1Height/2));
points.add(new PVector(mouseX-rect1Width/2, height/2-rect1Height/2));
// Draw second rectangle using lines
int inverseX = width-mouseX;
@ -43,6 +44,7 @@ void draw() {
points.add(new PVector(inverseX+rect2Width/2, height/2-rect2Height/2));
points.add(new PVector(inverseX+rect2Width/2, height/2+rect2Height/2));
points.add(new PVector(inverseX-rect2Width/2, height/2+rect2Height/2));
points.add(new PVector(inverseX-rect2Width/2, height/2-rect2Height/2));
if (points.size() > 0) {
println("point size : "+points.size());
println("pointlist");