public class HardwareMap extends java.lang.Object implements java.lang.Iterable<HardwareDevice>
A HardwareMap also contains an associated application context in which it was instantiated.
Through their hardwareMap
, this
provides access to a Context
for OpModes, as such an appropriate instance is needed
by various system APIs.
Modifier and Type | Class and Description |
---|---|
class |
HardwareMap.DeviceMapping<DEVICE_TYPE extends HardwareDevice>
A DeviceMapping contains a subcollection of the devices registered in a
HardwareMap
comprised of all the devices of a particular device type |
Constructor and Description |
---|
HardwareMap(android.content.Context appContext) |
Modifier and Type | Method and Description |
---|---|
<T> T |
get(java.lang.Class<? extends T> classOrInterface,
SerialNumber serialNumber)
(Advanced) Returns the device with the indicated
SerialNumber , if it exists,
cast to the indicated class or interface; otherwise, null. |
<T> T |
get(java.lang.Class<? extends T> classOrInterface,
java.lang.String deviceName)
Retrieves the (first) device with the indicated name which is also an instance of the
indicated class or interface.
|
HardwareDevice |
get(java.lang.String deviceName)
Returns the (first) device with the indicated name.
|
<T> java.util.List<T> |
getAll(java.lang.Class<? extends T> classOrInterface)
Returns all the devices which are instances of the indicated class or interface.
|
java.util.Set<java.lang.String> |
getNamesOf(HardwareDevice device)
Returns all the names by which the device is known.
|
protected void |
internalPut(SerialNumber serialNumber,
java.lang.String deviceName,
HardwareDevice device) |
java.util.Iterator<HardwareDevice> |
iterator()
Returns an iterator of all the devices in the HardwareMap.
|
void |
logDevices() |
void |
put(SerialNumber serialNumber,
java.lang.String deviceName,
HardwareDevice device)
(Advanced) Puts a device in the overall map without having it also reside in a type-specific DeviceMapping.
|
void |
put(java.lang.String deviceName,
HardwareDevice device)
Puts a device in the overall map without having it also reside in a type-specific DeviceMapping.
|
protected void |
rebuildDeviceNamesIfNecessary() |
protected void |
recordDeviceName(java.lang.String deviceName,
HardwareDevice device) |
boolean |
remove(SerialNumber serialNumber,
java.lang.String deviceName,
HardwareDevice device)
(Advanced) Removes a device from the overall map, if present.
|
boolean |
remove(java.lang.String deviceName,
HardwareDevice device)
(Advanced) Removes a device from the overall map, if present.
|
int |
size()
Returns the number of unique device objects currently found in this HardwareMap.
|
<T> T |
tryGet(java.lang.Class<? extends T> classOrInterface,
java.lang.String deviceName)
Retrieves the (first) device with the indicated name which is also an instance of the
indicated class or interface.
|
public HardwareMap.DeviceMapping<DcMotorController> dcMotorController
public HardwareMap.DeviceMapping<DcMotor> dcMotor
public HardwareMap.DeviceMapping<ServoController> servoController
public HardwareMap.DeviceMapping<Servo> servo
public HardwareMap.DeviceMapping<CRServo> crservo
public HardwareMap.DeviceMapping<LegacyModule> legacyModule
public HardwareMap.DeviceMapping<TouchSensorMultiplexer> touchSensorMultiplexer
public HardwareMap.DeviceMapping<DeviceInterfaceModule> deviceInterfaceModule
public HardwareMap.DeviceMapping<AnalogInput> analogInput
public HardwareMap.DeviceMapping<DigitalChannel> digitalChannel
public HardwareMap.DeviceMapping<OpticalDistanceSensor> opticalDistanceSensor
public HardwareMap.DeviceMapping<TouchSensor> touchSensor
public HardwareMap.DeviceMapping<PWMOutput> pwmOutput
public HardwareMap.DeviceMapping<I2cDevice> i2cDevice
public HardwareMap.DeviceMapping<I2cDeviceSynch> i2cDeviceSynch
public HardwareMap.DeviceMapping<AnalogOutput> analogOutput
public HardwareMap.DeviceMapping<ColorSensor> colorSensor
public HardwareMap.DeviceMapping<LED> led
public HardwareMap.DeviceMapping<AccelerationSensor> accelerationSensor
public HardwareMap.DeviceMapping<CompassSensor> compassSensor
public HardwareMap.DeviceMapping<GyroSensor> gyroSensor
public HardwareMap.DeviceMapping<IrSeekerSensor> irSeekerSensor
public HardwareMap.DeviceMapping<LightSensor> lightSensor
public HardwareMap.DeviceMapping<UltrasonicSensor> ultrasonicSensor
public HardwareMap.DeviceMapping<VoltageSensor> voltageSensor
protected java.util.Map<java.lang.String,java.util.List<HardwareDevice>> allDevicesMap
protected java.util.List<HardwareDevice> allDevicesList
protected java.util.Map<HardwareDevice,java.util.Set<java.lang.String>> deviceNames
protected java.util.Map<SerialNumber,HardwareDevice> serialNumberMap
public final java.util.List<HardwareMap.DeviceMapping<? extends HardwareDevice>> allDeviceMappings
public final android.content.Context appContext
protected final java.lang.Object lock
public <T> T get(java.lang.Class<? extends T> classOrInterface, java.lang.String deviceName)
DcMotor motorLeft = hardwareMap.get(DcMotor.class, "motorLeft"); ColorSensor colorSensor = hardwareMap.get(ColorSensor.class, "myColorSensor");
classOrInterface
- the class or interface indicating the type of the device object to be retrieveddeviceName
- the name of the device object to be retrievedget(String)
,
getAll(Class)
,
HardwareMap.DeviceMapping.get(String)
,
tryGet(Class, String)
public <T> T tryGet(java.lang.Class<? extends T> classOrInterface, java.lang.String deviceName)
get(java.lang.Class<? extends T>, java.lang.String)
is the usual method for retreiving items from
the map.get(Class, String)
public <T> T get(java.lang.Class<? extends T> classOrInterface, SerialNumber serialNumber)
SerialNumber
, if it exists,
cast to the indicated class or interface; otherwise, null.public HardwareDevice get(java.lang.String deviceName)
HardwareDevice
,
which is usually not what is desired in user code. Thus, the programmer usually casts the
return type to the target type that the programmer knows the returned value to be:
DcMotor motorLeft = (DcMotor)hardwareMap.get("motorLeft"); ColorSensor colorSensor = (ColorSensor)hardwareMap.get("myColorSensor");
deviceName
- the name of the device object to be retrievedget(Class, String)
,
HardwareMap.DeviceMapping.get(String)
public <T> java.util.List<T> getAll(java.lang.Class<? extends T> classOrInterface)
classOrInterface
- the class or interface indicating the type of the device object to be retrievedget(Class, String)
public void put(java.lang.String deviceName, HardwareDevice device)
deviceName
- the name by which the device is to be known (case sensitive)device
- the device to be stored by that namepublic void put(SerialNumber serialNumber, java.lang.String deviceName, HardwareDevice device)
serialNumber
- the SerialNumber
of the devicedeviceName
- the name by which the device is to be known (case sensitive)device
- the device to be stored by that nameprotected void internalPut(SerialNumber serialNumber, java.lang.String deviceName, HardwareDevice device)
public boolean remove(java.lang.String deviceName, HardwareDevice device)
HardwareMap.DeviceMapping.remove(java.lang.String)
instead of calling this method.
This is normally called only by code in the SDK itself, not by user code.
deviceName
- the name of the device to removedevice
- the device to remove under that namepublic boolean remove(SerialNumber serialNumber, java.lang.String deviceName, HardwareDevice device)
HardwareMap.DeviceMapping.remove(java.lang.String)
instead of calling this method.
This is normally called only by code in the SDK itself, not by user code.
serialNumber
- (optional) the serial number of the devicedeviceName
- the name of the device to removedevice
- the device to remove under that namepublic java.util.Set<java.lang.String> getNamesOf(HardwareDevice device)
device
- the device whose names are desired.protected void recordDeviceName(java.lang.String deviceName, HardwareDevice device)
protected void rebuildDeviceNamesIfNecessary()
public int size()
iterator()
public java.util.Iterator<HardwareDevice> iterator()
iterator
in interface java.lang.Iterable<HardwareDevice>
size()
public void logDevices()