public void read(int address, ByteBuffer dst) throws RuntimeIOException { read(address, SUB_ADDRESS_SIZE_1_BYTE, dst); }
/** * Read multiple bytes from an 8-bit device register * * @param regAddr * First register regAddr to read from * @param length * Number of bytes to read * @throws RuntimeIOException * if an I/O error occurs * @return the bytes read */ public byte[] readBytes(int regAddr, int length) throws RuntimeIOException { // int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t // length, uint8_t *data, uint16_t timeout) return read(regAddr, SUB_ADDRESS_SIZE_1_BYTE, length); }
public ByteBuffer read(int address, int count) { ByteBuffer buffer = ByteBuffer.allocateDirect(count); read(address, buffer); return buffer; }
public byte[] read(int count) throws RuntimeIOException { ByteBuffer buffer = ByteBuffer.allocateDirect(count); read(buffer); byte[] data = new byte[count]; buffer.get(data); return data; }
/** * Get the board revision details * @return revision[0]: Board type (2 == PiconZero); revision[1]: Firmware version */ public byte[] getRevision() { ByteBuffer buffer = device.read(REVISION_REG, 2); byte[] arr = new byte[buffer.remaining()]; buffer.get(arr); return arr; }
public byte[] read(int address, int subAddressSize, int count) throws RuntimeIOException { ByteBuffer buffer = ByteBuffer.allocateDirect(subAddressSize * count); read(address, subAddressSize, buffer); byte[] data = new byte[count]; buffer.get(data); return data; }
public short readShort(int address, int subAddressSize, ByteOrder order) throws RuntimeIOException { ByteBuffer buffer = ByteBuffer.allocateDirect(2); read(address, subAddressSize, buffer); return buffer.getShort(); }
public long readUInt(int address, int subAddressSize, int length, ByteOrder order) throws RuntimeIOException { if (length > 4) { throw new IllegalArgumentException("Can't create an int for " + length + " bytes, max length is 4"); } ByteBuffer buffer = ByteBuffer.allocateDirect(length); read(address, subAddressSize, buffer); return IOUtil.getUInt(buffer, length, order); }
public float[] getValues() { ByteBuffer buffer = device.read(PRESS_MSB_REG, 8);
public byte[] readBytes(int address, int length) { device.write(getAddressByteArray(address)); return device.read(length); }
/** * This method reads the calibration data common for the Temperature sensor * and Barometer sensor included in the BMP180 * @throws RuntimeIOException if an I/O error occurs **/ public void readCalibrationData() throws RuntimeIOException { // Read all of the calibration data into a byte array ByteBuffer calibData = ByteBuffer.allocateDirect(CALIBRATION_BYTES); i2cDevice.read(EEPROM_START, I2CConstants.SUB_ADDRESS_SIZE_1_BYTE, calibData); // Read each of the pairs of data as a signed short calibData.rewind(); calAC1 = calibData.getShort(); calAC2 = calibData.getShort(); calAC3 = calibData.getShort(); // Unsigned short values calAC4 = IOUtil.getUShort(calibData); calAC5 = IOUtil.getUShort(calibData); calAC6 = IOUtil.getUShort(calibData); // Signed sort values calB1 = calibData.getShort(); calB2 = calibData.getShort(); calMB = calibData.getShort(); calMC = calibData.getShort(); calMD = calibData.getShort(); }
private int getRawValue(int adcPin) { if (adcPin < 0 || adcPin >= inputMode.getNumPins()) { throw new IllegalArgumentException("Invalid input channel number (" + adcPin + ") for input mode " + inputMode.getName()); } // Set output enable? byte control_byte = (byte) ((outputEnabled ? ANALOG_OUTPUT_ENABLE_MASK : 0) | inputMode.getControlFlags() | adcPin); // Note if the auto-increment flag is set you need to read 5 bytes (if all channels are in single input mode), // 1 for the previous value + 1 for each channel. device.writeByte(control_byte); byte[] data = device.read(2); // Note data[0] is the previous value held in the DAC register, data[1] is value of data byte 1 return data[1] & 0xff; }