change font and design

This commit is contained in:
interfisch 2018-12-27 14:51:09 +01:00
parent d98700dfbd
commit 749509902c
3 changed files with 103 additions and 50 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

View File

@ -3,15 +3,21 @@ import java.io.FileWriter;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
PFont fontregular;
PImage image_line;
Serial myPort; Serial myPort;
String val = "0.0"; String val = "0.0";
int speeds_show=5; int speeds_show=10;
float[] speeds=new float[speeds_show]; float[] speeds=new float[speeds_show];
int speeds_index=0; //points to next array index int speeds_index=0; //points to next array index
float speedfloat=0; float speedfloat=0;
float triggerspeedmin=15; //current triggerspeed
Date d=new Date(); Date d=new Date();
PrintWriter pw; PrintWriter pw;
@ -19,13 +25,36 @@ PrintWriter pw;
int unitdisplay=0; int unitdisplay=0;
int unitdisplay_count=9; //how much different units available int unitdisplay_count=9; //how much different units available
int xtextstart=10;
void setup() { void setup() {
size(1500, 1000); size(800, 600);
frameRate(30); frameRate(30);
String portName = "COM5";
fontregular=createFont("Montserrat-Regular.ttf",32);
textFont(fontregular);
image_line= loadImage("bleeptrackline.png");
//String portName = "COM5";
//String portName = "/dev/ttyUSB0"; //String portName = "/dev/ttyUSB0";
int useportID=-1;
println("Serialports:");
for(int i=0;i<Serial.list().length;i++){
if (Serial.list()[i].contains("ttyUSB") || Serial.list()[i].contains("COM")){
println(i+" "+Serial.list()[i]);
if (useportID<0){ //no port set yet
useportID=i;
}
}
}
String portName = Serial.list()[useportID];
println("Using Port:"+portName);
myPort = new Serial(this, portName, 115200); myPort = new Serial(this, portName, 115200);
sendSpeedTrapValue(int(triggerspeedmin));
pw=createWriter("speeds.txt"); pw=createWriter("speeds.txt");
background(0); background(0);
@ -36,9 +65,10 @@ void setup() {
void draw() { void draw() {
if ( myPort.available() > 0) { if ( myPort.available() > 0) {
val = myPort.readString(); String sread = myPort.readString();
print("val = " + val); println("serialRead: " + sread);
val = val.substring(0,val.length()-1); if (sread.length()>=7 && sread.substring(0,6).equals("speed=")){ //new speed measurement
val = sread.substring(6,sread.length()-1);
speedfloat=float(val); speedfloat=float(val);
@ -55,70 +85,93 @@ void draw() {
unitdisplay=1; unitdisplay=1;
println("unitdisplay: "+unitdisplay); println("unitdisplay: "+unitdisplay);
triggerspeedmin=getTimesPercentile(0.8);
//triggerspeedmin=getTimesMax();
sendSpeedTrapValue(int(triggerspeedmin));
}
} }
background(0); background(0);
fill(255); fill(0,132,176);
textSize(150); textSize(100);
int xtext=xtextstart;
int ytext=100;
switch(unitdisplay){ switch(unitdisplay){
case 0: case 0:
text(nf(speedfloat,1,2) + " km/h" , 100, 200); text(nf(speedfloat,1,2) + " km/h" , xtext, ytext);
break; break;
case 1: case 1:
text(nf(speedfloat*0.621371,1,2) + " mph" , 100, 200); text(nf(speedfloat*0.621371,1,2) + " mph" , xtext, ytext);
break; break;
case 2: case 2:
text(nf(speedfloat*0.000809848,1,6) + " Mach" , 100, 200); text(nf(speedfloat*0.000809848,1,6) + " Mach" , xtext, ytext);
break; break;
case 3: case 3:
text(nf(speedfloat*0.911344,1,2) + " ft/s" , 100, 200); text(nf(speedfloat*0.911344,1,2) + " ft/s" , xtext, ytext);
break; break;
case 4: case 4:
text(nf(speedfloat*0.277778,1,2) + " m/s" , 100, 200); text(nf(speedfloat*0.277778,1,2) + " m/s" , xtext, ytext);
break; break;
case 5: case 5:
text(nf(speedfloat*0.539957,1,2) + " knots" , 100, 200); text(nf(speedfloat*0.539957,1,2) + " knots" , xtext, ytext);
break; break;
case 6: case 6:
text(nf(speedfloat*1079000000,1,0) + " c" , 100, 200); text(nf(speedfloat*1079000000,1,0) + " c" , xtext, ytext);
break; break;
case 7: case 7:
text(nf(speedfloat*54.67469,1,0) + " ft/min" , 100, 200); text(nf(speedfloat*54.67469,1,0) + " ft/min" , xtext, ytext);
break; break;
case 8: case 8:
text(nf(pow((speedfloat*0.277778/0.836), 2.0/3),1,0) + " Bft" , 100, 200); text(nf(pow((speedfloat*0.277778/0.836), 2.0/3),1,0) + " Bft" , xtext, ytext);
break; break;
} }
//Line
image(image_line, 10, 100);
textSize(80);
//println();
int ipos=1; int reducesizefactor=40;
int lastytextpos=200;
for (int i=speeds_show;i>0;i--){ for (int i=speeds_show;i>0;i--){
ipos++; float colorpercentage=i*1.0/speeds_show;
text( nf(speeds[(speeds_show+speeds_index-1+i)%speeds_show], 1,2) + "km/h", 100, 250+(ipos)*80); 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;
//print(speeds[i]);
//print(",");
} }
textSize(40);
text( "speed trap: "+nf(triggerspeedmin,1,1) +" km/h", 10, height-50);
} }
float getTimesMax(){
float speedmax=0;
for (int i=0;i<speeds_show;i++){
if (speedmax<speeds[i]){
speedmax=speeds[i];
}
}
return speedmax;
}
float getTimesPercentile(float p){ //p==1 would be max value
float[] sortedspeeds=sort(speeds);
return sortedspeeds[int(p*sortedspeeds.length)];
}
void sendSpeedTrapValue(int v){
myPort.write(""+v+"\n");
println("Send trigger speed:"+v);
}