lejos.nxt
Interface I2CPort

All Superinterfaces:
BasicSensorPort, SensorConstants
All Known Implementing Classes:
RemoteSensorPort, SensorPort

public interface I2CPort
extends BasicSensorPort

Abstraction for a port that supports I2C sensors.

Author:
Lawrie Griffiths

Field Summary
static int ALWAYS_ACTIVE
          Keep the i2c driver active between requests
static int ERR_ABORT
          Operation aborted
static int ERR_BUS_BUSY
          Bus is busy
static int ERR_BUSY
          Port is busy
static int ERR_FAULT
          Data error during transaction
static int ERR_INVALID_LENGTH
          Read/Write request too large
static int ERR_INVALID_PORT
          Invalid port number, or port is not enabled
static int HIGH_SPEED
          Use high speed I/O (125KHz)
static int LEGO_MODE
          Use Lego compatible i2c protocol (default)
static int MAX_IO
          Maximum read/write request length
static int NO_RELEASE
          Do not release the i2c bus between requests
static int STANDARD_MODE
          Use standard i2c protocol
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, 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
 
Method Summary
 void i2cDisable()
          Disable the device.
 void i2cEnable(int mode)
          Enable the low level device
 int i2cStatus()
          Check to see the status of the port/device
 int i2cTransaction(int deviceAddress, byte[] writeBuf, int writeOffset, int writeLen, byte[] readBuf, int readOffset, int readLen)
          High level i2c interface.
 
Methods inherited from interface lejos.nxt.BasicSensorPort
getMode, getType, setMode, setType, setTypeAndMode
 

Field Detail

STANDARD_MODE

static final int STANDARD_MODE
Use standard i2c protocol

See Also:
Constant Field Values

LEGO_MODE

static final int LEGO_MODE
Use Lego compatible i2c protocol (default)

See Also:
Constant Field Values

ALWAYS_ACTIVE

static final int ALWAYS_ACTIVE
Keep the i2c driver active between requests

See Also:
Constant Field Values

NO_RELEASE

static final int NO_RELEASE
Do not release the i2c bus between requests

See Also:
Constant Field Values

HIGH_SPEED

static final int HIGH_SPEED
Use high speed I/O (125KHz)

See Also:
Constant Field Values

MAX_IO

static final int MAX_IO
Maximum read/write request length

See Also:
Constant Field Values

ERR_INVALID_PORT

static final int ERR_INVALID_PORT
Invalid port number, or port is not enabled

See Also:
Constant Field Values

ERR_BUSY

static final int ERR_BUSY
Port is busy

See Also:
Constant Field Values

ERR_FAULT

static final int ERR_FAULT
Data error during transaction

See Also:
Constant Field Values

ERR_INVALID_LENGTH

static final int ERR_INVALID_LENGTH
Read/Write request too large

See Also:
Constant Field Values

ERR_BUS_BUSY

static final int ERR_BUS_BUSY
Bus is busy

See Also:
Constant Field Values

ERR_ABORT

static final int ERR_ABORT
Operation aborted

See Also:
Constant Field Values
Method Detail

i2cEnable

void i2cEnable(int mode)
Enable the low level device

Parameters:
mode - One or more of the mode bits above.

i2cDisable

void i2cDisable()
Disable the device.


i2cStatus

int i2cStatus()
Check to see the status of the port/device

Returns:
0 if ready -1: Invalid device -2: Device busy -3: Device fault -4: Buffer size error. -5: Bus is busy

i2cTransaction

int i2cTransaction(int deviceAddress,
                   byte[] writeBuf,
                   int writeOffset,
                   int writeLen,
                   byte[] readBuf,
                   int readOffset,
                   int readLen)
High level i2c interface. Perform a complete i2c transaction and return the results. Writes the specified data to the device and then reads the requested bytes from it. The address is given as an 8 bit value. Bit 0 must be always be zero. Bit 1 to 7 specify the 7 bit i2c address.

Parameters:
deviceAddress - The I2C device address.
writeBuf - The buffer containing data to be written to the device.
writeOffset - The offset of the data within the write buffer
writeLen - The number of bytes to write.
readBuf - The buffer to use for the transaction results
readOffset - Location to write the results to
readLen - The length of the read
Returns:
< 0 error otherwise the number of bytes read