use of com.robo4j.hw.rpi.gps.GPSEvent in project robo4j by Robo4J.
the class GPSExample method main.
public static void main(String[] args) throws RoboBuilderException, IOException {
RoboBuilder builder = new RoboBuilder();
builder.add(MtkGPSUnit.class, ID_GPS);
builder.add(GPSProcessor.class, ID_PROCESSOR);
RoboContext ctx = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(ctx));
ctx.start();
System.out.println("State after start:");
System.out.println(SystemUtil.printStateReport(ctx));
RoboReference<GPSRequest> gps = ctx.getReference(ID_GPS);
RoboReference<GPSEvent> processor = ctx.getReference(ID_PROCESSOR);
System.out.println("Press <Enter> to start requesting events, then press enter again to stop requesting events!");
System.in.read();
System.out.println("Requesting GPS events! Press <Enter> to stop!");
gps.sendMessage(new GPSRequest(processor, Operation.REGISTER));
System.in.read();
System.out.println("Ending requesting GPS events...");
gps.sendMessage(new GPSRequest(processor, Operation.UNREGISTER));
// Note that we can still get a few more events after this, and that is
// quite fine. ;)
System.out.println("All done! Press <Enter> to quit!");
System.in.read();
System.out.println("Exiting! Bye!");
ctx.shutdown();
// Seems Pi4J keeps an executor with non-daemon threads around after
// we've used the serial port, even after closing it. :/
System.exit(0);
}
Aggregations