|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectlejos.nxt.SensorPort
public class SensorPort
Abstraction for a NXT input port.
| Nested Class Summary | |
|---|---|
protected class |
SensorPort.ColorSensorReader
Lego Color Sensor driver. |
protected class |
SensorPort.SensorReader
The SensorReader class provides a type dependent way to obtain data from a sensor. |
protected class |
SensorPort.StandardReader
|
| Field Summary | |
|---|---|
static int |
NUMBER_OF_PORTS
The number of ports available. |
static SensorPort[] |
PORTS
Deprecated. use getInstance(int) instead. |
static int |
POWER_9V
Power types. |
static int |
POWER_RCX9V
Power types. |
static int |
POWER_STD
Power types. |
static SensorPort |
S1
Port labeled 1 on NXT. |
static SensorPort |
S2
Port labeled 2 on NXT. |
static SensorPort |
S3
Port labeled 3 on NXT. |
static SensorPort |
S4
Port labeled 4 on NXT. |
static int |
SP_ANA
Sensor port analogue input (pin 1 on connector) |
static int |
SP_DIGI0
Sensor port digital I/O 0 (pin 5 on connector) |
static int |
SP_DIGI1
Sensor port digital I/O 1 (pin 6 on connector) |
static int |
SP_MODE_ADC
Sensor port pin mode. |
static int |
SP_MODE_INPUT
Sensor port pin mode. |
static int |
SP_MODE_OFF
Sensor port pin mode. |
static int |
SP_MODE_OUTPUT
Sensor port pin mode. |
| 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 |
| Fields inherited from interface lejos.nxt.I2CPort |
|---|
ALWAYS_ACTIVE, ERR_ABORT, ERR_BUS_BUSY, ERR_BUSY, ERR_FAULT, ERR_INVALID_LENGTH, ERR_INVALID_PORT, HIGH_SPEED, LEGO_MODE, MAX_IO, NO_RELEASE, STANDARD_MODE |
| Method Summary | |
|---|---|
void |
activate()
Activates an RCX sensor. |
void |
addSensorPortListener(SensorPortListener aListener)
Adds a port listener. |
int |
callListeners()
Call Port Listeners. |
void |
enableColorSensor()
Enable the use of the Color Light Sensor on this port. |
int |
getId()
Return the ID of the port. |
static SensorPort |
getInstance(int id)
Return the SensorPort with the given Id. |
int |
getMode()
Returns mode compatible with Lego firmware. |
int |
getSensorPin(int pin)
Read the current state of a sensor port pin |
int |
getType()
Returns type compatible with Lego firmware. |
int |
i2cComplete(byte[] buffer,
int offset,
int numBytes)
Complete an I2C operation and transfer any read bytes |
void |
i2cDisable()
Low-level method to disable I2C on the port. |
void |
i2cEnable(int mode)
Low-level method to enable I2C on the port. |
int |
i2cStart(int address,
byte[] writeBuffer,
int writeOffset,
int writeLen,
int readLen)
Low-level method to start an I2C transaction. |
int |
i2cStatus()
Low-level method to test if I2C connection is busy. |
int |
i2cTransaction(int deviceAddress,
byte[] writeBuf,
int writeOffset,
int writeLen,
byte[] readBuf,
int readOffset,
int readLen)
High level i2c interface. |
void |
i2cWaitIOComplete()
Wait for the current IO operation on the i2c port to complete. |
void |
passivate()
Passivates an RCX sensor. |
boolean |
readBooleanValue()
Reads the boolean value of the sensor. |
int |
readRawValue()
Reads the raw value of the sensor. |
int |
readRawValues(int[] values)
Return a variable number of raw sensor values |
int |
readSensorPin(int pin)
Read the current ADC value from a sensor port pin |
int |
readValue()
Returns value compatible with Lego firmware. |
int |
readValues(int[] values)
Return a variable number of sensor values |
void |
reset()
Reset this port and attempt to reset any attached device. |
void |
setListenerTolerance(int tolerance)
Set the tolerance used when triggering a listener event. |
void |
setMode(int mode)
Sets mode compatible with Lego firmware. |
void |
setPowerType(int type)
Low-level method to set the input power setting for a sensor. |
void |
setSensorPin(int pin,
int val)
Set the output state of a sensor pin |
void |
setSensorPinMode(int pin,
int mode)
Low level method to set the operating mode for a sensor pin. |
void |
setType(int newType)
Sets type compatible with Lego firmware. |
void |
setTypeAndMode(int type,
int mode)
Sets type and mode compatible with Lego firmware. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int POWER_STD
public static final int POWER_RCX9V
public static final int POWER_9V
public static final int SP_DIGI0
public static final int SP_DIGI1
public static final int SP_ANA
public static final int SP_MODE_OFF
public static final int SP_MODE_INPUT
public static final int SP_MODE_OUTPUT
public static final int SP_MODE_ADC
public static final int NUMBER_OF_PORTS
public static final SensorPort S1
public static final SensorPort S2
public static final SensorPort S3
public static final SensorPort S4
@Deprecated public static final SensorPort[] PORTS
getInstance(int) instead.
| Method Detail |
|---|
public static SensorPort getInstance(int id)
id - the Id, between 0 and NUMBER_OF_PORTS-1.
public void enableColorSensor()
public void reset()
public final int getId()
public void addSensorPortListener(SensorPortListener aListener)
NOTE 1: You can add at most 8 listeners.
NOTE 2: Synchronizing inside listener methods could result
in a deadlock.
aListener - Listener for call backsSensorPortListenerpublic void setListenerTolerance(int tolerance)
tolerance - public final void activate()
activate in interface LegacySensorPortpublic final void passivate()
passivate in interface LegacySensorPortpublic int getMode()
getMode in interface BasicSensorPortpublic int getType()
getType in interface BasicSensorPort
public void setTypeAndMode(int type,
int mode)
setTypeAndMode in interface BasicSensorPorttype - the sensor typemode - the sensor modepublic void setType(int newType)
setType in interface BasicSensorPortnewType - the sensor typepublic void setMode(int mode)
setMode in interface BasicSensorPortmode - the mode to set.public final int readRawValue()
readRawValue in interface ADSensorPortpublic int readValue()
readValue in interface ADSensorPortpublic int readValues(int[] values)
values - An array in which to return the sensor values.
public int readRawValues(int[] values)
values - An array in which to return the sensor values.
public final boolean readBooleanValue()
readBooleanValue in interface ADSensorPortpublic void setPowerType(int type)
type - Power type to usepublic int callListeners()
callListeners in interface ListenerCallerpublic void i2cEnable(int mode)
i2cEnable in interface I2CPortmode - The operating mode for the devicepublic void i2cDisable()
i2cDisable in interface I2CPortpublic void i2cWaitIOComplete()
public int i2cStatus()
i2cStatus in interface I2CPort
public int i2cStart(int address,
byte[] writeBuffer,
int writeOffset,
int writeLen,
int readLen)
address - Address of the devicewriteBuffer - Buffer containing bytes to writewriteOffset - Offset into writeBufferwriteLen - number of bytes to writereadLen - number of bytes to read
public int i2cComplete(byte[] buffer,
int offset,
int numBytes)
buffer - Buffer for read dataoffset - offset into the buffernumBytes - Number of bytes to read
public int i2cTransaction(int deviceAddress,
byte[] writeBuf,
int writeOffset,
int writeLen,
byte[] readBuf,
int readOffset,
int readLen)
i2cTransaction in interface I2CPortdeviceAddress - The I2C device address.writeBuf - The buffer containing data to be written to the device.writeOffset - The offset of the data within the write bufferwriteLen - The number of bytes to write.readBuf - The buffer to use for the transaction resultsreadOffset - Location to write the results toreadLen - The length of the read
public void setSensorPinMode(int pin,
int mode)
pin - The pin idmode - The new mode
public void setSensorPin(int pin,
int val)
pin - The pin idval - The new output value (0/1)public int getSensorPin(int pin)
pin - The pin id.
public int readSensorPin(int pin)
pin - The id of the pin to read (SP_DIGI1/SP_ANA)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||