lejos.nxt.remote
Class RemoteSensorPort

java.lang.Object
  extended by lejos.nxt.remote.RemoteSensorPort
All Implemented Interfaces:
ADSensorPort, BasicSensorPort, I2CPort, NXTProtocol, SensorConstants

public class RemoteSensorPort
extends Object
implements NXTProtocol, ADSensorPort, I2CPort

Emulates a Sensor Port using LCP


Field Summary
 
Fields inherited from interface lejos.nxt.remote.NXTProtocol
ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_DEFRAG, NXJ_DISCONNECT, NXJ_FIND_FIRST, NXJ_FIND_NEXT, NXJ_PACKET_MODE, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TRANSITIONCNTMODE, WRITE
 
Fields inherited from interface lejos.nxt.I2CPort
ALWAYS_ACTIVE, LEGO_MODE, STANDARD_MODE
 
Fields inherited from interface lejos.nxt.SensorConstants
MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, TYPE_ANGLE, TYPE_CUSTOM, 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
 
Constructor Summary
RemoteSensorPort(NXTCommand nxtCommand, int id)
           
 
Method Summary
 int getId()
          Get the port number
 int getMode()
          Get the sensor mode
 NXTCommand getNXTCommand()
          Get the NXTCommand object used for remote access
 int getType()
          Get the sensor type
 int i2cBusy()
          Test if I2C is busy
 int i2cComplete(byte[] buffer, int numBytes)
          Complete the i2c transaction, and read any returned data.
 void i2cDisable()
          Disable I2C on the port - null for remote ports
 void i2cEnable(int mode)
          Enable I2C on the port - null for remote ports
 int i2cStart(int address, int internalAddress, int numInternalBytes, byte[] buffer, int numBytes, int transferType)
          Start an I2C transaction.
 boolean readBooleanValue()
          Reads the boolean value of the sensor.
 int readRawValue()
          Reads the raw value of the sensor.
 int readValue()
          Returns value compatible with Lego firmware.
 void setMode(int mode)
          Set the sensor mode
 void setType(int type)
          Set the sensor type
 void setTypeAndMode(int type, int mode)
          Set the sensor type and mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteSensorPort

public RemoteSensorPort(NXTCommand nxtCommand,
                        int id)
Method Detail

getId

public int getId()
Get the port number

Returns:
the port number

getType

public int getType()
Get the sensor type

Specified by:
getType in interface BasicSensorPort
Returns:
the sensor type

getMode

public int getMode()
Get the sensor mode

Specified by:
getMode in interface BasicSensorPort
Returns:
the sensor mode

setTypeAndMode

public void setTypeAndMode(int type,
                           int mode)
Set the sensor type and mode

Specified by:
setTypeAndMode in interface BasicSensorPort
Parameters:
type - the sensor type
mode - the sensor mode

setType

public void setType(int type)
Set the sensor type

Specified by:
setType in interface BasicSensorPort
Parameters:
type - the sensor type

setMode

public void setMode(int mode)
Set the sensor mode

Specified by:
setMode in interface BasicSensorPort
Parameters:
mode - the sensor mode

readBooleanValue

public boolean readBooleanValue()
Reads the boolean value of the sensor.

Specified by:
readBooleanValue in interface ADSensorPort
Returns:
Boolean value of sensor.

readRawValue

public int readRawValue()
Reads the raw value of the sensor.

Specified by:
readRawValue in interface ADSensorPort
Returns:
Raw sensor value. Range is device dependent.

readValue

public int readValue()
Returns value compatible with Lego firmware.

Specified by:
readValue in interface ADSensorPort

getNXTCommand

public NXTCommand getNXTCommand()
Get the NXTCommand object used for remote access

Returns:
the NXTCommand object

i2cBusy

public int i2cBusy()
Test if I2C is busy

Specified by:
i2cBusy in interface I2CPort
Returns:
the status value (see ErrorMessages)

i2cDisable

public void i2cDisable()
Disable I2C on the port - null for remote ports

Specified by:
i2cDisable in interface I2CPort

i2cEnable

public void i2cEnable(int mode)
Enable I2C on the port - null for remote ports

Specified by:
i2cEnable in interface I2CPort
Parameters:
mode - One or more of the mode bits above.

i2cStart

public int i2cStart(int address,
                    int internalAddress,
                    int numInternalBytes,
                    byte[] buffer,
                    int numBytes,
                    int transferType)
Start an I2C transaction. The remote implementation is synchronous.

Specified by:
i2cStart in interface I2CPort
Parameters:
address - the I2C address (x01 - x7F)
internalAddress - the register or internal address
numInternalBytes - not used
buffer - the buffer for reading or writing data
numBytes - the number of bytes to read or write
transferType - 0 for read, 1 for write
Returns:
the status value

i2cComplete

public int i2cComplete(byte[] buffer,
                       int numBytes)
Description copied from interface: I2CPort
Complete the i2c transaction, and read any returned data.

Specified by:
i2cComplete in interface I2CPort
Parameters:
buffer - The buffer for a read (null for write)
numBytes - Number of bytes to transfer
Returns:
>= 0 number of bytes returned -1: Invalid device -2: Device busy -3: I2C error -4: Buffer size error.