Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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

Constructor Summary
`ProximitySensor(Sensor sensor)` Constructor.
`ProximitySensor(Sensor sensor, int threshhold)` Constructor.

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.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Constructor Detail

### 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.

Method Detail

### 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`
  Parameters:
    `sensor` - The sensor that generated the event.
    `oldValue` - The old sensor value.
    `newValue` - The new sensor value.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD