public class I2CSensor extends BaseSensor implements SensorConstants
Modifier and Type | Field and Description |
---|---|
protected int |
address |
protected static int |
DEFAULT_I2C_ADDRESS |
protected I2CPort |
port |
protected static byte |
REG_PRODUCT_ID
Register number of sensor product ID, as defined by standard Lego I2C register layout.
|
protected static byte |
REG_VENDOR_ID
Register number of sensor vendor ID, as defined by standard Lego I2C register layout.
|
protected static byte |
REG_VERSION
Register number of sensor version string, as defined by standard Lego I2C register layout.
|
protected int |
retryCount |
currentMode, modes
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, BROWN, GREEN, GREEN_INDEX, MAX_TYPE, MIN_TYPE, MODE_RAW, NXT_ADC_RES, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HIGHSPEED, TYPE_HIGHSPEED_9V, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
Constructor and Description |
---|
I2CSensor(I2CPort port) |
I2CSensor(I2CPort port,
int address)
Create the sensor using an already open sensor port.
|
I2CSensor(Port port) |
I2CSensor(Port port,
int address) |
I2CSensor(Port port,
int address,
int type)
Create the sensor using the specified port.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
fetchString(byte reg,
int len)
Read a string from the device.
|
int |
getAddress()
Return the the I2C address of the sensor.
|
void |
getData(int register,
byte[] buf,
int len)
Executes an I2C read transaction and waits for the result.
|
void |
getData(int register,
byte[] buf,
int offset,
int len)
Executes an I2C read transaction and waits for the result.
|
I2CPort |
getPort()
Get the port that the sensor is attached to
|
java.lang.String |
getProductID()
Read the sensor's product identifier.
|
int |
getRetryCount()
Return the current get/send retry count value
|
java.lang.String |
getVendorID()
Read the sensor's vendor identifier.
|
java.lang.String |
getVersion()
Read the sensor's version string.
|
void |
sendData(int register,
byte value)
Executes an I2C write transaction.
|
void |
sendData(int register,
byte[] buf,
int len)
Executes an I2C write transaction.
|
void |
sendData(int register,
byte[] buf,
int offset,
int len)
Executes an I2C write transaction.
|
void |
setAddress(int addr)
Deprecated.
If the device has a changeable address, then constructor of the class should have an address parameter. If not, please report a bug.
|
void |
setRetryCount(int newCount)
Set the number of times that a get/send data request should be retried.
|
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
close, releaseOnClose
protected static final byte REG_VERSION
getVersion()
,
Constant Field Valuesprotected static final byte REG_VENDOR_ID
getVendorID()
,
Constant Field Valuesprotected static final byte REG_PRODUCT_ID
getProductID()
,
Constant Field Valuesprotected static final int DEFAULT_I2C_ADDRESS
protected I2CPort port
protected int address
protected int retryCount
public I2CSensor(I2CPort port, int address)
port
- the open portaddress
- I2C addresspublic I2CSensor(I2CPort port)
public I2CSensor(Port port, int address, int type)
port
- port the sensor is attached toaddress
- I2C addresstype
- type of I2C sensorpublic I2CSensor(Port port)
public I2CSensor(Port port, int address)
public void setRetryCount(int newCount)
newCount
- number of times to try the requestpublic int getRetryCount()
public void getData(int register, byte[] buf, int len)
register
- I2C register, e.g 0x41buf
- Buffer to return datalen
- Length of the return datapublic void getData(int register, byte[] buf, int offset, int len)
register
- I2C register, e.g 0x41buf
- Buffer to return dataoffset
- Offset of the start of the datalen
- Length of the return datapublic void sendData(int register, byte[] buf, int len)
register
- I2C register, e.g 0x42buf
- Buffer containing data to sendlen
- Length of data to sendpublic void sendData(int register, byte[] buf, int offset, int len)
register
- I2C register, e.g 0x42buf
- Buffer containing data to sendoffset
- Offset of the start of the datalen
- Length of data to sendpublic void sendData(int register, byte value)
register
- I2C register, e.g 0x42value
- single byte to sendpublic java.lang.String getVersion()
public java.lang.String getVendorID()
public java.lang.String getProductID()
protected java.lang.String fetchString(byte reg, int len)
reg
- len
- maximum length of the string, including the zero termination byte@Deprecated public void setAddress(int addr)
addr
- 0x02 to 0xfepublic int getAddress()
public I2CPort getPort()