public class I2CSensor extends Sensor
Constructor and Description |
---|
I2CSensor(SensorPort port)
Creates a sensor instance of given type connected to the given port
using the default address (0x02) and the default sensor
type (LOWSPEED_9V).
|
I2CSensor(SensorPort port,
int sensorType)
Creates a sensor instance of given type connected to the given port
using the default address (0x02) and the give sensor type.
|
I2CSensor(SensorPort port,
int deviceAddress,
int sensorType)
Creates a sensor instance of given type connected to the given port
the given device address and the given sensor type.
|
Modifier and Type | Method and Description |
---|---|
void |
getData(int register,
byte[] buf,
int len)
Retrieves data from the sensor and waits for the result.
|
void |
getData(int register,
byte[] buf,
int offset,
int len)
Retrieves data from the sensor and waits for the result.
|
lejos.hardware.sensor.I2CSensor |
getLejosI2CSensor()
Returns the reference of the the underlying lejos.hardware.sensor.I2CSensor.
|
java.lang.String |
getProductID()
Returns the product identifier (if available).
|
java.lang.String |
getVersion()
Returns the sensor version number (if available).
|
void |
sendData(int register,
byte value)
Sets a single byte in the I2C sensor.
|
void |
sendData(int register,
byte[] buf,
int len)
Send multiple values with a I2C write transaction.
|
void |
sendData(int register,
byte[] buf,
int offset,
int len)
Send multiple values with a I2C write transaction.
|
getLejosPort
public I2CSensor(SensorPort port)
port
- the port where the sensor is plugged-inpublic I2CSensor(SensorPort port, int sensorType)
port
- the port where the sensor is plugged-insensorType
- the type of the sensorpublic I2CSensor(SensorPort port, int deviceAddress, int sensorType)
port
- the port where the sensor is plugged-indeviceAddress
- in standard Lego/NXT format (range 0x02-0xFE).sensorType
- the type of the sensorpublic void getData(int register, byte[] buf, int len)
register
- the starting register usedbuf
- the buffer where data are returnedlen
- the length of data to read (minimum 1, maximum 16)public void getData(int register, byte[] buf, int offset, int len)
register
- the starting register usedbuf
- the buffer where data are returnedoffset
- offset of the start of the datalen
- the length of data to read (minimum 1, maximum 16)public void sendData(int register, byte value)
register
- the data register in the I2C sensorvalue
- the data sent to the sensorpublic void sendData(int register, byte[] buf, int len)
register
- the starting register in the I2C sensorbuf
- the buffer where data are suppliedlen
- the length the buffer (minimum 1, maximum 16)public void sendData(int register, byte[] buf, int offset, int len)
register
- the starting register in the I2C sensorbuf
- the buffer where data are suppliedlen
- the length the buffer (minimum 1, maximum 16)offset
- offset of the start of the datapublic java.lang.String getProductID()
public java.lang.String getVersion()
public lejos.hardware.sensor.I2CSensor getLejosI2CSensor()