icommand.nxt
Class I2CSensor

java.lang.Object
  extended by icommand.nxt.I2CSensor
Direct Known Subclasses:
ColorSensor, CompassSensor, RCXLink, RCXMotorMultiplexer, TiltSensor, UltrasonicSensor

public class I2CSensor
extends java.lang.Object

A sensor wrapper to allow easy access to I2C sensors, like the ultrasonic sensor. Currently uses the default I2C address of 0x02, but some sensors can be connected to same port lines and use different addresses using the Auto Detecting Parallel Architecture (ADPA). Currently unsure if there are commercial port expanders yet to use this function, or whether the Lego UltrasonicSensor sensor is ADPA compatible.

Author:
BB

Field Summary
protected static byte DEFAULT_ADDRESS
           
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(SensorPort s, byte sensorType)
           
 
Method Summary
protected  java.lang.String fetchString(byte constantEnumeration, int rxLength)
          Helper method for retrieving string cosntants using I2C protocol.
protected  byte getData(byte register)
          Helper method to return a single register byte.
protected  byte[] getData(byte register, 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.
protected  void sendData(byte register, byte value)
          Sets a single byte in the I2C sensor.
protected  void sendData(byte register, byte value1, byte value2)
          EXPERIMENTAL for RCXLink.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ADDRESS

protected static byte DEFAULT_ADDRESS

STOP

protected static byte STOP

VERSION

protected static byte VERSION
Returns the version number of the sensor. e.g. "V1.0" Reply length = 8.


PRODUCT_ID

protected static byte PRODUCT_ID
Returns the product ID of the sensor. e.g. "LEGO" Reply length = 8.


SENSOR_TYPE

protected static byte SENSOR_TYPE
Returns the sensor type. e.g. "Sonar" Reply length = 8.

Constructor Detail

I2CSensor

public I2CSensor(SensorPort s,
                 byte sensorType)
Parameters:
s - A sensor. e.g. Port.S1
Method Detail

getId

public int getId()

getData

protected byte[] getData(byte register,
                         int length)
Method for retrieving data values from the sensor. BYTE0 (icommand.nxtcomm.I2CProtocol) is usually the primary data value for the sensor. Data is read from registers in the sensor, usually starting at 0x00 and ending around 0x49. Just supply the register to start reading at, and the length of bytes to read (16 maximum). NOTE: The NXT supplies UBYTE (unsigned byte) values but Java converts them into signed bytes (probably more practical to return short/int?)

Parameters:
register - e.g. FACTORY_SCALE_DIVISOR, BYTE0, etc....
length - Length of data to read (minimum 1, maximum 16)
Returns:

getData

protected byte getData(byte register)
Helper method to return a single register byte.

Parameters:
register -
Returns:

sendData

protected void sendData(byte register,
                        byte value)
Sets a single byte in the I2C sensor.

Parameters:
register - A data register in the I2C sensor. e.g. ACTUAL_ZERO
value - The data value.

sendData

protected void sendData(byte register,
                        byte value1,
                        byte value2)
EXPERIMENTAL for RCXLink. Sets two bytes in the I2C sensor.

Parameters:
register - A data register in the I2C sensor. e.g. ACTUAL_ZERO
value - The data value.

getVersion

public java.lang.String getVersion()
Returns the version number of the sensor hardware. NOTE: A little unreliable at the moment due to a bug in firmware. Keep trying if it doesn't get it the first time.

Returns:
The version number. e.g. "V1.0"

getProductID

public java.lang.String getProductID()
Returns the Product ID as a string. NOTE: A little unreliable at the moment due to a bug in firmware. Keep trying if it doesn't get it the first time.

Returns:
The product ID. e.g. "LEGO"

getSensorType

public java.lang.String getSensorType()
Returns the type of sensor as a string. NOTE: A little unreliable at the moment due to a bug in firmware. Keep trying if it doesn't get it the first time.

Returns:
The sensor type. e.g. "Sonar"

fetchString

protected java.lang.String fetchString(byte constantEnumeration,
                                       int rxLength)
Helper method for retrieving string cosntants using I2C protocol.

Parameters:
constantEnumeration - e.g. I2CProtocol.VERSION
Returns:


Copyright 2006. All Rights Reserved.