josx.platform.rcx
Class ProximitySensor
java.lang.Object
|
+--josx.platform.rcx.ProximitySensor
- All Implemented Interfaces:
- SensorListener
- public class ProximitySensor
- extends Object
- implements SensorListener
A 'sensor' to detect object proximity. Sends a short
message out of the infra-red port every so often and looks for
the reflection using the light sensor (which happens to be
very infra-red sensitive).
- Author:
- Paul Andrews
Method Summary |
void |
stateChanged(Sensor sensor,
int oldValue,
int newValue)
Called from a thread private to sensor that runs at MAX_PRIORITY
If newValue > oldValue by more than the threshhold, notify anything
wait()ing on the sensor. |
void |
waitTillNear(long millis)
Block the current thread until a near object is detected. |
ProximitySensor
public ProximitySensor(Sensor sensor)
- Constructor. Threshhold defaults to 15.
- Parameters:
sensor
- the sensor to which the light detector is connected.
the constructor will initialize the sensor and set up the infrared
transmitter.
ProximitySensor
public ProximitySensor(Sensor sensor,
int threshhold)
- Constructor.
- Parameters:
sensor
- the sensor to which the light detector is connected.
the constructor will initialize the sensor and set up the infrared
transmitter.threshhold
- the bigger the number the closer we get.
waitTillNear
public void waitTillNear(long millis)
throws InterruptedException
- Block the current thread until a near object is detected.
A user could simply do their own sensor.wait() as that is
all this method does.
- Parameters:
millis
- wait at most millis milliseconds. 0 means wait forever- Throws:
InterruptedException
- if some thread calls interrupt() on the
calling thread.
stateChanged
public void stateChanged(Sensor sensor,
int oldValue,
int newValue)
- Called from a thread private to sensor that runs at MAX_PRIORITY
If newValue > oldValue by more than the threshhold, notify anything
wait()ing on the sensor.
- Specified by:
stateChanged
in interface SensorListener
- Following copied from interface:
josx.platform.rcx.SensorListener
- Parameters:
aSource
- The sensor that generated the event.aOldValue
- The old sensor value.aNewValue
- The new sensor value.