Class ADXL345

java.lang.Object
com.diozero.devices.imu.ADXL345
All Implemented Interfaces:
DeviceInterface, ImuInterface, AutoCloseable

public class ADXL345
extends Object
implements ImuInterface
http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.PDF
  • Constructor Details

    • ADXL345

      public ADXL345()
  • Method Details

    • getTapThreshold

      public float getTapThreshold()
      Get the tap threshold in g
      Returns:
      Tap threshold (g)
    • setTapThreshold

      public void setTapThreshold​(float tapThreshold)
      Set the tap threshold in g
      Parameters:
      tapThreshold - The threshold value in g for tap interrupts
    • getOffsetX

      public float getOffsetX()
    • setOffsetX

      public void setOffsetX​(float offset)
      Set the X-axis offset in g
      Parameters:
      offset - Offset value (g)
    • getOffsetY

      public float getOffsetY()
    • setOffsetY

      public void setOffsetY​(float offset)
      Set the Y-axis offset in g
      Parameters:
      offset - Offset value (g)
    • getOffsetZ

      public float getOffsetZ()
    • setOffsetZ

      public void setOffsetZ​(float offset)
      Set the Z-axis offset in g
      Parameters:
      offset - Offset value (g)
    • getOffsets

      public float[] getOffsets()
    • setOffsets

      public void setOffsets​(float offsetX, float offsetY, float offsetZ)
    • getTapDuration

      public float getTapDuration()
      Get the tap duration in milliseconds
      Returns:
      Tap duration (milliseconds)
    • setTapDuration

      public void setTapDuration​(float tapDuration)
      Set the tap duration in mS
      Parameters:
      tapDuration - The maximum time in ms that an event must be above to qualify as a tap event
    • getTapLatency

      public float getTapLatency()
      Get the tap latency in milliseconds
      Returns:
      The tap latency (milliseconds)
    • setTapLatency

      public void setTapLatency​(float tapLatency)
      Set the tap latency in mS
      Parameters:
      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
    • getTapWindow

      public float getTapWindow()
      Get the tap window in milliseconds
      Returns:
      Tap window (milliseconds)
    • setTapWindow

      public void setTapWindow​(float tapWindow)
      Set the tap window in mS
      Parameters:
      tapWindow - The amount of time in milliseconds after the expiration of the latency time during which a second valid tap can begin
    • getActivityThreshold

      public float getActivityThreshold()
    • setActivityThreshold

      public void setActivityThreshold​(float activityThreshold)
      Set the activity threshold value in g
      Parameters:
      activityThreshold - The threshold value for detecting activity
    • getInactivityThreshold

      public float getInactivityThreshold()
    • setInactivityThreshold

      public void setInactivityThreshold​(float inactivityThreshold)
      Set the inactivity threshold value in g
      Parameters:
      inactivityThreshold - The threshold value for detecting inactivity
    • getInactivityTime

      public float getInactivityTime()
    • setInactivityTime

      public void setInactivityTime​(float inactivityTime)
      Set the inactivity time value in mS
      Parameters:
      inactivityTime - Value representing the amount of time that acceleration must be less than the value in the THRESH_INACT register for inactivity to be declared
    • getActivityInactivityControlFlags

      public byte getActivityInactivityControlFlags()
      D7 - Activity ac/dc D6 - ACT_X enable D5 - ACT_Y enable D4 - ACT_Z enable D3 - Inactivity ac/dc D2 - INACT_X enable D1 - INACT_Y enable D0 - INACT_Z enable A setting of 0 selects dc-coupled operation, and a setting of 1 enables ac-coupled operation. In dc-coupled operation, the current acceleration magnitude is compared directly with THRESH_ACT and THRESH_INACT to determine whether activity or inactivity is detected. In ac-coupled operation for activity detection, the acceleration value at the start of activity detection is taken as a reference value. New samples of acceleration are then compared to this reference value, and if the magnitude of the difference exceeds the THRESH_ACT value, the device triggers an activity interrupt. Similarly, in ac-coupled operation for inactivity detection, a reference value is used for comparison and is updated whenever the device exceeds the inactivity threshold. After the reference value is selected, the device compares the magnitude of the difference between the reference value and the current acceleration with THRESH_INACT. If the difference is less than the value in THRESH_INACT for the time in TIME_INACT, the device is considered inactive and the inactivity interrupt is triggered.
      Returns:
      Activity / inativity control flags
    • setActivityInactivityControlFlags

      public void setActivityInactivityControlFlags​(byte flags)
    • getFreefallThreshold

      public float getFreefallThreshold()
    • setFreefallThreshold

      public void setFreefallThreshold​(float freefallThreshold)
      Set the freefall threshold value in g
      Parameters:
      freefallThreshold - The threshold value for detecting inactivity
    • getFreefallTime

      public float getFreefallTime()
    • setFreefallTime

      public void setFreefallTime​(float freefallTime)
      Set the freefall time value in mS
      Parameters:
      freefallTime - Value representing minimum time that the value of all axes must be less than THRESH_FF to generate a freefall interrupt
    • isDoubleTapSuppressed

      public boolean isDoubleTapSuppressed()
    • setDoubleTapSuppressed

      public void setDoubleTapSuppressed​(boolean doubleTapSuppressed)
    • getTapActivityStatusFlags

      public byte getTapActivityStatusFlags()
    • isLowPowerMode

      public boolean isLowPowerMode()
    • setLowPowerMode

      public void setLowPowerMode​(boolean lowPowerMode)
    • getBandwidthDataRate

      public ADXL345.OutputDataRateType getBandwidthDataRate() throws RuntimeIOException
      Throws:
      RuntimeIOException
    • setBandwidthRate

      public void setBandwidthRate​(ADXL345.OutputDataRateType dataRate) throws RuntimeIOException
      Throws:
      RuntimeIOException
    • setNormalMeasurementMode

      public void setNormalMeasurementMode() throws RuntimeIOException
      Throws:
      RuntimeIOException
    • setPowerControlFlags

      public void setPowerControlFlags​(byte powerControlValue) throws RuntimeIOException
      Throws:
      RuntimeIOException
    • getInterruptEnableFlags

      public byte getInterruptEnableFlags()
    • setInterruptEnableFlags

      public void setInterruptEnableFlags​(byte flags)
    • getInterruptMapFlags

      public byte getInterruptMapFlags()
    • setInterruptMapFlagS

      public void setInterruptMapFlagS​(byte flags)
    • getInterruptSourceFlags

      public byte getInterruptSourceFlags()
    • isFullResolutionMode

      public boolean isFullResolutionMode()
    • setFullResolutionMode

      public void setFullResolutionMode​(boolean fullResolution)
    • isSelfTestMode

      public boolean isSelfTestMode()
    • setSelfTestMode

      public void setSelfTestMode​(boolean selfTest)
    • getAccelFsr

      public int getAccelFsr()
    • setAccelFsr

      public void setAccelFsr​(int range)
    • getFifoControlFlags

      public byte getFifoControlFlags()
      D7 D6 | D5 | D4 D3 D2 D1 D0 FIFO_MODE | Trigger | Samples FIFO modes: 0 Bypass - FIFO is bypassed 1 FIFO - FIFO collects up to 32 values and then stops collecting data, collecting new data only when FIFO is not full 2 Stream - FIFO holds the last 32 data values. When FIFO is full, the oldest data is overwritten with newer data 3 Trigger - When triggered by the trigger bit, FIFO holds the last data samples before the trigger event and then continues to collect data until full. New data is collected only when FIFO is not full Trigger bit: A value of 0 in the trigger bit links the trigger event of trigger mode to INT1, and a value of 1 links the trigger event to INT2 Samples: The function of these bits depends on the FIFO mode selected (see below). Entering a value of 0 in the samples bits immediately sets the watermark status bit in the INT_SOURCE register, regardless of which FIFO mode is selected. Undesirable operation may occur if a value of 0 is used for the samples bits when trigger mode is used FIFO Mode | Samples Bits Function Bypass | None. FIFO | Specifies how many FIFO entries are needed to trigger a watermark interrupt. Stream | Specifies how many FIFO entries are needed to trigger a watermark interrupt. Trigger | Specifies how many FIFO samples are retained in the FIFO buffer before a trigger event.
      Returns:
      FIFO Control flags
    • setFifoControlFlags

      public void setFifoControlFlags​(byte flags)
    • getFifoStatus

      public byte getFifoStatus()
      D7 | D6 | D5 D4 D3 D2 D1 D0 FIFO Trig | 0 | Entries FIFO Trig: A 1 in the FIFO_TRIG bit corresponds to a trigger event occurring, and a 0 means that a FIFO trigger event has not occurred Entries: These bits report how many data values are stored in FIFO. Access to collect the data from FIFO is provided through the DATAX, DATAY, and DATAZ registers. FIFO reads must be done in burst or multiple-byte mode because each FIFO level is cleared after any read (single-or multiple-byte) of FIFO. FIFO stores a maximum of 32 entries, which equates to a maximum of 33 entries available at any given time because an additional entry is available at the output filter of the device.
      Returns:
      FIFO status
    • getImuData

      public ImuData getImuData() throws RuntimeIOException
      Specified by:
      getImuData in interface ImuInterface
      Throws:
      RuntimeIOException
    • getGyroData

      public org.apache.commons.math3.geometry.euclidean.threed.Vector3D getGyroData() throws RuntimeIOException
      Specified by:
      getGyroData in interface ImuInterface
      Throws:
      RuntimeIOException
    • getAccelerometerData

      public org.apache.commons.math3.geometry.euclidean.threed.Vector3D getAccelerometerData() throws RuntimeIOException
      Specified by:
      getAccelerometerData in interface ImuInterface
      Throws:
      RuntimeIOException
    • getCompassData

      public org.apache.commons.math3.geometry.euclidean.threed.Vector3D getCompassData() throws RuntimeIOException
      Specified by:
      getCompassData in interface ImuInterface
      Throws:
      RuntimeIOException
    • hasGyro

      public boolean hasGyro()
      Specified by:
      hasGyro in interface ImuInterface
    • hasAccelerometer

      public boolean hasAccelerometer()
      Specified by:
      hasAccelerometer in interface ImuInterface
    • hasCompass

      public boolean hasCompass()
      Specified by:
      hasCompass in interface ImuInterface
    • addTapListener

      public void addTapListener​(TapListener listener)
      Specified by:
      addTapListener in interface ImuInterface
    • addOrientationListener

      public void addOrientationListener​(OrientationListener listener)
      Specified by:
      addOrientationListener in interface ImuInterface
    • getImuName

      public String getImuName()
      Specified by:
      getImuName in interface ImuInterface
    • getPollInterval

      public int getPollInterval()
      Description copied from interface: ImuInterface
      Get the recommended poll interval in milliseconds
      Specified by:
      getPollInterval in interface ImuInterface
      Returns:
      The poll interval
    • startRead

      public void startRead()
      Specified by:
      startRead in interface ImuInterface
    • stopRead

      public void stopRead()
      Specified by:
      stopRead in interface ImuInterface
    • close

      public void close()
      Description copied from interface: DeviceInterface
      Close this device
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DeviceInterface