예제 #1
0
 public GyroInterface() {
   mSPI = new SPI(SPI.Port.kOnboardCS0);
   mSPI.setClockRate(4_000_000);
   mSPI.setChipSelectActiveLow();
   mSPI.setClockActiveHigh();
   mSPI.setSampleDataOnRising();
   mSPI.setMSBFirst();
 }
 LEDTest() {
   fred = new SPI(Port.kOnboardCS0);
   fred.setClockRate(bitrate);
   fred.setMSBFirst();
   fred.setSampleDataOnFalling();
   fred.setClockActiveLow();
   fred.setChipSelectActiveLow();
 }
  public boolean write() {
    byte[] cmd = new byte[17];
    cmd[0] = cmd[1] = cmd[2] = cmd[3] = (byte) 0x00;
    cmd[4] = cmd[5] = (byte) 0xF0;
    cmd[6] = cmd[7] = (byte) 0x00;
    cmd[8] = (byte) 0xFF;
    cmd[9] = (byte) 0x00;
    cmd[10] = (byte) 0x00;
    cmd[11] = (byte) 0xFF;
    cmd[12] = (byte) 0xFF;
    cmd[13] = (byte) 0x00;
    cmd[14] = (byte) 0xFF;
    cmd[15] = (byte) 0x00;
    cmd[16] = (byte) 0x00;

    if (fred.write(cmd, cmd.length) != cmd.length) {
      return false; // WRITE ERROR
    }
    return true;
  }
예제 #4
0
 /**
  * @param command The word to write
  * @return The result of the transaction
  * @throws GyroInterface.GyroException if the transaction fails
  */
 private int doTransaction(int command) throws GyroException {
   // ensure the parity bit
   if (!isOddParity(command & ~0x01)) {
     command |= 0x01;
   }
   ByteBuffer resultBuffer = ByteBuffer.allocate(4);
   int transactionSize =
       mSPI.transaction(ByteBuffer.allocate(4).putInt(command).array(), resultBuffer.array(), 4);
   if (transactionSize != 4) {
     throw new GyroException("Transaction failed with size: " + transactionSize);
   }
   int result = resultBuffer.getInt(0);
   // check the high-byte parity of the response
   if (!isOddParity(result & 0xffff0000)) {
     throw new GyroException("High bytes parity failure");
   }
   if (!isOddParity(result)) {
     throw new GyroException("Whole word parity failure");
   }
   return result;
 }