com.qualcomm.robotcore.hardware

## Class I2cDeviceImpl

- java.lang.Object
- - com.qualcomm.robotcore.hardware.I2cControllerPortDeviceImpl
  - - com.qualcomm.robotcore.hardware.I2cDeviceImpl

- All Implemented Interfaces:
    HardwareDevice, I2cController.I2cPortReadyCallback, I2cControllerPortDevice, I2cDevice

      public class I2cDeviceImpl
      extends I2cControllerPortDeviceImpl
      implements I2cDevice, HardwareDevice, I2cController.I2cPortReadyCallback

  Control a single I2C Device

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice

      `HardwareDevice.Manufacturer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected I2cController.I2cPortReadyCallback` | `callback`
    `protected java.util.concurrent.atomic.AtomicInteger` | `callbackCount`

    - ### Fields inherited from class com.qualcomm.robotcore.hardware.I2cControllerPortDeviceImpl

      `controller, physicalPort`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I2cDeviceImpl(I2cController controller, int port)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearI2cPortActionFlag()` Clears the flag that `I2cDevice.setI2cPortActionFlag()` sets
    `void` | `close()` Closes this device
    `protected void` | `controllerNowArmedOrPretending()` intended as a subclass hook
    `void` | `copyBufferIntoWriteBuffer(byte[] buffer)` Copy a byte array into the buffer that is set to be written out to the device
    `void` | `deregisterForPortReadyBeginEndCallback()` deregister for port-ready begin and cessation notifications
    `void` | `deregisterForPortReadyCallback()` Unregister for a port-ready callback
    `void` | `enableI2cReadMode(I2cAddr i2cAddr, int memAddress, int length)` Deprecated.
    `void` | `enableI2cWriteMode(I2cAddr i2cAddr, int memAddress, int length)` Deprecated.
    `int` | `getCallbackCount()` Returns the number of callbacks ever experienced by this I2cDevice instance, whether or not they were ever seen by a registered callback.
    `java.lang.String` | `getConnectionInfo()` Get connection information about this device in a human readable format
    `I2cController` | `getController()` returns the I2cController on which this device is found
    `byte[]` | `getCopyOfReadBuffer()` Get a copy of the most recent data read in from the device
    `byte[]` | `getCopyOfWriteBuffer()` Get a copy of the data that is set to be written out to the device
    `java.lang.String` | `getDeviceName()` Returns a string suitable for display to the user as to the type of device.
    `I2cController.I2cPortReadyCallback` | `getI2cPortReadyCallback()` returns the currently registered port-ready callback for this device
    `byte[]` | `getI2cReadCache()` Get direct access to the read cache used by this I2C device
    `java.util.concurrent.locks.Lock` | `getI2cReadCacheLock()` Get access to the read cache lock.
    `TimeWindow` | `getI2cReadCacheTimeWindow()` Returns the time window object into which time stamps are written when the read cache is updated
    `byte[]` | `getI2cWriteCache()` Get direct access to the write cache used by this I2C device
    `java.util.concurrent.locks.Lock` | `getI2cWriteCacheLock()` Get access to the write cache lock.
    `HardwareDevice.Manufacturer` | `getManufacturer()` Returns an indication of the manufacturer of this device.
    `int` | `getMaxI2cWriteLatency()` Returns the maximum interval, in milliseconds, from when the controller receives an I2c write transmission over USB to when that write is actually issued to the I2c device.
    `int` | `getPort()` returns the port number on the controller on which this device is found
    `I2cController.I2cPortReadyBeginEndNotifications` | `getPortReadyBeginEndCallback()` returns the currently registered callback that will receive begin and cessation notifications
    `int` | `getVersion()` Version
    `boolean` | `isArmed()` Returns whether, as of this instant, this I2cDevice is alive and operational in its normally expected mode; that is, whether it is currently in communication with its underlying hardware or whether it is in some other state
    `boolean` | `isI2cPortActionFlagSet()` Check whether or not the action flag is set for this I2C port
    `boolean` | `isI2cPortInReadMode()` Query whether or not the port is in Read mode
    `boolean` | `isI2cPortInWriteMode()` Query whether or not this port is in write mode
    `boolean` | `isI2cPortReady()` Query whether or not this I2c port is ready
    `void` | `portIsReady(int port)`
    `void` | `readI2cCacheFromController()` Trigger a read of the I2C cache
    `void` | `readI2cCacheFromModule()` Deprecated.
    `void` | `registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback callback)` The method used to register for a port-ready callback
    `void` | `registerForPortReadyBeginEndCallback(I2cController.I2cPortReadyBeginEndNotifications callback)` registers for notifications as to when port-ready callbacks begin or cease
    `void` | `resetDeviceConfigurationForOpMode()` Resets the device's configuration to that which is expected at the beginning of an OpMode.
    `void` | `setI2cPortActionFlag()` Set the port action flag; this flag tells the controller to send the current data in its buffer to the I2C device
    `void` | `writeI2cCacheToController()` Trigger a write of the I2C cache
    `void` | `writeI2cCacheToModule()` Deprecated.
    `void` | `writeI2cPortFlagOnlyToController()` Write only the action flag
    `void` | `writeI2cPortFlagOnlyToModule()` Deprecated.

    - ### Methods inherited from class com.qualcomm.robotcore.hardware.I2cControllerPortDeviceImpl

      `controllerNowDisarmed, finishConstruction, getI2cController, onModuleStateChange`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.qualcomm.robotcore.hardware.I2cControllerPortDevice

      `getI2cController`

- - ### Field Detail

    - #### callback

          protected I2cController.I2cPortReadyCallback callback

    - #### callbackCount

          protected java.util.concurrent.atomic.AtomicInteger callbackCount

  - ### Constructor Detail

    - #### I2cDeviceImpl

          public I2cDeviceImpl(I2cController controller,
                               int port)

      Constructor
      Parameters:
        `controller` - I2C controller this channel is attached to
        `port` - port on the I2C controller

  - ### Method Detail

    - #### controllerNowArmedOrPretending

          protected void controllerNowArmedOrPretending()

      Description copied from class: `I2cControllerPortDeviceImpl`
      intended as a subclass hook
      Overrides:
        `controllerNowArmedOrPretending` in class `I2cControllerPortDeviceImpl`

    - #### getController

          public I2cController getController()

      returns the I2cController on which this device is found
      Specified by:
        `getController` in interface `I2cDevice`
      Returns:
        the I2cController on which this device is found

    - #### getPort

          public int getPort()

      returns the port number on the controller on which this device is found
      Specified by:
        `getPort` in interface `I2cControllerPortDevice`
      Overrides:
        `getPort` in class `I2cControllerPortDeviceImpl`
      Returns:
        the port number on the controller on which this device is found

    - #### enableI2cReadMode

          @Deprecated
          public void enableI2cReadMode(I2cAddr i2cAddr,
                                                    int memAddress,
                                                    int length)

      Deprecated.
      Enable read mode for this I2C device
      Specified by:
        `enableI2cReadMode` in interface `I2cDevice`
      Parameters:
        `memAddress` - mem address at which to start reading
        `length` - number of bytes to read
        `i2cAddr` - the address of the device on the I2c bus which should be read
      See Also:
        `I2cDevice.writeI2cCacheToController()`

    - #### enableI2cWriteMode

          @Deprecated
          public void enableI2cWriteMode(I2cAddr i2cAddr,
                                                     int memAddress,
                                                     int length)

      Deprecated.
      Enable write mode for this I2C device
      Specified by:
        `enableI2cWriteMode` in interface `I2cDevice`
      Parameters:
        `memAddress` - mem address at which to start writing
        `length` - number of bytes to write
        `i2cAddr` - the address of the device on the I2c bus which should be written
      See Also:
        `I2cDevice.writeI2cCacheToController()`

    - #### getCopyOfReadBuffer

          public byte[] getCopyOfReadBuffer()

      Get a copy of the most recent data read in from the device
      Specified by:
        `getCopyOfReadBuffer` in interface `I2cDevice`
      Returns:
        a copy of the most recent data read in from the device
      See Also:
        `I2cDevice.getI2cReadCache()`

    - #### getCopyOfWriteBuffer

          public byte[] getCopyOfWriteBuffer()

      Get a copy of the data that is set to be written out to the device
      Specified by:
        `getCopyOfWriteBuffer` in interface `I2cDevice`
      Returns:
        a copy of the data set to be written out to the device
      See Also:
        `I2cDevice.getI2cWriteCache()`

    - #### copyBufferIntoWriteBuffer

          public void copyBufferIntoWriteBuffer(byte[] buffer)

      Copy a byte array into the buffer that is set to be written out to the device
      Specified by:
        `copyBufferIntoWriteBuffer` in interface `I2cDevice`
      Parameters:
        `buffer` - buffer to copy
      See Also:
        `I2cDevice.getI2cWriteCache()`

    - #### setI2cPortActionFlag

          public void setI2cPortActionFlag()

      Set the port action flag; this flag tells the controller to send the current data in its buffer to the I2C device
      Specified by:
        `setI2cPortActionFlag` in interface `I2cDevice`
      See Also:
        `I2cDevice.clearI2cPortActionFlag()`

    - #### clearI2cPortActionFlag

          public void clearI2cPortActionFlag()

      Description copied from interface: `I2cDevice`
      Clears the flag that `I2cDevice.setI2cPortActionFlag()` sets
      Specified by:
        `clearI2cPortActionFlag` in interface `I2cDevice`
      See Also:
        `I2cDevice.setI2cPortActionFlag()`

    - #### isI2cPortActionFlagSet

          public boolean isI2cPortActionFlagSet()

      Check whether or not the action flag is set for this I2C port
      Specified by:
        `isI2cPortActionFlagSet` in interface `I2cDevice`
      Returns:
        a boolean indicating whether or not the flag is set

    - #### readI2cCacheFromController

          public void readI2cCacheFromController()

      Trigger a read of the I2C cache
      Specified by:
        `readI2cCacheFromController` in interface `I2cDevice`

    - #### writeI2cCacheToController

          public void writeI2cCacheToController()

      Trigger a write of the I2C cache
      Specified by:
        `writeI2cCacheToController` in interface `I2cDevice`

    - #### writeI2cPortFlagOnlyToController

          public void writeI2cPortFlagOnlyToController()

      Write only the action flag
      Specified by:
        `writeI2cPortFlagOnlyToController` in interface `I2cDevice`

    - #### isI2cPortInReadMode

          public boolean isI2cPortInReadMode()

      Query whether or not the port is in Read mode
      Specified by:
        `isI2cPortInReadMode` in interface `I2cDevice`
      Returns:
        whether or not this port is in read mode

    - #### isI2cPortInWriteMode

          public boolean isI2cPortInWriteMode()

      Query whether or not this port is in write mode
      Specified by:
        `isI2cPortInWriteMode` in interface `I2cDevice`
      Returns:
        whether or not this port is in write mode

    - #### isI2cPortReady

          public boolean isI2cPortReady()

      Query whether or not this I2c port is ready
      Specified by:
        `isI2cPortReady` in interface `I2cDevice`
      Returns:
        boolean indicating I2c port readiness
      See Also:
        `I2cDeviceSynch`, `I2cDevice.registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback)`

    - #### getI2cReadCacheLock

          public java.util.concurrent.locks.Lock getI2cReadCacheLock()

      Get access to the read cache lock.

      This is needed if you are accessing the read cache directly. The read cache lock needs to be acquired before attempting to interact with the read cache

      Specified by:
        `getI2cReadCacheLock` in interface `I2cDevice`
      Returns:
        the read cache lock

    - #### getI2cWriteCacheLock

          public java.util.concurrent.locks.Lock getI2cWriteCacheLock()

      Get access to the write cache lock.

      This is needed if you ace accessing the write cache directly. The write cache lock needs to be acquired before attempting to interact with the write cache

      Specified by:
        `getI2cWriteCacheLock` in interface `I2cDevice`
      Returns:
        write cache lock

    - #### getI2cReadCache

          public byte[] getI2cReadCache()

      Get direct access to the read cache used by this I2C device

      Please lock the cache before accessing it.

      Specified by:
        `getI2cReadCache` in interface `I2cDevice`
      Returns:
        the read cache
      See Also:
        `I2cDevice.getI2cReadCacheLock()`, `I2cDevice.getCopyOfReadBuffer()`

    - #### getI2cReadCacheTimeWindow

          public TimeWindow getI2cReadCacheTimeWindow()

      Description copied from interface: `I2cDevice`
      Returns the time window object into which time stamps are written when the read cache is updated
      Specified by:
        `getI2cReadCacheTimeWindow` in interface `I2cDevice`
      Returns:
        the time window object into which time stamps are written when the read cache is updated
      See Also:
        `I2cDevice.getI2cReadCache()`

    - #### getI2cWriteCache

          public byte[] getI2cWriteCache()

      Get direct access to the write cache used by this I2C device

      Please lock the cache before accessing it.

      Specified by:
        `getI2cWriteCache` in interface `I2cDevice`
      Returns:
        the write cache
      See Also:
        `I2cDevice.getI2cWriteCacheLock()`, `I2cDevice.getCopyOfWriteBuffer()`

    - #### portIsReady

          public void portIsReady(int port)

      Specified by:
        `portIsReady` in interface `I2cController.I2cPortReadyCallback`

    - #### getMaxI2cWriteLatency

          public int getMaxI2cWriteLatency()

      Description copied from interface: `I2cDevice`
      Returns the maximum interval, in milliseconds, from when the controller receives an I2c write transmission over USB to when that write is actually issued to the I2c device.
      Specified by:
        `getMaxI2cWriteLatency` in interface `I2cDevice`
      Returns:
        the maximum interval, in milliseconds, from when the controller receives an I2c write transmission over USB to when that write is actually issued to the I2c device.

    - #### registerForI2cPortReadyCallback

          public void registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback callback)

      The method used to register for a port-ready callback
      Specified by:
        `registerForI2cPortReadyCallback` in interface `I2cDevice`
      Parameters:
        `callback` - pass in the I2C callback that will be called when the device is ready
      See Also:
        `I2cDevice.getI2cPortReadyCallback()`, `I2cDevice.deregisterForPortReadyCallback()`

    - #### getI2cPortReadyCallback

          public I2cController.I2cPortReadyCallback getI2cPortReadyCallback()

      returns the currently registered port-ready callback for this device
      Specified by:
        `getI2cPortReadyCallback` in interface `I2cDevice`
      Returns:
        the currently registered port-ready callback for this device

    - #### deregisterForPortReadyCallback

          public void deregisterForPortReadyCallback()

      Unregister for a port-ready callback
      Specified by:
        `deregisterForPortReadyCallback` in interface `I2cDevice`
      See Also:
        `I2cDevice.registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback)`

    - #### getCallbackCount

          public int getCallbackCount()

      Description copied from interface: `I2cDevice`
      Returns the number of callbacks ever experienced by this I2cDevice instance, whether or not they were ever seen by a registered callback. This method is mostly useful for debugging and gathering of statistics.
      Specified by:
        `getCallbackCount` in interface `I2cDevice`
      Returns:
        the number of port-is-ready callbacks ever experienced by this `I2cDevice` instance

    - #### registerForPortReadyBeginEndCallback

          public void registerForPortReadyBeginEndCallback(I2cController.I2cPortReadyBeginEndNotifications callback)

      registers for notifications as to when port-ready callbacks begin or cease
      Specified by:
        `registerForPortReadyBeginEndCallback` in interface `I2cDevice`
      Parameters:
        `callback` - the callback which will receive such notifications
      See Also:
        `I2cDevice.getPortReadyBeginEndCallback()`, `I2cDevice.deregisterForPortReadyBeginEndCallback()`

    - #### getPortReadyBeginEndCallback

          public I2cController.I2cPortReadyBeginEndNotifications getPortReadyBeginEndCallback()

      returns the currently registered callback that will receive begin and cessation notifications
      Specified by:
        `getPortReadyBeginEndCallback` in interface `I2cDevice`
      Returns:
        the currently registered callback that will receive begin and cessation notifications
      See Also:
        `I2cDevice.registerForPortReadyBeginEndCallback(I2cController.I2cPortReadyBeginEndNotifications)`

    - #### deregisterForPortReadyBeginEndCallback

          public void deregisterForPortReadyBeginEndCallback()

      deregister for port-ready begin and cessation notifications
      Specified by:
        `deregisterForPortReadyBeginEndCallback` in interface `I2cDevice`
      See Also:
        `I2cDevice.registerForPortReadyBeginEndCallback(I2cController.I2cPortReadyBeginEndNotifications)`

    - #### isArmed

          public boolean isArmed()

      Description copied from interface: `I2cDevice`
      Returns whether, as of this instant, this I2cDevice is alive and operational in its normally expected mode; that is, whether it is currently in communication with its underlying hardware or whether it is in some other state
      Specified by:
        `isArmed` in interface `I2cDevice`
      Returns:
        the arming status of this I2cDevice

    - #### getManufacturer

          public HardwareDevice.Manufacturer getManufacturer()

      Description copied from interface: `HardwareDevice`
      Returns an indication of the manufacturer of this device.
      Specified by:
        `getManufacturer` in interface `HardwareDevice`
      Returns:
        the device's manufacturer

    - #### getDeviceName

          public java.lang.String getDeviceName()

      Description copied from interface: `HardwareDevice`
      Returns a string suitable for display to the user as to the type of device. Note that this is a device-type-specific name; it has nothing to do with the name by which a user might have configured the device in a robot configuration.
      Specified by:
        `getDeviceName` in interface `HardwareDevice`
      Returns:
        device manufacturer and name

    - #### getConnectionInfo

          public java.lang.String getConnectionInfo()

      Description copied from interface: `HardwareDevice`
      Get connection information about this device in a human readable format
      Specified by:
        `getConnectionInfo` in interface `HardwareDevice`
      Returns:
        connection info

    - #### getVersion

          public int getVersion()

      Description copied from interface: `HardwareDevice`
      Version
      Specified by:
        `getVersion` in interface `HardwareDevice`
      Returns:
        get the version of this device

    - #### resetDeviceConfigurationForOpMode

          public void resetDeviceConfigurationForOpMode()

      Description copied from interface: `HardwareDevice`
      Resets the device's configuration to that which is expected at the beginning of an OpMode. For example, motors will reset the their direction to 'forward'.
      Specified by:
        `resetDeviceConfigurationForOpMode` in interface `HardwareDevice`

    - #### close

          public void close()

      Description copied from interface: `HardwareDevice`
      Closes this device
      Specified by:
        `close` in interface `HardwareDevice`

    - #### readI2cCacheFromModule

          @Deprecated
          public void readI2cCacheFromModule()

      Deprecated.
      Deprecated, use readI2cCacheFromController()
      Specified by:
        `readI2cCacheFromModule` in interface `I2cDevice`

    - #### writeI2cCacheToModule

          @Deprecated
          public void writeI2cCacheToModule()

      Deprecated.
      Deprecated, use writeI2cCacheToController()
      Specified by:
        `writeI2cCacheToModule` in interface `I2cDevice`

    - #### writeI2cPortFlagOnlyToModule

          @Deprecated
          public void writeI2cPortFlagOnlyToModule()

      Deprecated.
      Deprecated, use writeI2cPortFlagOnlyToController()
      Specified by:
        `writeI2cPortFlagOnlyToModule` in interface `I2cDevice`