Class AbstractDeviceFactory

java.lang.Object
com.diozero.internal.spi.AbstractDeviceFactory
All Implemented Interfaces:
DeviceFactoryInterface, Closeable, AutoCloseable
Direct Known Subclasses:
Ads1x15, BaseNativeDeviceFactory, MCP23xxx, McpAdc, PCA9685, PCF8574, PCF8591, PiconZero

public abstract class AbstractDeviceFactory
extends Object
implements DeviceFactoryInterface
Base class for all device factories, including custom board-specific provider implementations (e.g. pigpio) as well as expansion boards (e.g. the MCP 3xxx family of analog-to-digital converters).
  • Field Details

    • deviceStates

      protected DeviceStates deviceStates
    • closed

      protected boolean closed
  • Constructor Details

    • AbstractDeviceFactory

      public AbstractDeviceFactory​(String deviceFactoryPrefix)
  • Method Details

    • createPinKey

      public final String createPinKey​(PinInfo pinInfo)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to generate a unique key for the specified pin. Used for maintaining the state of devices provisioned by this device factory.
      Specified by:
      createPinKey in interface DeviceFactoryInterface
      Parameters:
      pinInfo - the pin to create the key for
      Returns:
      a key that is unique to this pin
    • createI2CKey

      public final String createI2CKey​(int controller, int address)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to generate a unique key for the I2C device at the specified address attached to the specified I2C bus controller.
      Specified by:
      createI2CKey in interface DeviceFactoryInterface
      Parameters:
      controller - the I2C bus controller number
      address - the I2C device address
      Returns:
      a unique I2C key
    • createSpiKey

      public final String createSpiKey​(int controller, int chipSelect)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to generate a unique key for the SPI device attached to the specified SPI controller and chip select.
      Specified by:
      createSpiKey in interface DeviceFactoryInterface
      Parameters:
      controller - the SPI controller number
      chipSelect - the SPI chip select number
      Returns:
      a unique SPI key
    • createSerialKey

      public final String createSerialKey​(String deviceFile)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to generate a unique key for the specified serial device.
      Specified by:
      createSerialKey in interface DeviceFactoryInterface
      Parameters:
      deviceFile - the serial device filename
      Returns:
      a unique serial key
    • close

      public void close()
      Description copied from interface: DeviceFactoryInterface
      Close this device factory including all devices that have been provisioned by it.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface DeviceFactoryInterface
    • reopen

      public void reopen()
      Description copied from interface: DeviceFactoryInterface
      Reopen this device factory.
      Specified by:
      reopen in interface DeviceFactoryInterface
    • isClosed

      public final boolean isClosed()
      Description copied from interface: DeviceFactoryInterface
      Check if this device factory is closed.
      Specified by:
      isClosed in interface DeviceFactoryInterface
      Returns:
      true if this device factory is closed
    • deviceOpened

      public final void deviceOpened​(DeviceInterface device)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to notify the AbstractDeviceFactory that a device has been opened. Enables diozero to perform cleanup operations, for example closing a device factory closes all devices provisionined by that device factory.
      Specified by:
      deviceOpened in interface DeviceFactoryInterface
    • deviceClosed

      public final void deviceClosed​(DeviceInterface device)
      Description copied from interface: DeviceFactoryInterface
      diozero internal method to notify the AbstractDeviceFactory that a device has been closed.
      Specified by:
      deviceClosed in interface DeviceFactoryInterface
    • isDeviceOpened

      public final boolean isDeviceOpened​(String key)
      Description copied from interface: DeviceFactoryInterface
      Check if the device with the given unique key is opened
      Specified by:
      isDeviceOpened in interface DeviceFactoryInterface
      Parameters:
      key - the unique key of the device
      Returns:
      true if the device is opened
    • getDevice

      public final <T extends DeviceInterface> T getDevice​(String key)
      Description copied from interface: DeviceFactoryInterface
      Get the already provisioned device for the specified key
      Specified by:
      getDevice in interface DeviceFactoryInterface
      Parameters:
      key - the unique device key
      Returns:
      the device otherwise null if not found