SunSPOT API V6.0


com.sun.spot.sensorboard.peripheral
Class LightSensor

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

public class LightSensor
extends ScalarInput
implements ILightSensor, ILightSensor, IMeasurementInfo

Simple extension of ScalarInput.

Author:
arshan & Ron Goldman

Field Summary
 
Fields inherited from class com.sun.spot.sensorboard.io.ScalarInput
index, myController, range, thIsolates, thListeners
 
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.
 SensorEvent createSensorEvent()
          Create a SensorEvent of the appropriate type for this sensor.
 double getAccuracy()
          Returns the accuracy of the sensor (in the current measurement range) as a percentage of reading (=data value).
 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.
 double getMaxValue()
          Returns the current maximum value of the sensor (in the current measurement range).
 double getMinValue()
          Returns the current minimum value of the sensor (in the current measurement range).
 double getResolution()
          Returns the resolution of the range (in the current measurement range).
 void removeILightSensorThresholdListener(ILightSensorThresholdListener who)
          Removes the specified light sensor threshold listener so that it no longer receives callbacks from this light sensor.
 void saveEventState(SensorEvent evt)
          Save the current sensor state in the specified event.
 
Methods inherited from class com.sun.spot.sensorboard.io.ScalarInput
addIADT7411ThresholdListener, addIScalarInputThresholdListener, areThresholdEventsEnabled, enableThresholdEvents, getDescription, getHighThreshold, getIADT7411ThresholdListeners, getIndex, getIScalarInputThresholdListeners, getLowThreshold, getMaxSamplingRate, getRange, getValue, getVoltage, removeIADT7411ThresholdListener, removeIScalarInputThresholdListener, setThresholds, supportsThresholdEvents, thresholdChanged, thresholdExceeded, toString
 
Methods inherited from class com.sun.spot.resources.Resource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, 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
 
Methods inherited from interface com.sun.spot.resources.transducers.ITransducer
getDescription, getMaxSamplingRate
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from interface com.sun.spot.resources.transducers.ILightSensor
getValue
 
Methods inherited from interface com.sun.spot.resources.transducers.ITransducer
getDescription, getMaxSamplingRate
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

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.

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.

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.

Returns:
all of this light sensor's ILightSensorThresholdListener or an empty array if no light sensor threshold listeners are currently registered.

getMinValue

public double getMinValue()
Returns the current minimum value of the sensor (in the current measurement range).

Specified by:
getMinValue in interface IMeasurementInfo
Overrides:
getMinValue in class ScalarInput
Returns:
the min value of the sensor

getMaxValue

public double getMaxValue()
Returns the current maximum value of the sensor (in the current measurement range).

Specified by:
getMaxValue in interface IMeasurementInfo
Overrides:
getMaxValue in class ScalarInput
Returns:
the max value of the sensor

getResolution

public double getResolution()
Returns the resolution of the range (in the current measurement range). The resolution is the minimum amount of change in the input of a sensor that can be detected as a change in the output. Resolution is a property of the transducer of a sensor but the input and output ranges and word length of the A/D converter usually set the limitations for the resolution of a digital sensor.

Specified by:
getResolution in interface IMeasurementInfo
Overrides:
getResolution in class ScalarInput
Returns:
resolution of the sensor

getAccuracy

public double getAccuracy()
Returns the accuracy of the sensor (in the current measurement range) as a percentage of reading (=data value). Because this accuracy value describes the relative measurement error, greater values indicate a less accurate sensor. The accuracy value is within: 0 ≤ accuracy < 1

Specified by:
getAccuracy in interface IMeasurementInfo
Overrides:
getAccuracy in class ScalarInput
Returns:
the accuracy of the sensor. If the accuracy is not known, a value of -1 is returned.

createSensorEvent

public SensorEvent createSensorEvent()
Description copied from interface: ITransducer
Create a SensorEvent of the appropriate type for this sensor.

Specified by:
createSensorEvent in interface ITransducer
Overrides:
createSensorEvent in class ScalarInput
Returns:
a SensorEvent of the appropriate type for this sensor.

saveEventState

public void saveEventState(SensorEvent evt)
Description copied from interface: ITransducer
Save the current sensor state in the specified event.

Specified by:
saveEventState in interface ITransducer
Overrides:
saveEventState in class ScalarInput
Parameters:
evt - the event to store the sensor state in

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.