|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.SensorPort.SensorReader lejos.nxt.SensorPort.ColorSensorReader
protected class SensorPort.ColorSensorReader
Lego Color Sensor driver. This driver provides access to the Lego Color sensor. It allows the reading raw and processed color values. The sensor has a tri-color led and this can be set to output red/green/blue or off. It also has a full mode in which four samples are read (off/red/green/blue) very quickly. These samples can then be combined using the calibration data provided by the device to determine the "Lego" color currently being viewed.
Field Summary | |
---|---|
protected static int |
ADMAX
|
protected static int |
ADVOLTS
|
protected int[][] |
calData
|
protected int[] |
calLimits
|
protected static int |
CLOCK
|
protected Colors.Color[] |
colorMap
|
protected static int |
DATA
|
protected boolean |
initialized
|
protected static int |
MINBLANKVAL
|
protected int[] |
rawValues
|
static int |
RGB_BLANK
|
static int |
RGB_BLUE
|
static int |
RGB_GREEN
|
static int |
RGB_RED
Indexes into the output arrays for specific color values. |
protected static int |
SENSORMAX
|
protected int |
type
|
protected int[] |
values
|
Constructor Summary | |
---|---|
SensorPort.ColorSensorReader()
Create a new Color Sensor instance and bind it to a port. |
Method Summary | |
---|---|
protected int |
calcCRC(int crc,
int val)
Incrementally calculate the CRC value of the read data. |
protected void |
calibrate(int[] vals)
This method accepts a set of raw values (in full color mode) and processes them using the calibration data to return standard RGB values between 0 and 255 |
protected boolean |
checkInitialized()
Check to see if a sensor is attached and working, Read the standard sensor analogue pin to see if a the sensor is present. |
protected boolean |
checkPresent()
Check to see if a sensor is attached. |
protected boolean |
checkSensor()
Check the state of an initialized sensor. |
protected boolean |
getData()
get the current digital value from the data pin. |
protected boolean |
initSensor(int mode)
Initialize the sensor and set the operating mode. |
protected void |
initValues()
initialize the raw and processed RGB values |
protected int |
readByte()
Read a data byte from the sensor. |
protected boolean |
readCalibration()
Read the calibration data from the sensor. |
protected int |
readData()
Read the current analogue value from the data pin |
protected int |
readFullColorValue(int newClock)
Read a value from the sensor when in fill color mode. |
int |
readRawValue()
Return a single raw value from the device. |
int |
readRawValues(int[] vals)
When in full color mode this returns all four raw color values from the device by doing four very quick reads and flashing all colors. |
protected boolean |
readSensor()
Read the device |
int |
readValue()
Return a single processed value. |
int |
readValues(int[] vals)
Return a set of calibrated data. |
void |
reset()
Reset the sensor. |
protected void |
resetSensor()
perform a reset of the device. |
protected void |
sendMode(int mode)
Send the new operating mode to the sensor. |
protected void |
setClock(int val)
Set the clock pin to the specified value |
protected void |
setData(int val)
Set the data pin to the specified value |
void |
setType(int type)
Change the type of the sensor |
Methods inherited from class lejos.nxt.SensorPort.SensorReader |
---|
setMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int RGB_RED
public static final int RGB_GREEN
public static final int RGB_BLUE
public static final int RGB_BLANK
protected Colors.Color[] colorMap
protected static final int CLOCK
protected static final int DATA
protected boolean initialized
protected int type
protected static final int ADVOLTS
protected static final int ADMAX
protected static final int MINBLANKVAL
protected static final int SENSORMAX
protected int[][] calData
protected int[] calLimits
protected int[] rawValues
protected int[] values
Constructor Detail |
---|
public SensorPort.ColorSensorReader()
Method Detail |
---|
protected void initValues()
public void setType(int type)
setType
in class SensorPort.SensorReader
type
- new sensor type.public void reset()
reset
in class SensorPort.SensorReader
protected void setClock(int val)
val
- the new value(0/1) for the pin.protected void setData(int val)
val
- new value(0/1) for the pin.protected boolean getData()
protected int readData()
protected void resetSensor()
protected void sendMode(int mode)
mode
- protected int readByte()
protected int calcCRC(int crc, int val)
crc
- current crcval
- new value
protected boolean readCalibration()
protected boolean initSensor(int mode)
mode
- Operating mode.
protected boolean checkPresent()
protected boolean checkInitialized()
protected boolean checkSensor()
protected int readFullColorValue(int newClock)
newClock
- New value for the clock pin
protected boolean readSensor()
public int readRawValue()
readRawValue
in class SensorPort.SensorReader
public int readRawValues(int[] vals)
vals[ColorLightSensor.RGB_BLUE]
readRawValues
in class SensorPort.SensorReader
vals
- array of four color values.
protected void calibrate(int[] vals)
vals
- array to return the newly calibrated data.public int readValues(int[] vals)
vals[ColorLightSensor.RGB_BLUE]
readValues
in class SensorPort.SensorReader
vals
- 4 element array for the results
public int readValue()
readValue
in class SensorPort.SensorReader
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |