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
,OutputShiftRegister
,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
All Methods Instance Methods Concrete Methods 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
createPwmPinKey(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
createServoPinKey(PinInfo pinInfo)
diozero internal method to generate a unique key for the specified pin.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)
Convenience method to get a device of the specified type and key.boolean
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 Detail
-
deviceStates
protected DeviceStates deviceStates
-
closed
protected boolean closed
-
-
Constructor Detail
-
AbstractDeviceFactory
public AbstractDeviceFactory(String deviceFactoryPrefix)
-
-
Method Detail
-
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
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 interfaceDeviceFactoryInterface
- Parameters:
key
- the unique key of the device- Returns:
- true if the device is opened
-
deviceOpened
public final void deviceOpened(InternalDeviceInterface device)
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
- Parameters:
device
- the internal device
-
deviceClosed
public final void deviceClosed(InternalDeviceInterface device)
Description copied from interface:DeviceFactoryInterface
diozero internal method to notify theAbstractDeviceFactory
that a device has been closed.- Specified by:
deviceClosed
in interfaceDeviceFactoryInterface
- Parameters:
device
- the internal device
-
getDevice
public final <T extends InternalDeviceInterface> T getDevice(String key)
Convenience method to get a device of the specified type and key. Consumers must ensure that the return type is correct to prevent class cast exceptions.- Specified by:
getDevice
in interfaceDeviceFactoryInterface
- Type Parameters:
T
- derived device type to return- Parameters:
key
- device key- Returns:
- the device or null if not found
-
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 interfaceDeviceFactoryInterface
- Parameters:
pinInfo
- the pin to create the key for- Returns:
- a key that is unique to this pin
-
createPwmPinKey
public final String createPwmPinKey(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:
createPwmPinKey
in interfaceDeviceFactoryInterface
- Parameters:
pinInfo
- the pin to create the key for- Returns:
- a key that is unique to this pin
-
createServoPinKey
public final String createServoPinKey(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:
createServoPinKey
in interfaceDeviceFactoryInterface
- 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 interfaceDeviceFactoryInterface
- Parameters:
controller
- the I2C bus controller numberaddress
- 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 interfaceDeviceFactoryInterface
- Parameters:
controller
- the SPI controller numberchipSelect
- 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 interfaceDeviceFactoryInterface
- Parameters:
deviceFile
- the serial device filename- Returns:
- a unique serial key
-
-