use of com.robo4j.hw.rpi.serial.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(GPSUnit.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