fix config loading

This commit is contained in:
interfisch 2019-10-04 14:14:33 +02:00
parent c70575547f
commit 7a0becfba5

View file

@ -26,13 +26,14 @@ boolean enable_IRImage=false;
boolean enable_colordepth=false;
// Which pixels do we care about?
int minDepth = 200;
int maxDepth = 1000;
int minDepth = 0;
int maxDepth = 910;
// What is the kinect's angle
float angle;
static int boxnum=19;
static int boxnum=50; //maximum boxes
int boxnumloaded=boxnum; //can be changes if less boxes are loaded from config
color box[] = new color[boxnum];
int boxid[] = new int[boxnum];
PVector boxpos[] = new PVector[boxnum]; //center position of box
@ -73,18 +74,21 @@ void setup() {
for (int i=0;i<boxnum;i++) { //initialize boxpositions PVector
boxpos[i]=new PVector();
boxsize[i]=new PVector();
boxenabled[i]=false;
}
//default config
/*
for (int i=0;i<boxnum;i++) { //initialize boxsizes
boxsize[i]=new PVector();
//boxsize[i].x=kinect.width/(boxnum+1);
//boxsize[i].y=kinect.width/(boxnum+1);
boxsize[i].x=kinect.width/(10+1);
boxsize[i].y=kinect.width/(10+1);
}
}*/
/* for testing
int _boxesperrow=10;
for (int j=0;j<=int(boxnum/_boxesperrow);j++) {
int _boxesthisrow=min(_boxesperrow,boxnum-j*_boxesperrow);
@ -94,6 +98,7 @@ void setup() {
boxenabled[i+j*10]=true;
}
}
*/
boxid[0]=15;
boxid[1]=11;
@ -163,7 +168,7 @@ void draw() {
for (int i=0;i<boxnum;i++) {
for (int i=0;i<boxnumloaded;i++) {
float cpmean=0;
int cpmeancounter=0;
float cpmax=0;
@ -359,7 +364,7 @@ void keyPressed() {
}
void sendToWuerfels() {
for (int i=0;i<boxnum;i++) {
for (int i=0;i<boxnumloaded;i++) {
if (boxenabled[i]) {
//print(str(i)+"="+str(brightness(box[i]))+", ");
sPort.write("B,"+str(boxid[i])+","+str(fadetime)+","+int(red(box[i]))+","+int(green(box[i]))+","+int(blue(box[i]))+"\n");
@ -382,9 +387,9 @@ void mouseClicked() {
}
void saveBoxConfig(){
String[] boxconfig=new String[boxnum];
for (int i=0;i<boxnum;i++) {
boxconfig[i]=boxid[i]+";"+float(1.0*boxpos[i].x/kinect.width)+";"+float(1.0*boxpos[i].y/kinect.height)+";"+float(1.0*boxsize[i].x/kinect.width)+";"+float(1.0*boxsize[i].y/kinect.height);
String[] boxconfig=new String[boxnumloaded];
for (int i=0;i<boxnumloaded;i++) {
boxconfig[i]=boxid[i]+";"+(1.0*boxpos[i].x/kinect.width)+";"+(1.0*boxpos[i].y/kinect.height)+";"+(1.0*boxsize[i].x/kinect.width)+";"+(1.0*boxsize[i].y/kinect.height);
}
saveStrings("boxconfig.txt", boxconfig);
println("saved");
@ -392,18 +397,20 @@ void saveBoxConfig(){
infomessage="saved";
}
void loadBoxConfig(){
String[] boxconfig = loadStrings("boxconfig.txt");
for (int i=0;i<boxnum;i++) { //disable boxes
boxenabled[i]=false;
}
boxnumloaded = boxconfig.length;
for (int i=0;i<min(boxconfig.length,boxnum);i++) {
String[] _boxconfsplit=split(boxconfig[i], ';');
boxid[i]=int(_boxconfsplit[0]);
boxpos[i].x=int(_boxconfsplit[1]*kinect.width);
boxpos[i].y=int(_boxconfsplit[2]*kinect.height);
boxsize[i].x=int(_boxconfsplit[3]*kinect.width);
boxsize[i].y=int(_boxconfsplit[4]*kinect.height);
boxpos[i].x=int(float(_boxconfsplit[1])*kinect.width);
boxpos[i].y=int(float(_boxconfsplit[2])*kinect.height);
boxsize[i].x=int(float(_boxconfsplit[3])*kinect.width);
boxsize[i].y=int(float(_boxconfsplit[4])*kinect.height);
boxenabled[i]=true;
}
println("loaded");