From 4532f82d8499af386dcc87a6d9d7b282f9797eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Sat, 29 Dec 2018 19:07:44 +0100 Subject: [PATCH] added server --- lichtschranke/speedshow/speedshow.pde | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/lichtschranke/speedshow/speedshow.pde b/lichtschranke/speedshow/speedshow.pde index de0ecd1..156d04c 100644 --- a/lichtschranke/speedshow/speedshow.pde +++ b/lichtschranke/speedshow/speedshow.pde @@ -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)];