private CommandStatus waitForAck(int timeout) throws InterruptedException {
    log("pn532i2c.waitForAck()");

    byte ackbuff[] = new byte[7];
    byte PN532_ACK[] = new byte[]{0, 0, (byte) 0xFF, 0, (byte) 0xFF, 0};

    int timer = 0;
    String message = "";
    while (true) {
      try {
        int read = i2cDevice.read(ackbuff, 0, 7);
        if (debugReads && read > 0) {
          log("pn532i2c.waitForAck Read " + read + " bytes.");
        }
      } catch (IOException e) {
        message = e.getMessage();
      }

      if ((ackbuff[0] & 1) > 0) {
        break;
      }

      if (timeout != 0) {
        timer += 10;
        if (timer > timeout) {
          log("pn532i2c.waitForAck timeout occured: " + message);
          return CommandStatus.TIMEOUT;
        }
      }
      Gpio.delay(10);

    }

    for (int i = 1; i < ackbuff.length; i++) {
      if (ackbuff[i] != PN532_ACK[i - 1]) {
        log("pn532i2c.waitForAck Invalid Ack.");
        return CommandStatus.INVALID_ACK;
      }
    }
    log("pn532i2c.waitForAck OK");
    return CommandStatus.OK;

  }