Android Open Source - android-weather-station Serial Data Handler






From Project

Back to project page android-weather-station.

License

The source code is released under:

Apache License

If you think the Android project android-weather-station listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.grundid.weather;
//from   w  w  w.ja v  a 2s  . co m
import de.grundid.weather.io.SerialReceiver;
import de.grundid.weather.io.SerialReceiverListener;
import de.grundid.weather.sensor.WeatherLogger;

public class SerialDataHandler implements SerialReceiverListener {

  private WeatherLogger weatherLogger;
  private Thread thread;

  public SerialDataHandler(WeatherLogger weatherLogger) {
    this.weatherLogger = weatherLogger;
  }

  @Override
  public void onSerialReceiver(final SerialReceiver serialReceiver) {
    Runnable runnable = new Runnable() {

      @Override
      public void run() {
        while (!Thread.interrupted()) {
          byte[] data = serialReceiver.receive();
          if (data.length > 0) {
            weatherLogger.readData(data, data.length);
          }
          try {
            Thread.sleep(100);
          }
          catch (InterruptedException e) {
            return;
          }
        }
        serialReceiver.releaseDevice();
      }
    };
    thread = new Thread(runnable);
    thread.start();
  }

  public void releaseDevice() {
    thread.interrupt();
  }
}




Java Source Code List

de.grundid.weather.Beeper.java
de.grundid.weather.Constants.java
de.grundid.weather.MainActivity.java
de.grundid.weather.SensorHandler.java
de.grundid.weather.SerialDataHandler.java
de.grundid.weather.io.AttachedDeviceHandler.java
de.grundid.weather.io.ConnectedUsbDevice.java
de.grundid.weather.io.PermissionBroadcastReceiver.java
de.grundid.weather.io.SerialReceiverListener.java
de.grundid.weather.io.SerialReceiver.java
de.grundid.weather.io.UsbConnectionException.java
de.grundid.weather.sensor.InsideSensor.java
de.grundid.weather.sensor.LightSensor.java
de.grundid.weather.sensor.OutsideSensor.java
de.grundid.weather.sensor.SensorFactory.java
de.grundid.weather.sensor.SensorListener.java
de.grundid.weather.sensor.Sensor.java
de.grundid.weather.sensor.WeatherLogger.java
de.grundid.weather.utils.Utils.java