Package lejos.robotics.objectdetection
Class FeatureDetectorAdapter
- java.lang.Object
-
- lejos.robotics.objectdetection.FeatureDetectorAdapter
-
- All Implemented Interfaces:
FeatureDetector
- Direct Known Subclasses:
RangeFeatureDetector,TouchFeatureDetector
public abstract class FeatureDetectorAdapter extends java.lang.Object implements FeatureDetector
An adapter to make it easier to implement FeatureDetector classes. The scan() method is the only method which must be implemented by the actual class.- Author:
- BB
-
-
Constructor Summary
Constructors Constructor Description FeatureDetectorAdapter(int delay)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(FeatureListener l)Adds a listener to the FeatureDetector.voidenableDetection(boolean enable)Enable or disable detection of objects.intgetDelay()The minimum delay between notification of readings from the feature detector.booleanisEnabled()Indicates if automatic scanning mode and listener notification is currently enabled.protected voidnotifyListeners(Feature feature)abstract Featurescan()Performs a single scan for an object and returns the results.voidsetDelay(int delay)Sets the minimum delay between readings from the feature detector.
-
-
-
Method Detail
-
addListener
public void addListener(FeatureListener l)
Description copied from interface:FeatureDetectorAdds a listener to the FeatureDetector. The FeatureListener will be notified when objects are detected.- Specified by:
addListenerin interfaceFeatureDetector- Parameters:
l- The FeatureListener that is notified every time a feature is detected.
-
enableDetection
public void enableDetection(boolean enable)
Description copied from interface:FeatureDetectorEnable or disable detection of objects.- Specified by:
enableDetectionin interfaceFeatureDetector- Parameters:
enable- true enables detection and notifications, false disables this class until it is enabled again.
-
isEnabled
public boolean isEnabled()
Description copied from interface:FeatureDetectorIndicates if automatic scanning mode and listener notification is currently enabled. (true by default)- Specified by:
isEnabledin interfaceFeatureDetector- Returns:
- true if enabled, false if not
-
getDelay
public int getDelay()
Description copied from interface:FeatureDetectorThe minimum delay between notification of readings from the feature detector. If no objects are detected, no notification will occur. Some sensors, such as touch sensors, check the sensor more frequently than other sensors, such as range sensors.- Specified by:
getDelayin interfaceFeatureDetector- Returns:
- The delay between sensor readings.
-
setDelay
public void setDelay(int delay)
Description copied from interface:FeatureDetectorSets the minimum delay between readings from the feature detector. The notification thread will notify FeatureListener objects every delay milliseconds, unless it takes longer to retrieve readings from the sensor.- Specified by:
setDelayin interfaceFeatureDetector- Parameters:
delay- The FeatureDetector will return one new set of readings every delay milliseconds.
-
notifyListeners
protected void notifyListeners(Feature feature)
-
scan
public abstract Feature scan()
Description copied from interface:FeatureDetectorPerforms a single scan for an object and returns the results. If an object is not detected, this method returns null.
Warning: Make sure to check for a null object before trying to read data from the returned Feature object, otherwise your code will throw a null pointer exception.
- Specified by:
scanin interfaceFeatureDetector- Returns:
- A feature it has detected. null if nothing found.
-
-