SunSPOT API V6.0


com.sun.spot.sensorboard.peripheral
Class TemperatureInput

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.TemperatureInput
All Implemented Interfaces:
IResource, IMeasurementInfo, ITemperatureInput, ITransducer, IScalarInput

public class TemperatureInput
extends ScalarInput
implements ITemperatureInput, ITemperatureInput, IMeasurementInfo

Simple temperature sensor.

Author:
Ron Goldman

Field Summary
protected  Hashtable thIsolates
           
protected  Vector thListeners
           
 
Fields inherited from class com.sun.spot.sensorboard.io.ScalarInput
index, myController, range
 
Fields inherited from interface com.sun.spot.sensorboard.peripheral.ITemperatureInput
CELSIUS, FAHRENHEIT
 
Constructor Summary
TemperatureInput(PinDescriptor pidx, int r, IADCController cntrl)
          Creates a new instance of TemperatureInput
 
Method Summary
 void addIADT7411TemperatureInputThresholdListener(IADT7411TemperatureInputThresholdListener who)
          Add an ILIS3L02AQAccelerometerThresholdListener to the list of callbacks.
 void addITemperatureInputThresholdListener(ITemperatureInputThresholdListener who)
          Adds the specified temperature sensor threshold listener to receive callbacks from this temperature sensor.
 double convert(double val, boolean toCelsius)
          Deprecated. use convertF2C() & convertC2F instead
 double convertC2F(double val)
          Convert from Celsius to Fahrenheit.
 double convertF2C(double val)
          Convert from Fahrenheit to Celsius.
 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).
 double getCelsius()
          Return the current temperature in degrees Celsius.
 String getDescription()
          This method returns a readable description of the sensor.
 double getFahrenheit()
          Return the current temperature in degrees Fahrenheit.
 double getHighThreshold(boolean toCelsius)
          Return the current high threshold value.
 IADT7411TemperatureInputThresholdListener[] getIADT7411TemperatureInputThresholdListeners()
          Return all of the IADT7411ThresholdListener callbacks.
 ITemperatureInputThresholdListener[] getITemperatureInputThresholdListeners()
          Returns an array of all the temperature sensor threshold listeners registered on this temperature sensor.
 double getLowThreshold(boolean toCelsius)
          Return the current low threshold value.
 double getMaxSamplingRate()
          Return the maximum sampling rate per second for this 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 removeIADT7411TemperatureInputThresholdListener(IADT7411TemperatureInputThresholdListener who)
          Remove an IADT7411ThresholdListener from the list of callbacks.
 void removeITemperatureInputThresholdListener(ITemperatureInputThresholdListener who)
          Removes the specified temperature sensor threshold listener so that it no longer receives callbacks from this temperature sensor.
 void saveEventState(SensorEvent evt)
          Save the current sensor state in the specified event.
 void setThresholds(double low, double high, boolean inCelsius)
          Set the low and high threshold values for this temperature sensor.
 void thresholdChanged(int low, int high)
          Called by pin's IADCController when pin threshold values are changed.
 void thresholdExceeded(int val)
          Callback from EDemoBoard interrupt handler for threshold event.
 
Methods inherited from class com.sun.spot.sensorboard.io.ScalarInput
addIADT7411ThresholdListener, addIScalarInputThresholdListener, areThresholdEventsEnabled, enableThresholdEvents, getHighThreshold, getIADT7411ThresholdListeners, getIndex, getIScalarInputThresholdListeners, getLowThreshold, getRange, getValue, getVoltage, removeIADT7411ThresholdListener, removeIScalarInputThresholdListener, setThresholds, supportsThresholdEvents, 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.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Field Detail

thListeners

protected Vector thListeners

thIsolates

protected Hashtable thIsolates
Constructor Detail

TemperatureInput

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

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

convertC2F

public double convertC2F(double val)
Convert from Celsius to Fahrenheit.

Specified by:
convertC2F in interface ITemperatureInput
Parameters:
val - Celsius value to convert
Returns:
the input value converted to Fahrenheit

convertF2C

public double convertF2C(double val)
Convert from Fahrenheit to Celsius.

Specified by:
convertF2C in interface ITemperatureInput
Parameters:
val - Fahrenheit value to convert
Returns:
the input value converted to Celsius

convert

public double convert(double val,
                      boolean toCelsius)
Deprecated. use convertF2C() & convertC2F instead

Convert between Celsius and Fahrenheit.

Parameters:
val - value to convert
toCelsius - if true convert value from Fahrenheit to Celsius, if false convert value from Celsius to Fahrenheit
Returns:
the input value converted to Celsius or Fahrenheit

getCelsius

public double getCelsius()
                  throws IOException
Return the current temperature in degrees Celsius.

Specified by:
getCelsius in interface ITemperatureInput
Returns:
the current temperature in degrees Celsius
Throws:
IOException

getFahrenheit

public double getFahrenheit()
                     throws IOException
Return the current temperature in degrees Fahrenheit.

Specified by:
getFahrenheit in interface ITemperatureInput
Returns:
the current temperature in degrees Fahrenheit
Throws:
IOException

setThresholds

public void setThresholds(double low,
                          double high,
                          boolean inCelsius)
Set the low and high threshold values for this temperature sensor. Callbacks occur when the temperature reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value. Note: all listeners are notified of the new threshold values.

Parameters:
low - the new low threshold value
high - the new high threshold value
inCelsius - true if the new thresholds are in degrees Celsius

thresholdChanged

public void thresholdChanged(int low,
                             int high)
Called by pin's IADCController when pin threshold values are changed. 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.

getLowThreshold

public double getLowThreshold(boolean toCelsius)
Return the current low threshold value.

Parameters:
toCelsius - if true report the low threshold in degrees Celsius
Returns:
the current low threshold value.

getHighThreshold

public double getHighThreshold(boolean toCelsius)
Return the current high threshold value.

Parameters:
toCelsius - if true report the high threshold in degrees Celsius
Returns:
the current high threshold value.

addIADT7411TemperatureInputThresholdListener

public void addIADT7411TemperatureInputThresholdListener(IADT7411TemperatureInputThresholdListener who)
Add an ILIS3L02AQAccelerometerThresholdListener to the list of callbacks.

Parameters:
who - the ILIS3L02AQAccelerometerThresholdListener to add

removeIADT7411TemperatureInputThresholdListener

public void removeIADT7411TemperatureInputThresholdListener(IADT7411TemperatureInputThresholdListener who)
Remove an IADT7411ThresholdListener from the list of callbacks.

Parameters:
who - the IADT7411ThresholdListener to remove

getIADT7411TemperatureInputThresholdListeners

public IADT7411TemperatureInputThresholdListener[] getIADT7411TemperatureInputThresholdListeners()
Return all of the IADT7411ThresholdListener callbacks.

Returns:
an array of the IADT7411ThresholdListener callbacks

addITemperatureInputThresholdListener

public void addITemperatureInputThresholdListener(ITemperatureInputThresholdListener who)
Adds the specified temperature sensor threshold listener to receive callbacks from this temperature sensor. Callbacks occur when the temperature 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 temperature sensor threshold listener to add.

removeITemperatureInputThresholdListener

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

Parameters:
who - the temperature sensor threshold listener to remove.

getITemperatureInputThresholdListeners

public ITemperatureInputThresholdListener[] getITemperatureInputThresholdListeners()
Returns an array of all the temperature sensor threshold listeners registered on this temperature sensor.

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

thresholdExceeded

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

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

getDescription

public String getDescription()
Description copied from interface: ITransducer
This method returns a readable description of the sensor. The description should tell the essentials of the sensor, including at least the sensor type (accelerometer, microphone, thermometer). The returned string MUST not be null or an empty string.

Specified by:
getDescription in interface ITransducer
Overrides:
getDescription in class ScalarInput
Returns:
the description of the sensor

getMaxSamplingRate

public double getMaxSamplingRate()
Description copied from interface: ITransducer
Return the maximum sampling rate per second for this sensor.

Specified by:
getMaxSamplingRate in interface ITransducer
Overrides:
getMaxSamplingRate in class ScalarInput
Returns:
the maximum sampling rate per second for this sensor or 0 if not applicable.

getMinValue

public double getMinValue()
Description copied from interface: IMeasurementInfo
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()
Description copied from interface: IMeasurementInfo
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()
Description copied from interface: IMeasurementInfo
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()
Description copied from interface: IMeasurementInfo
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.