Android Open Source - noxdroidandroidapp I O I O Connected Test Thread






From Project

Back to project page noxdroidandroidapp.

License

The source code is released under:

MIT License

If you think the Android project noxdroidandroidapp 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 dk.itu.noxdroid.ioio;
/*from   w w w  .  j  a v a  2  s . co  m*/
import ioio.lib.api.DigitalOutput.Spec;
import ioio.lib.api.IOIO;
import ioio.lib.api.IOIOFactory;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.api.exception.IncompatibilityException;
import android.util.Log;

public class IOIOConnectedTestThread extends Thread {
  public static enum STATUS {CONNECTED, INCOMPATIBLE, CONNECTION_WAITING, NULL, ABORTED, CONNECTION_LOST}
  
  private STATUS status = STATUS.NULL;

  private IOIO ioio_;
  private int pinLed = 9;
  private int pinIn = 40;

  private boolean abort_ = false;
  private boolean connected_ = true;
  
  private String TAG = "NoxDroid_IOIOConnectedTestThread";

  /** Not relevant to subclasses. */
  @Override
  public final void run() {
    super.run();
    while (true) {
      try {
        synchronized (this) {
          if (abort_) {
            break;
          }
          ioio_ = IOIOFactory.create();
        }
        status = STATUS.CONNECTION_WAITING;
        ioio_.waitForConnect();
        connected_ = true;
        status = STATUS.CONNECTED;
        setup();
        abort();
      } catch (ConnectionLostException e) {
        if (abort_) {
          status = STATUS.CONNECTION_LOST;
          abort();
          break;
        }
      } catch (IncompatibilityException e) {
        Log.e("AbstractIOIOActivity", "Incompatible IOIO firmware", e);
        status = STATUS.INCOMPATIBLE;
        // nothing to do - just wait until physical disconnection
        try {
          ioio_.waitForDisconnect();
          break;
        } catch (InterruptedException e1) {
          ioio_.disconnect();
          break;
        }
      } catch (Exception e) {
        Log.e("AbstractIOIOActivity", "Unexpected exception caught", e);
        status = STATUS.ABORTED;
        ioio_.disconnect();
        break;
      } finally {
        try {
          if (ioio_ != null) {
            ioio_.waitForDisconnect();
            if (connected_) {
              abort();
            }
          }
        } catch (InterruptedException e) {
          
        }
      }
    }
  }

  public void setup() throws ConnectionLostException {
    try {
      ioio_.openAnalogInput(pinIn);
      ioio_.openDigitalOutput(pinLed, Spec.Mode.NORMAL, true);
    } catch (ConnectionLostException e) {
      connected_ = false;
    }
  }

  /** Not relevant to subclasses. */
  public synchronized final void abort() {
    Log.d(TAG, "Aborting ");
    abort_ = true;
    if (ioio_ != null) {
      ioio_.disconnect();
    }
    if (connected_) {
      interrupt();
    }
  }
  
  public STATUS getStatus() {
    return this.status;
  }
}




Java Source Code List

dk.itu.noxdroid.NoxDroidActivity.java
dk.itu.noxdroid.NoxDroidApp.java
dk.itu.noxdroid.NoxDroidMainActivity.java
dk.itu.noxdroid.cloudservice.NoxDroidAppEngineUtils.java
dk.itu.noxdroid.database.NoxDroidDbAdapter.java
dk.itu.noxdroid.experiments.ConnectivityTest.java
dk.itu.noxdroid.experiments.DbAdapter.java
dk.itu.noxdroid.experiments.IOIOActivity.java
dk.itu.noxdroid.experiments.IOIOSensorActivity.java
dk.itu.noxdroid.experiments.NoxDroidGPSActivity.java
dk.itu.noxdroid.geocommons.api.DataSet.java
dk.itu.noxdroid.ioio.IOIOConnectedTestThread.java
dk.itu.noxdroid.ioio.IOIOEventListener.java
dk.itu.noxdroid.ioio.NoxDroidIOIOThread.java
dk.itu.noxdroid.location.GPSLocationService.java
dk.itu.noxdroid.location.SkyHookLocationService.java
dk.itu.noxdroid.model.LocationSensor.java
dk.itu.noxdroid.model.Location.java
dk.itu.noxdroid.model.NoxDroid.java
dk.itu.noxdroid.model.NoxSensor.java
dk.itu.noxdroid.model.Nox.java
dk.itu.noxdroid.model.Sensor.java
dk.itu.noxdroid.model.Track.java
dk.itu.noxdroid.service.NoxDroidService.java
dk.itu.noxdroid.setup.PreferencesActivity.java
dk.itu.noxdroid.tracks.TracksListActivity.java
dk.itu.noxdroid.util.GPSUtil.java
dk.itu.noxdroid.util.Line.java
dk.itu.noxdroid.util.SensorDataUtil.java