Exemplo n.º 1
0
  public void run() {
    try {
      switch (m_Task) {
        case Connect:
          m_IOIO.waitForConnect();

          IOIOInterface.OnIOIOConnected();
          break;
        case Disconnect:
          m_IOIO.waitForDisconnect();

          IOIOInterface.OnIOIODisconnected();
          break;
      }
    } catch (ConnectionLostException e) {
      IOIOInterface.Log("Lost connection during IOIOWaitThread (" + m_Task + ")");
      IOIOInterface.OnIOIODisconnected();
    } catch (IncompatibilityException e) {
      IOIOInterface.Log("Incompatibility detected during IOIOWaitThread (" + m_Task + ")");
      IOIOInterface.OnIOIOIncompatible();
    } catch (InterruptedException e)
    // This one is most likely our own doing
    {
    }
  }
 /** Not relevant to subclasses. */
 @Override
 public final void run() {
   super.run();
   while (true) {
     try {
       synchronized (this) {
         if (abort_) {
           break;
         }
         ioio_ = IOIOFactory.create();
       }
       ioio_.waitForConnect();
       setup();
       while (true) {
         loop();
       }
     } catch (ConnectionLostException e) {
       if (abort_) {
         break;
       }
     } catch (Exception e) {
       Log.e("AbstractIOIOActivity", "Unexpected exception caught", e);
       ioio_.disconnect();
       break;
     } finally {
       try {
         ioio_.waitForDisconnect();
       } catch (InterruptedException e) {
       }
     }
   }
 }
Exemplo n.º 3
0
 private void showVersions(IOIO ioio, String title) {
   toast(
       String.format(
           "%s\n"
               + "IOIOLib: %s\n"
               + "Application firmware: %s\n"
               + "Bootloader firmware: %s\n"
               + "Hardware: %s",
           title,
           ioio.getImplVersion(IOIO.VersionType.IOIOLIB_VER),
           ioio.getImplVersion(IOIO.VersionType.APP_FIRMWARE_VER),
           ioio.getImplVersion(IOIO.VersionType.BOOTLOADER_VER),
           ioio.getImplVersion(IOIO.VersionType.HARDWARE_VER)));
 }
Exemplo n.º 4
0
 /** Not relevant to subclasses. */
 public final synchronized void abort() {
   abort_ = true;
   if (ioio_ != null) {
     ioio_.disconnect();
   }
   if (connected_) {
     interrupt();
   }
 }
Exemplo n.º 5
0
  /** Not relevant to subclasses. */
  @Override
  public final void run() {
    super.run();
    Looper.prepare();
    while (true) {
      try {
        synchronized (this) {
          if (abort_) {
            break;
          }
          ioio_ = IOIOFactory.create(spec_.className, spec_.args);
        }

        ioio_.waitForConnect();

        connected_ = true;

        setup();
        while (!abort_) {
          loop();
        }
        ioio_.disconnect();
      } catch (ConnectionLostException e) {
        RunningScreen.piezoSignal = false;
        if (abort_) {
          break;
        }
      } catch (InterruptedException e) {

        ioio_.disconnect();
        break;
      } catch (IncompatibilityException e) {
        Log.e(TAG, "Incompatible IOIO firmware", e);
        incompatible();
        // nothing to do - just wait until physical disconnection
        try {
          ioio_.waitForDisconnect();
        } catch (InterruptedException e1) {
          ioio_.disconnect();
        }
      } catch (Exception e) {
        System.out.println("in exception handler");
        Log.e(TAG, "Unexpected exception caught", e);
        ioio_.disconnect();
        break;
      } finally {

        try {
          if (ioio_ != null) {
            ioio_.waitForDisconnect();
            if (connected_) {
              disconnected();
            }
          }
        } catch (InterruptedException e) {
        }
      }
    }
  }
Exemplo n.º 6
0
  private boolean runTest(int inPin, int outPin) throws Exception {
    if (outPin == 9) {
      // pin 9 doesn't support peripheral output
      return true;
    }
    final int BYTE_COUNT = 2000;
    final int SEED = 17;

    Uart uart = ioio_.openUart(inPin, outPin, 115200, Uart.Parity.NONE, Uart.StopBits.ONE);
    InputStream in = uart.getInputStream();
    OutputStream out = uart.getOutputStream();
    Random rand = new Random(SEED);
    bytesVerified_ = 0;
    Thread reader = new ReaderThread(in, SEED, BYTE_COUNT);
    reader.start();
    try {
      for (int i = 0; i < BYTE_COUNT; ++i) {
        byte value = (byte) rand.nextInt();
        out.write(value);
      }
      reader.join();
    } catch (Exception e) {
      try {
        in.close();
      } catch (IOException e1) {
      }
      reader.interrupt();
      reader.join();
      throw e;
    } finally {
      uart.close();
    }
    if (bytesVerified_ != BYTE_COUNT) {
      Log.w(
          "IOIOTortureTest",
          "Failed UartTest input: "
              + inPin
              + ", output: "
              + outPin
              + ". Bytes passed: "
              + bytesVerified_);
      return false;
    }
    return true;
  }