public TSL2561(int controllerNumber, int addressSize, int clockFreq, TSL2561Package tsl2561Package) throws RuntimeIOException { i2cDevice = new I2CDevice(controllerNumber, DEVICE_ADDR, addressSize, clockFreq); this.tsl2561Package = tsl2561Package; initialised = false; autoGain = false; integrationTime = TSL2561_INTEGRATIONTIME_13MS; gain = TSL2561_GAIN_1X; broadband = 0; ir = 0; }
@Override public void close() { device.close(); } }
@Override public String getName() { return DEVICE_NAME + "-" + device.getController() + "-" + device.getAddress(); }
public LPS25H(int controller, int address) { device = new I2CDevice(controller, address, I2CConstants.ADDR_SIZE_7, I2CConstants.DEFAULT_CLOCK_FREQUENCY, ByteOrder.LITTLE_ENDIAN); // Power on, 25Hz output data rate, output registers not updated until both MSB & LSB read device.writeByte(CTRL_REG1, CR1_PD_CONTROL | CR1_ODR_25HZ | CR1_BDU); // Configure the number of pressure and temperature samples device.writeByte(RES_CONF, RC_PRESSURE_32_SAMPLES | RC_TEMP_16_SAMPLES); // Configure the FIFO (mean mode) // TODO Configure number of WTM samples?! device.writeByte(FIFO_CTRL, FC_FIFO_MEAN_MODE); // Enable the FIFO device.writeByte(CTRL_REG2, CR2_FIFO_EN); }
/** * Disables the device (putting it in lower power sleep mode) */ private void disable() throws RuntimeIOException { i2cDevice.writeByte(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF); }
@Override protected byte readByte(int register) { return device.readByte(register); } }
magSensor = new AK8975Driver(i2cDevice.getController(), i2cDevice.getAddressSize(), i2cDevice.getClockFrequency(), compass_addr); magSensor.init(); i2cDevice.writeByte(MPU9150_RA_I2C_MST_CTRL, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV0_ADDR, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV0_REG, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV0_CTRL, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV1_ADDR, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV1_REG, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV1_CTRL, data); i2cDevice.writeByte(MPU9150_RA_I2C_SLV1_DO, data); i2cDevice.writeByte(MPU9150_RA_I2C_MST_DELAY_CTRL, data); i2cDevice.writeByte(MPU9150_RA_YG_OFFS_TC, data);
@Override public float getRelativeHumidity() { byte status = device.readByte(STATUS_REG); if ((status & SR_H_DA) == 0) { Logger.warn("Humidity data not available"); return -1; } // Read raw humidity short humidity_raw = device.readShort(HUMIDITY_OUT | READ); return (h1Rh - h0Rh) * (humidity_raw - h0T0Out) / (h1T0Out - h0T0Out) + h0Rh; }
@Override public float getPressure() { byte status = device.readByte(STATUS_REG); if ((status & SR_P_DA) == 0) { Logger.warn("Pressure data not available"); return -1; } byte[] raw_data = device.readBytes(PRESS_OUT_XL | READ, 3); int raw_pressure = raw_data[2] << 16 | (raw_data[1] & 0xff) << 8 | (raw_data[0] & 0xff); return (float) (raw_pressure / PRESSURE_SCALE); }
/** * Read the MPU interrupt status registers. * @return status Mask of interrupt bits. * @throws RuntimeIOException if an I/O error occurs */ public short mpu_get_int_status() throws RuntimeIOException { if (sensors == 0) { return -1; } // dmp_int_status == 0x39 == MPU9150_RA_DMP_INT_STATUS return i2cDevice.readShort(MPU9150_RA_DMP_INT_STATUS); }
public float[] get_accel_prod_shift() throws RuntimeIOException { byte[] tmp = new byte[4]; tmp = i2cDevice.readBytes(0x0D, 4); //if (i2c_read(st.hw->addr, 0x0D, 4, tmp)) // return 0x07; float[] st_shift = new float[3]; byte[] shift_code = new byte[3]; shift_code[0] = (byte)(((tmp[0] & 0xE0) >> 3) | ((tmp[3] & 0x30) >> 4)); shift_code[1] = (byte)(((tmp[1] & 0xE0) >> 3) | ((tmp[3] & 0x0C) >> 2)); shift_code[2] = (byte)(((tmp[2] & 0xE0) >> 3) | (tmp[3] & 0x03)); for (int ii = 0; ii < 3; ii++) { if (shift_code[ii] == 0) { st_shift[ii] = 0.f; continue; } /* Equivalent to.. * st_shift[ii] = 0.34f * powf(0.92f/0.34f, (shift_code[ii]-1) / 30.f) */ st_shift[ii] = 0.34f; while (--shift_code[ii] != 0) { st_shift[ii] *= 1.034f; } } return st_shift; }
public void init() throws RuntimeIOException { byte[] data = new byte[4]; data[0] = AKM_POWER_DOWN; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); data[0] = AKM_FUSE_ROM_ACCESS; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); /* Get sensitivity adjustment data from fuse ROM. */ data = i2cDevice.readBytes(AKM_REG_ASAX, 3); mag_sens_adj[0] = (short)(data[0] + 128); mag_sens_adj[1] = (short)(data[1] + 128); mag_sens_adj[2] = (short)(data[2] + 128); data[0] = AKM_POWER_DOWN; i2cDevice.writeByte(AKM_REG_CNTL, data[0]); SleepUtil.sleepMillis(1); }
i2cDevice.writeBytes(MPU9150_RA_BANK_SEL, 2, tmp); return i2cDevice.readBytes(MPU9150_RA_MEM_R_W, length);
public void writeBytes(int regAddr, int length, byte[] data, int offset) throws RuntimeIOException { /* * if (I2CDEV_SERIAL_DEBUG) { System.out.format( * "I2C (0x%x) writing %d bytes to 0x%x...%n", devAddr, length, regAddr); } */ byte[] dest = new byte[length]; System.arraycopy(data, offset, dest, 0, length); write(regAddr, SUB_ADDRESS_SIZE_1_BYTE, dest); }
private int readRawTemperature() throws RuntimeIOException { // Write the read temperature command to the command register i2cDevice.writeByte(CONTROL_REGISTER, GET_TEMP_CMD); // Wait 5m before reading the temperature SleepUtil.sleepMillis(5); // Read uncompressed data return i2cDevice.readUShort(TEMP_ADDR, I2CConstants.SUB_ADDRESS_SIZE_1_BYTE); }
public LM73(int controller, Configuration config) { this.config = config; resolution = DEFAULT_RESOLUTION; device = new I2CDevice(controller, config.getAddress()); int id = device.readUShort(ID_REG); if (id != LM73_ID) { Logger.warn("Expected device id 0x{}, got 0x{}", Integer.toHexString(LM73_ID), Integer.toHexString(id)); } }
private void writeBytes(int register, int length, byte[] data) throws RuntimeIOException { device.writeBytes(register, length, data); SleepUtil.sleepMillis(1); }