Search in sources :

Example 1 with GPS

use of com.robo4j.hw.rpi.serial.gps.GPS in project robo4j by Robo4J.

the class GPSTest method main.

public static void main(String[] args) throws InterruptedException, IOException {
    GPS gps = new GPS();
    gps.addListener(new GPSListener() {

        @Override
        public void onEvent(PositionEvent event) {
            System.out.println(event);
        }

        @Override
        public void onEvent(VelocityEvent event) {
            System.out.println(event);
        }
    });
    gps.startAutoUpdate();
    System.out.println("Press enter to quit!");
    System.in.read();
    gps.shutdown();
}
Also used : GPSListener(com.robo4j.hw.rpi.serial.gps.GPSListener) GPS(com.robo4j.hw.rpi.serial.gps.GPS) VelocityEvent(com.robo4j.hw.rpi.serial.gps.VelocityEvent) PositionEvent(com.robo4j.hw.rpi.serial.gps.PositionEvent)

Example 2 with GPS

use of com.robo4j.hw.rpi.serial.gps.GPS in project robo4j by Robo4J.

the class GPSUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    readInterval = configuration.getInteger("readInterval", DEFAULT_READ_INTERVAL);
    String scheduler = configuration.getString("scheduler", PROPERTY_VALUE_PLATFORM_SCHEDULER);
    boolean usePlatformScheduler = PROPERTY_VALUE_PLATFORM_SCHEDULER.equals(scheduler) ? true : false;
    try {
        gps = new GPS(readInterval);
    } catch (IOException e) {
        throw new ConfigurationException("Could not instantiate GPS!", e);
    }
    if (usePlatformScheduler) {
        scheduledFuture = getContext().getScheduler().scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                gps.update();
            }
        }, 10, readInterval, TimeUnit.MILLISECONDS);
    } else {
        gps.startAutoUpdate();
    }
}
Also used : ConfigurationException(com.robo4j.core.ConfigurationException) GPS(com.robo4j.hw.rpi.serial.gps.GPS) IOException(java.io.IOException)

Aggregations

GPS (com.robo4j.hw.rpi.serial.gps.GPS)2 ConfigurationException (com.robo4j.core.ConfigurationException)1 GPSListener (com.robo4j.hw.rpi.serial.gps.GPSListener)1 PositionEvent (com.robo4j.hw.rpi.serial.gps.PositionEvent)1 VelocityEvent (com.robo4j.hw.rpi.serial.gps.VelocityEvent)1 IOException (java.io.IOException)1