public class ModernRoboticsI2cColorSensor extends I2cDeviceSynchDevice<I2cDeviceSynch> implements ColorSensor, NormalizedColorSensor, SwitchableLight, I2cAddrConfig
ModernRoboticsI2cColorSensor
provides support for the Modern Robotics Color Sensor.Modifier and Type | Class and Description |
---|---|
static class |
ModernRoboticsI2cColorSensor.Command |
static class |
ModernRoboticsI2cColorSensor.Register |
HardwareDevice.Manufacturer
Modifier and Type | Field and Description |
---|---|
static I2cAddr |
ADDRESS_I2C_DEFAULT |
protected float |
colorNormalizationFactor
In
NormalizedColorSensor we report the 16-bit sensor-normalized values, not the
8 bit colors reported through ColorSensor . |
protected boolean |
isLightOn |
deviceClient, deviceClientIsOwned, isInitialized
Constructor and Description |
---|
ModernRoboticsI2cColorSensor(I2cDeviceSynch deviceClient) |
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 boolean |
doInitialize()
Actually carries out the initialization of the instance.
|
void |
enableLed(boolean enable)
Enable the LED light
|
void |
enableLight(boolean enable)
Turns the light on or off.
|
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.
|
boolean |
isLightOn()
Answers whether the light is on or off
|
byte |
read8(ModernRoboticsI2cColorSensor.Register reg) |
int |
readUnsignedByte(ModernRoboticsI2cColorSensor.Register register) |
int |
readUnsignedShort(ModernRoboticsI2cColorSensor.Register register) |
int |
red()
Get the Red values detected by the sensor as an int.
|
void |
setI2cAddress(I2cAddr newAddress)
Set the I2C address to a new value.
|
java.lang.String |
toString() |
void |
write8(ModernRoboticsI2cColorSensor.Register reg,
byte value) |
void |
writeCommand(ModernRoboticsI2cColorSensor.Command command) |
close, disengage, engage, getConnectionInfo, getDeviceClient, getVersion, initialize, initializeIfNecessary, onModuleStateChange, registerArmingStateCallback, resetDeviceConfigurationForOpMode
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, getConnectionInfo, getVersion, resetDeviceConfigurationForOpMode
public static final I2cAddr ADDRESS_I2C_DEFAULT
protected final float colorNormalizationFactor
NormalizedColorSensor
we report the 16-bit sensor-normalized values, not the
8 bit colors reported through ColorSensor
.protected boolean isLightOn
public ModernRoboticsI2cColorSensor(I2cDeviceSynch deviceClient)
protected boolean doInitialize()
I2cDeviceSynchDevice
doInitialize
in class I2cDeviceSynchDevice<I2cDeviceSynch>
public HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
public java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
public byte read8(ModernRoboticsI2cColorSensor.Register reg)
public void write8(ModernRoboticsI2cColorSensor.Register reg, byte value)
public int readUnsignedByte(ModernRoboticsI2cColorSensor.Register register)
public int readUnsignedShort(ModernRoboticsI2cColorSensor.Register register)
public void writeCommand(ModernRoboticsI2cColorSensor.Command command)
public java.lang.String toString()
toString
in class java.lang.Object
public int red()
ColorSensor
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
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 void enableLight(boolean enable)
SwitchableLight
enableLight
in interface SwitchableLight
enable
- if true, the light turns on; otherwise the light turns offpublic boolean isLightOn()
Light
public void setI2cAddress(I2cAddr newAddress)
ColorSensor
setI2cAddress
in interface ColorSensor
setI2cAddress
in interface I2cAddrConfig
newAddress
- the new I2C address to usepublic I2cAddr getI2cAddress()
ColorSensor
getI2cAddress
in interface ColorSensor
getI2cAddress
in interface I2cAddressableDevice