SunSPOT API V3.0


com.sun.spot.sensorboard.peripheral
Class LightSensor

java.lang.Object
  extended by com.sun.spot.sensorboard.io.ScalarInput
      extended by com.sun.spot.sensorboard.peripheral.LightSensor
All Implemented Interfaces:
IScalarInput, ILightSensor

public class LightSensor
extends ScalarInput
implements ILightSensor

Simple extension of ScalarInput.

Author:
arshan & Ron Goldman

Field Summary
 
Fields inherited from class com.sun.spot.sensorboard.io.ScalarInput
index, myController, range
 
Constructor Summary
LightSensor(PinDescriptor pidx, int r, IADCController cntrl)
          Creates a new instance of LightSensor
 
Method Summary
 void addILightSensorThresholdListener(ILightSensorThresholdListener who)
          Adds the specified light sensor threshold listener to receive callbacks from this light sensor.
 int getAverageValue()
          Take 17 readings, one every 1 msec and average them.
 int getAverageValue(int n)
          To deal with light sources that change rapidly over time, such as fluorescent light bulbs, it is necessary to take multiple readings and average them.
 ILightSensorThresholdListener[] getILightSensorThresholdListeners()
          Returns an array of all the light sensor threshold listeners registered on this light sensor.
 void removeILightSensorThresholdListener(ILightSensorThresholdListener who)
          Removes the specified light sensor threshold listener so that it no longer receives callbacks from this light sensor.
 void thresholdChanged(int low, int high)
          Called by pin's IADCController when pin threshold values are exceeded.
 void thresholdExceeded(int val)
          Callback from EDemoBoard interrupt handler for threshold event.
 
Methods inherited from class com.sun.spot.sensorboard.io.ScalarInput
addIScalarInputThresholdListener, areThresholdEventsEnabled, enableThresholdEvents, getHighThreshold, getIndex, getIScalarInputThresholdListeners, getLowThreshold, getRange, getValue, getVoltage, removeIScalarInputThresholdListener, setThresholds, supportsThresholdEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.sensorboard.io.IScalarInput
addIScalarInputThresholdListener, areThresholdEventsEnabled, enableThresholdEvents, getHighThreshold, getIndex, getIScalarInputThresholdListeners, getLowThreshold, getRange, getValue, removeIScalarInputThresholdListener, setThresholds, supportsThresholdEvents
 

Constructor Detail

LightSensor

public LightSensor(PinDescriptor pidx,
                   int r,
                   IADCController cntrl)
Creates a new instance of LightSensor

Parameters:
pidx - PinDescriptor that the lightsensor is connected to
r - Range of the mask for the above pin
cntrl - the ADC controller to use
Method Detail

getAverageValue

public int getAverageValue(int n)
                    throws IOException
To deal with light sources that change rapidly over time, such as fluorescent light bulbs, it is necessary to take multiple readings and average them. This method sleeps for 1 millisecond between readings. At least one reading is always taken, even if n <= 0.

Specified by:
getAverageValue in interface ILightSensor
Parameters:
n - the number of readings to take.
Returns:
the averaged light intensity.
Throws:
IOException

getAverageValue

public int getAverageValue()
                    throws IOException
Take 17 readings, one every 1 msec and average them. Equivalent to getAverageValue(17);

Specified by:
getAverageValue in interface ILightSensor
Returns:
the averaged light intensity.
Throws:
IOException

addILightSensorThresholdListener

public void addILightSensorThresholdListener(ILightSensorThresholdListener who)
Adds the specified light sensor threshold listener to receive callbacks from this light sensor. Callbacks occur when the light sensor reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value.

Specified by:
addILightSensorThresholdListener in interface ILightSensor
Parameters:
who - the light sensor threshold listener to add.

removeILightSensorThresholdListener

public void removeILightSensorThresholdListener(ILightSensorThresholdListener who)
Removes the specified light sensor threshold listener so that it no longer receives callbacks from this light sensor. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this light sensor.

Specified by:
removeILightSensorThresholdListener in interface ILightSensor
Parameters:
who - the light sensor threshold listener to remove.

getILightSensorThresholdListeners

public ILightSensorThresholdListener[] getILightSensorThresholdListeners()
Returns an array of all the light sensor threshold listeners registered on this light sensor.

Specified by:
getILightSensorThresholdListeners in interface ILightSensor
Returns:
all of this light sensor's ILightSensorThresholdListener or an empty array if no light sensor threshold listeners are currently registered.

thresholdChanged

public void thresholdChanged(int low,
                             int high)
Called by pin's IADCController when pin threshold values are exceeded. Spawns threads to notify any registered IScalarInputThresholdListener.

Overrides:
thresholdChanged in class ScalarInput
Parameters:
low - the new low threshold value.
high - the new high threshold value.

thresholdExceeded

public void thresholdExceeded(int val)
Callback from EDemoBoard interrupt handler for threshold event. Spawns threads to notify any registered ILightSensorThresholdListener.

Overrides:
thresholdExceeded in class ScalarInput
Parameters:
val - light sensor value taken after event triggered

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.