-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.pde
More file actions
41 lines (31 loc) · 1.32 KB
/
initialize.pde
File metadata and controls
41 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.lang.ProcessBuilder;
public void Initialize(String dir, String port){
println("Starting upload of " + dir);
//String port = "/dev/ttyACM1";
String[] resetArgs = new String[] {"sudo", "udevadm", "trigger"};
String[] compileArgs = new String[] {"/bin/arduino-cli", "compile","--fqbn", "arduino:avr:uno", dir};
String[] uploadArgs = new String[] {"/bin/arduino-cli", "upload", "-p",port,"--fqbn", "arduino:avr:uno", dir};
File logFile = new File("/home/pi/Desktop/Brew_Pi/log/logFile.txt");
File errorFile = new File("/home/pi/Desktop/Brew_Pi/log/errorFile.txt");
Timer delay = new Timer(3000);
try{
ProcessBuilder reset = new ProcessBuilder(resetArgs);
Process resetProc = reset.start();
ProcessBuilder compile = new ProcessBuilder(compileArgs);
compile.redirectOutput(logFile);
compile.redirectError(errorFile);
Process compileProc = compile.start();
delay.start();
while (!delay.isFinished()){
; //Wait for timer
}
ProcessBuilder upload = new ProcessBuilder(uploadArgs);
upload.redirectOutput(logFile);
upload.redirectError(errorFile);
Process uploadProc = upload.start();
println("Uploaded " + dir + " to port " + port);
}catch(IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}