|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.I2CSensor
public class I2CSensor
Abstract class that implements common methods for all I2C sensors. Extend this class to implement new I2C sensors.
Field Summary | |
---|---|
protected static byte |
PRODUCT_ID
Returns the product ID of the sensor. |
protected static byte |
SENSOR_TYPE
Returns the sensor type. |
protected static byte |
VERSION
Returns the version number of the sensor. |
Constructor Summary | |
---|---|
I2CSensor(I2CPort port)
|
|
I2CSensor(I2CPort port,
int mode)
|
Method Summary | |
---|---|
protected String |
fetchString(int register,
int len)
Internal helper function, read a string from the device |
int |
getData(int register,
byte[] buf,
int len)
Executes an I2C read transaction and waits for the result. |
I2CPort |
getPort()
Get the port that the sensor is attached to |
String |
getProductID()
Return the sensor product identifier. |
String |
getSensorType()
Return the sensor type. |
String |
getVersion()
Return the sensor version number. |
int |
sendData(int register,
byte value)
Executes an I2C write transaction. |
int |
sendData(int register,
byte[] buf,
int len)
Executes an I2C write transaction. |
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 static byte VERSION
protected static byte PRODUCT_ID
protected static byte SENSOR_TYPE
Constructor Detail |
---|
public I2CSensor(I2CPort port, int mode)
public I2CSensor(I2CPort port)
Method Detail |
---|
public int getData(int register, byte[] buf, int len)
register
- I2C register, e.g 0x41buf
- Buffer to return datalen
- Length of the return data
public int sendData(int register, byte[] buf, int len)
register
- I2C register, e.g 0x42buf
- Buffer containing data to sendlen
- Length of data to send
public int sendData(int register, byte value)
register
- I2C register, e.g 0x42value
- single byte to send
public String getVersion()
public String getProductID()
public String getSensorType()
protected String fetchString(int register, int len)
register
- len
- The length of the space padded reply.
public void setAddress(int addr)
addr
- 1 to 0x7Fpublic I2CPort getPort()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |