added server

This commit is contained in:
Lucas Pleß 2018-12-29 19:07:44 +01:00
parent 9ff3d5654f
commit 4532f82d84
1 changed files with 7 additions and 22 deletions

View File

@ -1,38 +1,24 @@
import processing.serial.*;
import processing.net.*;
import java.io.FileWriter;
import java.io.*;
import java.util.*;
import spout.*;
boolean spoutactive=true;
Spout spout;
PFont fontregular;
PImage image_line;
Serial myPort;
Server myServer;
String val = "0.0";
int speeds_show=10;
float[] speeds=new float[speeds_show];
int speeds_index=0; //points to next array index
float speedfloat=0;
float triggerspeedmin=15; //current triggerspeed
PrintWriter pw;
int unitdisplay=0;
int unitdisplay_count=9; //how much different units available
int xtextstart=10;
void setup() {
@ -42,7 +28,8 @@ void setup() {
fontregular=createFont("Montserrat-Regular.ttf",64);
textFont(fontregular);
image_line= loadImage("bleeptrackline.png");
myServer = new Server(this, 2323);
image_line = loadImage("bleeptrackline.png");
//String portName = "COM5";
//String portName = "/dev/ttyUSB0";
@ -62,8 +49,6 @@ void setup() {
sendSpeedTrapValue(int(triggerspeedmin));
//pw=createWriter("speeds.txt");
background(0);
@ -103,6 +88,7 @@ void draw() {
//triggerspeedmin=getTimesMax();
sendSpeedTrapValue(int(triggerspeedmin));
myServer.write(str(speedfloat));
}
}
@ -151,17 +137,15 @@ void draw() {
//Line
image(image_line, 10, 100);
int reducesizefactor=40;
int lastytextpos=200;
for (int i=speeds_show;i>0;i--){
float colorpercentage=i*1.0/speeds_show;
fill(0,132*colorpercentage+163*(1-colorpercentage),176*colorpercentage+86*(1-colorpercentage));
textSize(50-(1-colorpercentage)*reducesizefactor);
text( nf(speeds[(speeds_show+speeds_index-1+i)%speeds_show], 1,2) + " km/h", xtextstart, lastytextpos);
lastytextpos+=50-(1-colorpercentage)*reducesizefactor;
}
textSize(40);
@ -183,6 +167,7 @@ float getTimesMax(){
}
return speedmax;
}
float getTimesPercentile(float p){ //p==1 would be max value
float[] sortedspeeds=sort(speeds);
return sortedspeeds[int(p*sortedspeeds.length)];