Class I2CConnection

java.lang.Object
me.autobot.lib.hardware.Connection
me.autobot.lib.hardware.i2c.I2CConnection
Direct Known Subclasses:
SensorHubI2CConnection

public class I2CConnection extends Connection
Creates a connection to an I2C device.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default I2C bus to use.
    static int
    Verboseness level for I2C errors.
    protected static final int
    The address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...)
  • Constructor Summary

    Constructors
    Constructor
    Description
    I2CConnection(String id, int bus, int device)
    Creates a new I2C connection with the given bus and device address.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Disable all connections.
    int
    Gets the bus of the I2C device.
    int
    Gets the device address of the I2C device.
    byte[]
    read(int length)
    Reads data from the I2C device.
    void
    write(byte[] data)
    Writes data to the I2C device.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • i2cVerboseLevel

      public static int i2cVerboseLevel
      Verboseness level for I2C errors. 0=none, 1=notify there's an error, 2=print stack trace
    • THIS_DEVICE_ADDRESS

      protected static final int THIS_DEVICE_ADDRESS
      The address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...)
      See Also:
    • default_bus

      public static final int default_bus
      The default I2C bus to use. This is the bus that the I2C device is connected to by default.
      See Also:
  • Constructor Details

    • I2CConnection

      public I2CConnection(String id, int bus, int device)
      Creates a new I2C connection with the given bus and device address.
      Parameters:
      id - The ID of the I2C device. Can be any string. This is used to identify the device in the Pi4J context.
      bus - The bus of the I2C device.
      device - The device of the I2C device.
  • Method Details

    • disableConnections

      public static void disableConnections()
      Disable all connections.
    • write

      public void write(byte[] data)
      Writes data to the I2C device.
      Overrides:
      write in class Connection
      Parameters:
      data - The data to write to the I2C device.
    • read

      public byte[] read(int length)
      Reads data from the I2C device.
      Parameters:
      length - The length of the data to read.
      Returns:
      The data read from the I2C device.
    • getDeviceAddress

      public int getDeviceAddress()
      Gets the device address of the I2C device.
      Returns:
      The device address of the I2C device.
    • getBus

      public int getBus()
      Gets the bus of the I2C device.
      Returns:
      The bus of the I2C device.