|
@@ -0,0 +1,60 @@
|
|
1
|
+package pdu_jctrl;
|
|
2
|
+
|
|
3
|
+import java.io.IOException;
|
|
4
|
+import java.util.concurrent.TimeUnit;
|
|
5
|
+
|
|
6
|
+public class gpio_java
|
|
7
|
+{
|
|
8
|
+
|
|
9
|
+ public static void main (String [] args)
|
|
10
|
+ {
|
|
11
|
+ System.out.println("Hello World");
|
|
12
|
+
|
|
13
|
+ setgpio(true);
|
|
14
|
+
|
|
15
|
+ try {
|
|
16
|
+ TimeUnit.SECONDS.sleep(1);
|
|
17
|
+ }
|
|
18
|
+ catch(InterruptedException e)
|
|
19
|
+ {
|
|
20
|
+ System.out.println("sleep error InterruptedException ocure");
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ setgpio(false);
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ public static void launchcmd(String cmd)
|
|
27
|
+ {
|
|
28
|
+ // Wenn Simulation True ist kann sie auf dem PC ausfuehren
|
|
29
|
+ // wenn die Simulation false is auf dem Raspberry PI
|
|
30
|
+ boolean simulation = true;
|
|
31
|
+
|
|
32
|
+ if(simulation==true){
|
|
33
|
+ System.out.println(cmd);
|
|
34
|
+ }
|
|
35
|
+ else {
|
|
36
|
+ try{
|
|
37
|
+ Runtime.getRuntime().exec(cmd);
|
|
38
|
+ }
|
|
39
|
+ catch(IOException e)
|
|
40
|
+ {
|
|
41
|
+ System.out.println("process error IOException");
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ public static void setgpio(boolean status)
|
|
48
|
+ {
|
|
49
|
+ launchcmd("/usr/bin/gpio -g mode 14 out");
|
|
50
|
+
|
|
51
|
+ if(status == true)
|
|
52
|
+ {
|
|
53
|
+ launchcmd("/usr/bin/gpio -g write 14 1");
|
|
54
|
+ }
|
|
55
|
+ else
|
|
56
|
+ {
|
|
57
|
+ launchcmd("/usr/bin/gpio -g write 14 0");
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+}
|