60 lines
1.0 KiB
Java
60 lines
1.0 KiB
Java
package pdu_jctrl;
|
|
|
|
import java.io.IOException;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
public class gpio_java
|
|
{
|
|
|
|
public static void main (String [] args)
|
|
{
|
|
System.out.println("Hello World");
|
|
|
|
setgpio(true);
|
|
|
|
try {
|
|
TimeUnit.SECONDS.sleep(1);
|
|
}
|
|
catch(InterruptedException e)
|
|
{
|
|
System.out.println("sleep error InterruptedException ocure");
|
|
}
|
|
|
|
setgpio(false);
|
|
}
|
|
|
|
public static void launchcmd(String cmd)
|
|
{
|
|
// Wenn Simulation True ist kann sie auf dem PC ausfuehren
|
|
// wenn die Simulation false is auf dem Raspberry PI
|
|
boolean simulation = true;
|
|
|
|
if(simulation==true){
|
|
System.out.println(cmd);
|
|
}
|
|
else {
|
|
try{
|
|
Runtime.getRuntime().exec(cmd);
|
|
}
|
|
catch(IOException e)
|
|
{
|
|
System.out.println("process error IOException");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static void setgpio(boolean status)
|
|
{
|
|
launchcmd("/usr/bin/gpio -g mode 14 out");
|
|
|
|
if(status == true)
|
|
{
|
|
launchcmd("/usr/bin/gpio -g write 14 1");
|
|
}
|
|
else
|
|
{
|
|
launchcmd("/usr/bin/gpio -g write 14 0");
|
|
}
|
|
}
|
|
} |