|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.aplu.nxt.Part
ch.aplu.nxt.Sensor
ch.aplu.nxt.I2CSensor
public class I2CSensor
A sensor wrapper to allow easy access to I2C sensors, like the ultrasonic sensor. Most of the code and the documentation taken from the leJOS library (lejos.sourceforge.net, with thanks to the autor.
Field Summary |
---|
Constructor Summary | |
---|---|
I2CSensor(SensorPort port,
byte sensorType)
Creates a sensor instance of given type connected to the given port with default device address 0x02. |
|
I2CSensor(SensorPort port,
byte sensorType,
int deviceAddress)
Creates a sensor instance of given type connected to the given port using the given I2C device address (default address is 0x02). |
Method Summary | |
---|---|
int |
getData(int register,
byte[] buf,
int len)
Retrieves data from the sensor. |
lejos.nxt.I2CSensor |
getLejosI2CSensor()
Returns the reference of the the underlying lejos.nxt.I2CSensor. |
lejos.nxt.SensorPort |
getLejosPort()
Returns the reference of the the underlying lejos.nxt.SensorPort. |
java.lang.String |
getProductID()
Returns the product identifier (if available). |
java.lang.String |
getVersion()
Returns the sensor version number (if available). |
int |
sendData(int register,
byte value)
Sets a single byte in the I2C sensor. |
int |
sendData(int register,
byte[] buf,
int len)
Send multiple values with a I2C write transaction. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public I2CSensor(SensorPort port, byte sensorType, int deviceAddress)
port
- the port where the sensor is plugged-insensorType
- the type of the sensordeviceAddress
- in standard Lego/NXT format (range 0x02-0xFE).
The low bit must always be zero.
Some data sheets (and older versions of leJOS) may use i2c 7 bit format
(0x01-0x7F) in which case this address must be shifted left one bit.public I2CSensor(SensorPort port, byte sensorType)
port
- the port where the sensor is plugged-insensorType
- the type of the sensorMethod Detail |
---|
public int 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 int sendData(int register, byte value)
register
- the data register in the I2C sensorvalue
- the data sent to the sensor
public int 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 java.lang.String getProductID()
public java.lang.String getVersion()
public lejos.nxt.I2CSensor getLejosI2CSensor()
public lejos.nxt.SensorPort getLejosPort()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |