Class TrcI2cDevice

java.lang.Object
trclib.robotcore.TrcI2cDevice

public abstract class TrcI2cDevice extends Object
This class implements a platform independent I2C device. Typically, this class is extended by a platform dependent I2C device class. The platform dependent I2C device class must implement the abstract methods required by this class. The abstract methods allow this class to perform platform independent operations on the I2C device.
  • Field Details

  • Constructor Details

    • TrcI2cDevice

      public TrcI2cDevice(String instanceName)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
  • Method Details

    • isPortReady

      public abstract boolean isPortReady()
      This method checks if the I2C port is ready for bus transaction.
      Returns:
      true if port is ready, false otherwise.
    • isPortInWriteMode

      public abstract boolean isPortInWriteMode()
      This method checks if the I2C port is in write mode.
      Returns:
      true if port is in write mode, false otherwise.
    • sendReadCommand

      public abstract void sendReadCommand(int regAddress, int length)
      This method sends a read command to the device.
      Parameters:
      regAddress - specifies the register address.
      length - specifies the number of bytes to read.
    • sendWriteCommand

      public abstract void sendWriteCommand(int regAddress, int length, byte[] data)
      This method sends a write command to the device.
      Parameters:
      regAddress - specifies the register address.
      length - specifies the number of bytes to write.
      data - specifies the data buffer containing the data to write to the device.
    • getData

      public abstract byte[] getData()
      This method retrieves the data read from the device.
      Returns:
      byte array containing the data read.
    • toString

      public String toString()
      This method returns the instance name of the device.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • setTaskEnabled

      private void setTaskEnabled(boolean enabled)
      This method enables/disables the internal port command state machine and its task.
      Parameters:
      enabled - specifies true to enable the state machine and task, false otherwise.
    • read

      public void read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler, double timeout)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
      handler - specifies the completion handler to call when done. Can be null if none needed.
      timeout - specifies the timeout for the operation in seconds.
    • read

      public void read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
      handler - specifies the completion handler to call when done. Can be null if none needed.
    • read

      public void read(int regAddress, int length)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler, double timeout)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
      handler - specifies the completion handler to call when done. Can be null if none needed.
      timeout - specifies the timeout for the operation in seconds.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
      handler - specifies the completion handler to call when done. Can be null if none needed.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
    • sendByteCommand

      public void sendByteCommand(int regAddress, byte command)
      This method sends a byte command to the device.
      Parameters:
      regAddress - specifies the register address to write to.
      command - specifies the command byte.
    • sendWordCommand

      public void sendWordCommand(int regAddress, short command)
      This method sends a 16-bit command to the device.
      Parameters:
      regAddress - specifies the register address to write to.
      command - specifies the 16-bit command.
    • i2cDeviceTask

      private void i2cDeviceTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This method is called periodically to run the PortCommand state machines.
      Parameters:
      taskType - specifies the type of task being run.
      runMode - specifies the competition mode that is running.
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.