Package me.autobot.lib.hardware.i2c
Class I2CConnection
java.lang.Object
me.autobot.lib.hardware.Connection
me.autobot.lib.hardware.i2c.I2CConnection
- Direct Known Subclasses:
SensorHubI2CConnection
Creates a connection to an I2C device.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default I2C bus to use.static int
Verboseness level for I2C errors.protected static final int
The address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...) -
Constructor Summary
ConstructorsConstructorDescriptionI2CConnection
(String id, int bus, int device) Creates a new I2C connection with the given bus and device address. -
Method Summary
-
Field Details
-
i2cVerboseLevel
public static int i2cVerboseLevelVerboseness level for I2C errors. 0=none, 1=notify there's an error, 2=print stack trace -
THIS_DEVICE_ADDRESS
protected static final int THIS_DEVICE_ADDRESSThe address of this device, what the signature will be so I2C devices will know to reply to the pi! (I mean they will, but depending on expansion etc it'll be good to have for now...)- See Also:
-
default_bus
public static final int default_busThe default I2C bus to use. This is the bus that the I2C device is connected to by default.- See Also:
-
-
Constructor Details
-
I2CConnection
Creates a new I2C connection with the given bus and device address.- Parameters:
id
- The ID of the I2C device. Can be any string. This is used to identify the device in the Pi4J context.bus
- The bus of the I2C device.device
- The device of the I2C device.
-
-
Method Details
-
disableConnections
public static void disableConnections()Disable all connections. -
write
public void write(byte[] data) Writes data to the I2C device.- Overrides:
write
in classConnection
- Parameters:
data
- The data to write to the I2C device.
-
read
public byte[] read(int length) Reads data from the I2C device.- Parameters:
length
- The length of the data to read.- Returns:
- The data read from the I2C device.
-
getDeviceAddress
public int getDeviceAddress()Gets the device address of the I2C device.- Returns:
- The device address of the I2C device.
-
getBus
public int getBus()Gets the bus of the I2C device.- Returns:
- The bus of the I2C device.
-