/** * 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 void writeByte(int register, byte value) { device.writeByte(register, value); } }
public void setPowerControlFlags(byte powerControlValue) throws RuntimeIOException { // Enable measure mode device.writeByte(POWER_CTL, powerControlValue); }
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); }
/** * Set the freefall threshold value in g * @param freefallThreshold The threshold value for detecting inactivity */ public void setFreefallThreshold(float freefallThreshold) { if (freefallThreshold < 0 || freefallThreshold > FREEFALL_THRESHOLD_RANGE) { throw new IllegalArgumentException("Illegal freefall threshold value (" + freefallThreshold + "), must be 0.." + FREEFALL_THRESHOLD_RANGE); } device.writeByte(THRESH_FF, (byte)(Math.floor(freefallThreshold / FREEFALL_THRESHOLD_LSB))); }
/** * Set the freefall time value in mS * @param freefallTime Value representing minimum time that the value of all axes * must be less than THRESH_FF to generate a freefall interrupt */ public void setFreefallTime(float freefallTime) { if (freefallTime < 0 || freefallTime > FREEFALL_TIME_RANGE) { throw new IllegalArgumentException("Illegal freefall time value (" + freefallTime + "), must be 0.." + FREEFALL_TIME_RANGE); } device.writeByte(TIME_FF, (byte)(Math.floor(freefallTime / FREEFALL_TIME_LSB))); }
/** * Set the tap duration in mS * @param tapDuration The maximum time in ms that an event must be above to qualify as a tap event */ public void setTapDuration(float tapDuration) { if (tapDuration < 0 || tapDuration > TAP_DURATION_MS_RANGE) { throw new IllegalArgumentException("Illegal tap duration value (" + tapDuration + "), must be 0.." + TAP_DURATION_MS_RANGE); } device.writeByte(TAP_DUR, (byte)(Math.floor(tapDuration / TAP_DURATION_MS_LSB))); }
/** * Set the activity threshold value in g * @param activityThreshold The threshold value for detecting activity */ public void setActivityThreshold(float activityThreshold) { if (activityThreshold < 0 || activityThreshold > ACTIVITY_THRESHOLD_RANGE) { throw new IllegalArgumentException("Illegal activity threshold value (" + activityThreshold + "), must be 0.." + ACTIVITY_THRESHOLD_RANGE); } device.writeByte(THRESH_ACT, (byte)(Math.floor(activityThreshold / ACTIVITY_THRESHOLD_LSB))); }
/** * Set the inactivity threshold value in g * @param inactivityThreshold The threshold value for detecting inactivity */ public void setInactivityThreshold(float inactivityThreshold) { if (inactivityThreshold < 0 || inactivityThreshold > INACTIVITY_THRESHOLD_RANGE) { throw new IllegalArgumentException("Illegal inactivity threshold value (" + inactivityThreshold + "), must be 0.." + INACTIVITY_THRESHOLD_RANGE); } device.writeByte(THRESH_INACT, (byte)(Math.floor(inactivityThreshold / INACTIVITY_THRESHOLD_LSB))); }
private void setOffset(int register, float offset) { if (offset < 0 || offset > OFFSET_RANGE) { throw new IllegalArgumentException("Illegal offset value (" + offset + "), must be 0.." + OFFSET_RANGE); } device.writeByte(register, (byte)(Math.floor(offset / OFFSET_LSB))); }
/** * Set the tap window in mS * @param tapWindow The amount of time in milliseconds after the expiration of the latency time * during which a second valid tap can begin */ public void setTapWindow(float tapWindow) { if (tapWindow < 0 || tapWindow > TAP_WINDOW_MS_RANGE) { throw new IllegalArgumentException("Illegal tap window value (" + tapWindow + "), must be 0.." + TAP_WINDOW_MS_RANGE); } device.writeByte(TAP_WINDOW, (byte)(Math.floor(tapWindow / TAP_WINDOW_MS_LSB))); }
/** * Set the tap latency in mS * @param tapLatency The wait time in mS from the detection of a tap event to the start of the * time window during which a possible second tap event can be detected */ public void setTapLatency(float tapLatency) { if (tapLatency < 0 || tapLatency > TAP_LATENCY_MS_RANGE) { throw new IllegalArgumentException("Illegal tap latency value (" + tapLatency + "), must be 0.." + TAP_LATENCY_MS_RANGE); } device.writeByte(TAP_LATENCY, (byte)(Math.floor(tapLatency / TAP_LATENCY_MS_LSB))); }
public void setAccelFsr(int range) { for (int i : RANGE_LIST) { if (RANGE_LIST[i] == range) { device.writeByte(DATA_FORMAT, i); return; } } throw new IllegalArgumentException("Invalid range value (" + range + "), must be one of " + Arrays.toString(RANGE_LIST)); }
public void setLowPowerMode(boolean lowPowerMode) { byte old_val = device.readByte(BW_RATE); if (lowPowerMode != ((old_val & LOW_POWER_MODE) != 0)) { device.writeByte(BW_RATE, lowPowerMode ? old_val | LOW_POWER_MODE : old_val & ~LOW_POWER_MODE); } }
public void setFullResolutionMode(boolean fullResolution) { byte old_val = device.readByte(DATA_FORMAT); if (fullResolution != ((old_val & FULL_RESOLUTION_MODE) != 0)) { device.writeByte(DATA_FORMAT, fullResolution ? old_val | FULL_RESOLUTION_MODE : old_val & ~SELF_TEST_MODE); } }
private void writeByte(int register, int value) throws RuntimeIOException { for (int i=0; i<MAX_I2C_RETRIES; i++) { try { device.writeByte(register, value); SleepUtil.sleepMillis(1); return; } catch (RuntimeIOException e) { Logger.warn(e, "Retrying I2C call, attempt # {}, error: {}", Integer.valueOf(i+1), e); } } }
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 void setOperatingModes(TemperatureOversampling tempOversampling, PressureOversampling pressOversampling, HumidityOversampling humOversampling, OperatingMode operatingMode) { // Humidity over sampling rate = 1 device.writeByte(CTRL_HUM_REG, humOversampling.getMask()); // Normal mode, temp and pressure oversampling rate = 1 device.writeByte(CTRL_MEAS_REG, (byte) (tempOversampling.getMask() | pressOversampling.getMask() | operatingMode.getMask())); }
void setIntegrationTime(int time) throws RuntimeIOException { // Enable the device by setting the control bit to 0x03 enable(); // Update the timing register i2cDevice.writeByte(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, (byte) (time | gain)); integrationTime = time; // Turn the device off to save power disable(); }
public void setMode(Mode mode) { device.writeByte(mode.getCommand()); SleepUtil.sleepMillis(mode.getMeasurementTimeMs()); this.mode = mode; }