Package com.pi4j.io.i2c
Class I2CFactory
- java.lang.Object
-
- com.pi4j.io.i2c.I2CFactory
-
public class I2CFactory extends Object
I2C factory - it returns instances ofI2CBus
interface.- Author:
- Robert Savage (http://www .savagehomeautomation.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
I2CFactory.UnsupportedBusNumberException
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_LOCKAQUIRE_TIMEOUT
static TimeUnit
DEFAULT_LOCKAQUIRE_TIMEOUT_UNITS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]
getBusIds()
Fetch all available I2C bus numbers from sysfs.static I2CBus
getInstance(int busNumber)
Create new I2CBus instance.static I2CBus
getInstance(int busNumber, long lockAquireTimeout, TimeUnit lockAquireTimeoutUnit)
Create new I2CBus instance.static void
setFactory(I2CFactoryProvider factoryProvider)
allow changing the provider for the factory
-
-
-
Field Detail
-
DEFAULT_LOCKAQUIRE_TIMEOUT
public static final long DEFAULT_LOCKAQUIRE_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_LOCKAQUIRE_TIMEOUT_UNITS
public static final TimeUnit DEFAULT_LOCKAQUIRE_TIMEOUT_UNITS
-
-
Method Detail
-
getInstance
public static I2CBus getInstance(int busNumber) throws I2CFactory.UnsupportedBusNumberException, IOException
Create new I2CBus instance.The timeout for locking the bus for exclusive communication is set to DEFAULT_LOCKAQUIRE_TIMEOUT.
- Parameters:
busNumber
- The bus number- Returns:
- Return a new I2CBus instance
- Throws:
I2CFactory.UnsupportedBusNumberException
- If the given bus-number is not supported by the underlying systemIOException
- If communication to i2c-bus fails- See Also:
DEFAULT_LOCKAQUIRE_TIMEOUT
,DEFAULT_LOCKAQUIRE_TIMEOUT_UNITS
-
getInstance
public static I2CBus getInstance(int busNumber, long lockAquireTimeout, TimeUnit lockAquireTimeoutUnit) throws I2CFactory.UnsupportedBusNumberException, IOException
Create new I2CBus instance.- Parameters:
busNumber
- The bus numberlockAquireTimeout
- The timeout for locking the bus for exclusive communicationlockAquireTimeoutUnit
- The units of lockAquireTimeout- Returns:
- Return a new I2CBus instance
- Throws:
I2CFactory.UnsupportedBusNumberException
- If the given bus-number is not supported by the underlying systemIOException
- If communication to i2c-bus fails
-
setFactory
public static void setFactory(I2CFactoryProvider factoryProvider)
allow changing the provider for the factory- Parameters:
factoryProvider
-
-
getBusIds
public static int[] getBusIds() throws IOException
Fetch all available I2C bus numbers from sysfs. Returns null, if nothing was found.- Returns:
- Return found I2C bus numbers or null
- Throws:
IOException
- If fetching from sysfs interface fails
-
-