SunSPOT API V3.0


com.sun.spot.sensorboard.peripheral
Class TemperatureInput

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

public class TemperatureInput
extends ScalarInput
implements ITemperatureInput

Simple extension of ScalarInput.

Author:
Ron Goldman

Field Summary
 
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 addITemperatureInputThresholdListener(ITemperatureInputThresholdListener who)
          Adds the specified temperature sensor threshold listener to receive callbacks from this temperature sensor.
 double convert(double val, boolean toCelsius)
          Convert between Celsius and Fahrenheit.
 double getCelsius()
          Return the current temperature in degrees Celsius.
 double getFahrenheit()
          Return the current temperature in degrees Fahrenheit.
 double getHighThreshold(boolean toCelsius)
          Return the current high threshold value.
 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.
 void removeITemperatureInputThresholdListener(ITemperatureInputThresholdListener who)
          Removes the specified temperature sensor threshold listener so that it no longer receives callbacks from this temperature sensor.
 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
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

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

convert

public double convert(double val,
                      boolean toCelsius)
Convert between Celsius and Fahrenheit.

Specified by:
convert in interface ITemperatureInput
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.

Specified by:
setThresholds in interface ITemperatureInput
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.

Specified by:
getLowThreshold in interface ITemperatureInput
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.

Specified by:
getHighThreshold in interface ITemperatureInput
Parameters:
toCelsius - if true report the high threshold in degrees Celsius
Returns:
the current high threshold value.

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.

Specified by:
addITemperatureInputThresholdListener in interface ITemperatureInput
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.

Specified by:
removeITemperatureInputThresholdListener in interface ITemperatureInput
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.

Specified by:
getITemperatureInputThresholdListeners in interface ITemperatureInput
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

SunSPOT API V3.0


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