public abstract class AMSColorSensorImpl extends I2cDeviceSynchDeviceWithParameters<I2cDeviceSynchSimple,AMSColorSensor.Parameters> implements AMSColorSensor, I2cAddrConfig, Light
AMSColorSensor.Config, AMSColorSensor.Enable, AMSColorSensor.Gain, AMSColorSensor.LEDDrive, AMSColorSensor.Parameters, AMSColorSensor.Pers, AMSColorSensor.Register, AMSColorSensor.Status, AMSColorSensor.Wait
HardwareDevice.Manufacturer
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TAG |
parameters
deviceClient, deviceClientIsOwned, isInitialized
AMS_COLOR_COMMAND_BIT, AMS_COLOR_COMMAND_TYPE_AUTO_INCREMENT, AMS_COLOR_COMMAND_TYPE_REPEATED_BYTE, AMS_COLOR_COMMAND_TYPE_RESERVED, AMS_COLOR_COMMAND_TYPE_SPECIAL, AMS_TCS34725_ADDRESS, AMS_TCS34725_ID, AMS_TMD37821_ADDRESS, AMS_TMD37821_ID, AMS_TMD37823_ID
Modifier | Constructor and Description |
---|---|
protected |
AMSColorSensorImpl(AMSColorSensor.Parameters params,
I2cDeviceSynchSimple deviceClient,
boolean isOwned) |
Modifier and Type | Method and Description |
---|---|
int |
alpha()
Get the amount of light detected by the sensor as an int.
|
int |
argb()
Get the sensed ARGB color value from the sensor.
|
int |
blue()
Get the Blue values detected by the sensor as an int.
|
protected void |
delay(int ms) |
protected void |
disable() |
protected void |
dumpState() |
protected void |
enable() |
void |
enableLed(boolean enable)
Enable the LED light
|
byte |
getDeviceID()
Returns the flavor of the AMS color sensor as reported by the chip itself
|
java.lang.String |
getDeviceName()
Returns a string suitable for display to the user as to the type of device.
|
I2cAddr |
getI2cAddress()
Get the current I2C Address of this object.
|
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
NormalizedRGBA |
getNormalizedColors()
Reads the colors from the sensor
|
int |
green()
Get the Green values detected by the sensor as an int.
|
protected boolean |
internalInitialize(AMSColorSensor.Parameters parameters)
Actually attempts to carry out initialization with the indicated parameter block.
|
protected boolean |
is3782() |
protected boolean |
isConnectedAndEnabled()
Return whether we know we are enabled and still actively able to talk to the device
|
boolean |
isLightOn()
Answers whether the light is on or off
|
protected int |
normalToUnsignedShort(float normal) |
byte[] |
read(AMSColorSensor.Register reg,
int cb)
Low level: read data starting at the indicated register
|
byte |
read8(AMSColorSensor.Register reg)
Low level: read the byte starting at the indicated register
|
protected byte |
readEnable() |
protected byte |
readEnableAfterWrite() |
protected int |
readUnsignedByte(AMSColorSensor.Register reg) |
protected int |
readUnsignedShort(AMSColorSensor.Register reg,
java.nio.ByteOrder byteOrder) |
int |
red()
In this implementation, the
Color methods return 16 bit unsigned values. |
protected void |
setGain(AMSColorSensor.Gain gain) |
void |
setI2cAddress(I2cAddr i2cAddr)
Set the I2C address to a new value.
|
protected void |
setIntegrationTime(int atime) |
protected void |
setPDrive(AMSColorSensor.LEDDrive ledDrive) |
protected void |
setProximityPulseCount(int proximityPulseCount)
From the TMD3782 datasheet:
"When the proximity detection feature is enabled (PEN), the
state machine transitions through the Prox Accum, Prox Wait,
and Prox ADC states.
|
protected boolean |
testBits(byte value,
AMSColorSensor.Enable desired) |
protected boolean |
testBits(byte value,
AMSColorSensor.Enable mask,
AMSColorSensor.Enable desired) |
protected boolean |
testBits(byte value,
byte desired) |
protected boolean |
testBits(byte value,
byte mask,
byte desired) |
protected void |
updateControl(int mask,
int value) |
void |
write(AMSColorSensor.Register reg,
byte[] data)
Low level: write data starting at the indicated register
|
void |
write8(AMSColorSensor.Register reg,
int data)
Low level: write a byte to the indicated register
|
protected void |
writeEnable(int value) |
doInitialize, getParameters, initialize
close, disengage, engage, getConnectionInfo, getDeviceClient, getVersion, initialize, initializeIfNecessary, onModuleStateChange, registerArmingStateCallback, resetDeviceConfigurationForOpMode
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getParameters, initialize
close, getConnectionInfo, getVersion, resetDeviceConfigurationForOpMode
public static final java.lang.String TAG
protected AMSColorSensorImpl(AMSColorSensor.Parameters params, I2cDeviceSynchSimple deviceClient, boolean isOwned)
protected boolean internalInitialize(AMSColorSensor.Parameters parameters)
I2cDeviceSynchDeviceWithParameters
I2cDeviceSynchDeviceWithParameters.parameters
member variable.internalInitialize
in class I2cDeviceSynchDeviceWithParameters<I2cDeviceSynchSimple,AMSColorSensor.Parameters>
parameters
- the parameter block with which to initializeprotected void dumpState()
protected void enable()
protected void disable()
protected boolean isConnectedAndEnabled()
protected boolean testBits(byte value, byte desired)
protected boolean testBits(byte value, byte mask, byte desired)
protected boolean testBits(byte value, AMSColorSensor.Enable desired)
protected boolean testBits(byte value, AMSColorSensor.Enable mask, AMSColorSensor.Enable desired)
protected void writeEnable(int value)
protected byte readEnable()
protected byte readEnableAfterWrite()
protected void setIntegrationTime(int atime)
protected void setProximityPulseCount(int proximityPulseCount)
protected boolean is3782()
protected void setGain(AMSColorSensor.Gain gain)
protected void setPDrive(AMSColorSensor.LEDDrive ledDrive)
protected void updateControl(int mask, int value)
public byte getDeviceID()
AMSColorSensor
getDeviceID
in interface AMSColorSensor
public int red()
Color
methods return 16 bit unsigned values.red
in interface ColorSensor
public int green()
ColorSensor
green
in interface ColorSensor
public int blue()
ColorSensor
blue
in interface ColorSensor
public int alpha()
ColorSensor
alpha
in interface ColorSensor
protected int normalToUnsignedShort(float normal)
public int argb()
ColorSensor
argb
in interface ColorSensor
public NormalizedRGBA getNormalizedColors()
NormalizedColorSensor
getNormalizedColors
in interface NormalizedColorSensor
public void enableLed(boolean enable)
ColorSensor
enableLed
in interface ColorSensor
enable
- true to enable; false to disablepublic boolean isLightOn()
Light
public I2cAddr getI2cAddress()
ColorSensor
getI2cAddress
in interface ColorSensor
getI2cAddress
in interface I2cAddressableDevice
public void setI2cAddress(I2cAddr i2cAddr)
ColorSensor
setI2cAddress
in interface ColorSensor
setI2cAddress
in interface I2cAddrConfig
i2cAddr
- the new I2C address to usepublic java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
public HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
protected int readUnsignedByte(AMSColorSensor.Register reg)
protected int readUnsignedShort(AMSColorSensor.Register reg, java.nio.ByteOrder byteOrder)
public byte read8(AMSColorSensor.Register reg)
AMSColorSensor
read8
in interface AMSColorSensor
reg
- the location from which to read the datapublic byte[] read(AMSColorSensor.Register reg, int cb)
AMSColorSensor
read
in interface AMSColorSensor
reg
- the location from which to read the datacb
- the number of bytes to readpublic void write8(AMSColorSensor.Register reg, int data)
AMSColorSensor
write8
in interface AMSColorSensor
reg
- the location at which to write the datadata
- the data to writepublic void write(AMSColorSensor.Register reg, byte[] data)
AMSColorSensor
write
in interface AMSColorSensor
protected void delay(int ms)