upm/examples/java/RHUSB_Example.java
Mihai Tudor Panu 89d5de43e0 license: update to SPDX style license text throughout
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2020-03-05 15:13:36 -08:00

48 lines
1.3 KiB
Java

/*
* Author: Stefan Andritoiu <stefan.andritoiu@gmail.com>
* Copyright (c) 2017 Intel Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the The MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
*/
public class RHUSB_Example {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
String defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
System.out.println("Initializing...");
// Instantiate an RHUSB instance on defaultDev
upm_rhusb.RHUSB sensor = new upm_rhusb.RHUSB(defaultDev);
// output the firmware ID
System.out.println("Firmware ID: " + sensor.getFirmwareID());
// update and print available values every second
while (true) {
// update our values from the sensor
sensor.update();
// we show both C and F for temperature
System.out.println("Temperature: " + sensor.getTemperature() + " C / " + sensor.getTemperature(true) + " F");
System.out.println("Humidity: " + sensor.getHumidity() + " %");
Thread.sleep(1000);
}
// ! [Interesting]
}
}