// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput inet_pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
// provision gpio pin #01 as an output pin and turn on
final GpioPinDigitalOutput run_pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "LEDrun", PinState.LOW);
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput exitButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_07, PinPullResistance.PULL_DOWN);
// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);
// provision gpio pin #00 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput myButton2 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
// provision gpio pin #03 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput myButton3 = gpio.provisionDigitalInputPin(RaspiPin.GPIO_03, PinPullResistance.PULL_DOWN);
// create and register gpio pin listener
myButton2.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState() == PinState.LOW)
{
System.out.println(ANSI_WHITE +"Velocity Test Start" + ANSI_GREEN);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(SerialCommn.class.getName()).log(Level.SEVERE, null, ex);
}
// System.out.println("Velocity");
hs.store("Test",fm.getSeial());
System.out.println(ANSI_WHITE + "000.000mps" + ANSI_GREEN);
}
}
});
// create and register gpio pin listener
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
long start=0,stop=0;
if(event.getState() == PinState.LOW)
{
if(CheckInternet.testInet("192.168.1.5"))
{
String m = fm.getAddr();
String ser= fm.getSeial();
//System.out.println(ser);
//System.out.println(m);
System.out.println(ANSI_PURPLE +"Register Online");
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(SerialCommn.class.getName()).log(Level.SEVERE, null, ex);
}
//System.out.println("Online...");
RegisterDevice reg = new RegisterDevice();
String s = reg.sendRecord(m +","+ ser);
if(s.equals("false"))
{
System.out.println(ANSI_BLUE +"Device Registered" + ANSI_GREEN);
// System.out.println("Registered");
}
else
{
System.out.println(ANSI_RED +"Already Registered" + ANSI_GREEN);
// System.out.println("Registered");
}
// System.out.println("");
}
else
{
System.out.println(ANSI_RED +"Network Failure");
}
}
}
});
// create and register gpio pin listener
myButton3.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState() == PinState.LOW)
{
if(CheckInternet.testInet("192.168.1.5"))
{
System.out.println(ANSI_WHITE + "Trying Upload" );
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(SerialCommn.class.getName()).log(Level.SEVERE, null, ex);
}
String r = new UploadData().upload();
System.out.println(ANSI_GREEN + r);
}
else
{
System.out.println(ANSI_RED +"Network Failure");
}
}
}
});
exitButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent gpdsce) {
System.exit(0);
}
});
// create an instance of the serial communications class
final Serial serial = SerialFactory.createInstance();
// create and register the serial data listener
serial.addListener(new SerialDataListener() {
@Override
public void dataReceived(SerialDataEvent event) {
// print out the data received to the console
String v = event.getData();
//System.out.print(v);
hs.store(v,fm.getSeial());
System.out.print(ANSI_WHITE + v + " m/s" +ANSI_GREEN);
}
});
run_pin.high();
try {
// open the default serial port provided on the GPIO header
serial.open(Serial.DEFAULT_COM_PORT, 38400);