Package com.diozero.internal.spi
Class AbstractDeviceFactory
java.lang.Object
com.diozero.internal.spi.AbstractDeviceFactory
- All Implemented Interfaces:
DeviceFactoryInterface
,AutoCloseable
- Direct Known Subclasses:
Ads112C04
,Ads1x15
,BaseNativeDeviceFactory
,MCP23xxx
,McpAdc
,PCA9685
,PCF8574
,PCF8591
,PiconZero
public abstract class AbstractDeviceFactory extends Object implements DeviceFactoryInterface
-
Field Summary
Fields Modifier and Type Field Description protected boolean
closed
protected DeviceStates
deviceStates
-
Constructor Summary
Constructors Constructor Description AbstractDeviceFactory(String deviceFactoryPrefix)
-
Method Summary
Modifier and Type Method Description void
close()
Close this device factory including all devices that have been provisioned by it.String
createI2CKey(int controller, int address)
diozero internal method to generate a unique key for the I2C device at the specified address attached to the specified I2C bus controller.String
createPinKey(PinInfo pinInfo)
diozero internal method to generate a unique key for the specified pin.String
createSerialKey(String deviceFile)
diozero internal method to generate a unique key for the specified serial device.String
createSpiKey(int controller, int chipSelect)
diozero internal method to generate a unique key for the SPI device attached to the specified SPI controller and chip select.void
deviceClosed(InternalDeviceInterface device)
diozero internal method to notify theAbstractDeviceFactory
that a device has been closed.void
deviceOpened(InternalDeviceInterface device)
diozero internal method to notify theAbstractDeviceFactory
that a device has been opened.<T extends InternalDeviceInterface>
TgetDevice(String key)
Get the already provisioned device for the specified keyboolean
isClosed()
Check if this device factory is closed.boolean
isDeviceOpened(String key)
Check if the device with the given unique key is openedvoid
reopen()
Reopen this device factory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
getBoardPinInfo, getName, start
-
Field Details
-
deviceStates
-
closed
protected boolean closed
-
-
Constructor Details
-
AbstractDeviceFactory
-
-
Method Details
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
-
isClosed
public final boolean isClosed()Description copied from interface:DeviceFactoryInterface
Check if this device factory is closed.- Specified by:
isClosed
in interfaceDeviceFactoryInterface
- Returns:
- true if this device factory is closed
-
reopen
public void reopen()Description copied from interface:DeviceFactoryInterface
Reopen this device factory.- Specified by:
reopen
in interfaceDeviceFactoryInterface
-
isDeviceOpened
Description copied from interface:DeviceFactoryInterface
Check if the device with the given unique key is opened- Specified by:
isDeviceOpened
in interfaceDeviceFactoryInterface
- Parameters:
key
- the unique key of the device- Returns:
- true if the device is opened
-
deviceOpened
Description copied from interface:DeviceFactoryInterface
diozero internal method to notify theAbstractDeviceFactory
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 interfaceDeviceFactoryInterface
-
deviceClosed
Description copied from interface:DeviceFactoryInterface
diozero internal method to notify theAbstractDeviceFactory
that a device has been closed.- Specified by:
deviceClosed
in interfaceDeviceFactoryInterface
-
getDevice
Description copied from interface:DeviceFactoryInterface
Get the already provisioned device for the specified key- Specified by:
getDevice
in interfaceDeviceFactoryInterface
- Parameters:
key
- the unique device key- Returns:
- the device otherwise null if not found
-
createPinKey
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 interfaceDeviceFactoryInterface
- Parameters:
pinInfo
- the pin to create the key for- Returns:
- a key that is unique to this pin
-
createI2CKey
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 interfaceDeviceFactoryInterface
- Parameters:
controller
- the I2C bus controller numberaddress
- the I2C device address- Returns:
- a unique I2C key
-
createSpiKey
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 interfaceDeviceFactoryInterface
- Parameters:
controller
- the SPI controller numberchipSelect
- the SPI chip select number- Returns:
- a unique SPI key
-
createSerialKey
Description copied from interface:DeviceFactoryInterface
diozero internal method to generate a unique key for the specified serial device.- Specified by:
createSerialKey
in interfaceDeviceFactoryInterface
- Parameters:
deviceFile
- the serial device filename- Returns:
- a unique serial key
-