Class LinuxFsI2CBus

java.lang.Object
com.pi4j.io.i2c.I2CBusBase
com.pi4j.plugin.linuxfs.provider.i2c.LinuxFsI2CBus
All Implemented Interfaces:
I2CBus

public class LinuxFsI2CBus extends I2CBusBase
Implementation of an I2C bus using Linux file system access.
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
      Logger for the class
    • file

      protected LinuxFile file
      File handle for this I2C bus
  • Constructor Details

    • LinuxFsI2CBus

      public LinuxFsI2CBus(I2CConfig config)
      Constructs a new LinuxFsI2CBus.
      Parameters:
      config - the I2C configuration
      Throws:
      Pi4JException - if the bus cannot be initialized due to missing sysfs or devfs paths
  • Method Details

    • execute

      public <R> R execute(I2C i2c, Callable<R> action)
      Executes a callable action with the specified I2C device.
      Type Parameters:
      R - the result type of the action
      Parameters:
      i2c - the I2C device
      action - the action to perform
      Returns:
      the result of the action
      Throws:
      Pi4JException - if the action fails
    • execute

      public <R> R execute(I2C i2c, CheckedFunction<LinuxFile, R> action)
      Executes an action that interacts with the underlying file handle.
      Type Parameters:
      R - the result type of the action
      Parameters:
      i2c - the I2C device
      action - the action to perform
      Returns:
      the result of the action
      Throws:
      Pi4JException - if the action fails
    • executeIOCTL

      public void executeIOCTL(I2C i2c, long command, ByteBuffer data, IntBuffer offsets)
      Executes an ioctl command on the I2C device.
      Parameters:
      i2c - the I2C device
      command - the ioctl command
      data - the data buffer for the command
      offsets - the offsets buffer
      Throws:
      Pi4JException - if the ioctl command fails
    • selectBusSlave

      protected void selectBusSlave(I2C i2c) throws IOException
      Selects the slave device on the I2C bus, if not already selected.
      Parameters:
      i2c - the I2C device to select
      Throws:
      IOException - if selecting the device fails
    • close

      public void close()
      Closes the file handle for the I2C bus.