|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlejos.nxt.I2CSensor
public class I2CSensor
A sensor wrapper to allow easy access to I2C sensors, like the ultrasonic sensor. This version of this class supports remote execution of I2C.
Field Summary | |
---|---|
protected byte |
address
|
protected static java.lang.String |
BLANK
|
protected static byte |
PRODUCT_ID
Returns the product ID of the sensor. |
protected static byte |
SENSOR_TYPE
Returns the sensor type. |
protected static byte |
STOP
|
protected static byte |
VERSION
Returns the version number of the sensor. |
Constructor Summary | |
---|---|
I2CSensor(I2CPort s)
|
|
I2CSensor(I2CPort s,
byte sensorType)
|
Method Summary | |
---|---|
protected java.lang.String |
fetchString(int constantEnumeration,
int rxLength)
Helper method for retrieving string constants using I2C protocol. |
int |
getData(int register)
Helper method to return a single register byte. |
int |
getData(int register,
byte[] buf,
int length)
Method for retrieving data values from the sensor. |
int |
getId()
|
java.lang.String |
getProductID()
Returns the Product ID as a string. |
java.lang.String |
getSensorType()
Returns the type of sensor as a string. |
java.lang.String |
getVersion()
Returns the version number of the sensor hardware. |
int |
sendData(int register,
byte value)
Sets a single byte in the I2C sensor. |
int |
sendData(int register,
byte[] data,
int length)
Send data top the sensor |
void |
setAddress(int addr)
Set the address of the port Note that addresses are from 0x01 to 0x7F not even numbers from 0x02 to 0xFE as given in some I2C device specifications. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected byte address
protected static byte STOP
protected static java.lang.String BLANK
protected static byte VERSION
protected static byte PRODUCT_ID
protected static byte SENSOR_TYPE
Constructor Detail |
---|
public I2CSensor(I2CPort s, byte sensorType)
s
- A sensor. e.g. Port.S1public I2CSensor(I2CPort s)
Method Detail |
---|
public int getId()
public int getData(int register, byte[] buf, int length)
register
- e.g. FACTORY_SCALE_DIVISOR, BYTE0, etc....length
- Length of data to read (minimum 1, maximum 16)
public int getData(int register)
register
-
public int sendData(int register, byte value)
register
- A data register in the I2C sensor. e.g. ACTUAL_ZEROvalue
- The data value.public int sendData(int register, byte[] data, int length)
register
- A data register in the I2C sensor.data
- The byte to send.length
- the number of bytespublic java.lang.String getVersion()
public java.lang.String getProductID()
public java.lang.String getSensorType()
protected java.lang.String fetchString(int constantEnumeration, int rxLength)
constantEnumeration
- e.g. I2CProtocol.VERSIONrxLength
-
public void setAddress(int addr)
addr
- 1 to 0x7F
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |