hopefully fix file writer append issue
This commit is contained in:
parent
32f76f397d
commit
9ff3d5654f
|
@ -25,7 +25,7 @@ float speedfloat=0;
|
||||||
|
|
||||||
float triggerspeedmin=15; //current triggerspeed
|
float triggerspeedmin=15; //current triggerspeed
|
||||||
|
|
||||||
Date d=new Date();
|
|
||||||
|
|
||||||
PrintWriter pw;
|
PrintWriter pw;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void setup() {
|
||||||
|
|
||||||
sendSpeedTrapValue(int(triggerspeedmin));
|
sendSpeedTrapValue(int(triggerspeedmin));
|
||||||
|
|
||||||
pw=createWriter("speeds.txt");
|
//pw=createWriter("speeds.txt");
|
||||||
|
|
||||||
background(0);
|
background(0);
|
||||||
|
|
||||||
|
@ -89,10 +89,12 @@ void draw() {
|
||||||
speeds_index++;
|
speeds_index++;
|
||||||
speeds_index%=speeds_show;
|
speeds_index%=speeds_show;
|
||||||
|
|
||||||
|
Date d=new Date();
|
||||||
|
|
||||||
println(d.getTime()+";"+speedfloat);
|
println(d.getTime()+";"+speedfloat);
|
||||||
pw.println(d.getTime()+";"+speedfloat);
|
//pw.println(d.getTime()+";"+speedfloat);
|
||||||
pw.flush();
|
//pw.flush();
|
||||||
|
appendTextToFile("speeds.txt",d.getTime()+";"+speedfloat);
|
||||||
|
|
||||||
unitdisplay=int(random(0,unitdisplay_count));
|
unitdisplay=int(random(0,unitdisplay_count));
|
||||||
println("unitdisplay: "+unitdisplay);
|
println("unitdisplay: "+unitdisplay);
|
||||||
|
@ -190,3 +192,27 @@ void sendSpeedTrapValue(int v){
|
||||||
myPort.write(""+v+"\n");
|
myPort.write(""+v+"\n");
|
||||||
println("Send trigger speed:"+v);
|
println("Send trigger speed:"+v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void appendTextToFile(String filename, String text){
|
||||||
|
File f = new File(dataPath(filename));
|
||||||
|
if(!f.exists()){
|
||||||
|
createFile(f);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
|
||||||
|
out.println(text);
|
||||||
|
out.close();
|
||||||
|
}catch (IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void createFile(File f){
|
||||||
|
File parentDir = f.getParentFile();
|
||||||
|
try{
|
||||||
|
parentDir.mkdirs();
|
||||||
|
f.createNewFile();
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue