ukcrobots.simplecore
Class Sensor

java.lang.Object
  |
  +--ukcrobots.simplecore.Sensor
Direct Known Subclasses:
LightSensor, RotationSensor, TouchSensor

public abstract class Sensor
extends Object

A delegating wrapper around the InputDevice class. All methods delegate to the associated device. Multiple sensors may be connected to the same device, if required. However, there are drawbacks to this approach and the most sensible configuration would involve sensors of the same type. This class is based on josx.platform.rcx.Sensor.

Version:
2001.12.20

Constructor Summary
Sensor(int id, int type, int mode)
          Sets the sensor's mode and type.
 
Method Summary
 void activate()
          Activates the sensor.
protected  ukcrobots.simplecore.InputDevice getDevice()
          Obtain access to the attached InputDevice in order to provide enhanced functionality via a sub class.
 void passivate()
          Passivates the sensor.
 int readValue()
          Reads the canonical value of the sensor.
 int readValueAsInt()
          Implementation of Listenable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

Sensor

public Sensor(int id,
              int type,
              int mode)
       throws NoSuchDeviceException
Sets the sensor's mode and type.

Parameters:
type - 0 = RAW, 1 = TOUCH, 2 = TEMP, 3 = LIGHT, 4 = ROT.
mode - 0x00 = RAW, 0x20 = BOOL, 0x40 = EDGE, 0x60 = PULSE, 0x80 = PERCENT, 0xA0 = DEGC, 0xC0 = DEGF, 0xE0 = ANGLE. Also, mode can be OR'd with slope (0..31).
See Also:
SensorConstants
Method Detail

readValue

public int readValue()
Reads the canonical value of the sensor.


readValueAsInt

public int readValueAsInt()
Implementation of Listenable.

Returns:
The current canonical value of the sensor.

activate

public void activate()
Activates the sensor. This method should be called if you want to get accurate values from the sensor. In the case of light sensors, you should see the led go on when you call this method.

Note that the sensor must be activatved if a listener is to receive notifications.


passivate

public final void passivate()
Passivates the sensor.


getDevice

protected ukcrobots.simplecore.InputDevice getDevice()
Obtain access to the attached InputDevice in order to provide enhanced functionality via a sub class.

Returns:
The associated InputDevice.