SunSPOT API V3.0


com.sun.spot.sensorboard.io
Class ScalarInput

java.lang.Object
  extended by com.sun.spot.sensorboard.io.ScalarInput
All Implemented Interfaces:
IScalarInput
Direct Known Subclasses:
LightSensor, TemperatureInput

public class ScalarInput
extends Object
implements IScalarInput

Simple concrete implementation of IScalarInput.


Field Summary
protected  PinDescriptor index
           
protected  IADCController myController
           
protected  int range
           
 
Constructor Summary
ScalarInput(PinDescriptor idx, int r, IADCController cntrl)
           
 
Method Summary
 void addIScalarInputThresholdListener(IScalarInputThresholdListener who)
          Adds the specified scalar input threshold listener to receive callbacks from this input device.
 boolean areThresholdEventsEnabled()
          Return whether threshold events are enabled or not.
 void enableThresholdEvents(boolean enable)
          Enable or disable threshold events.
 int getHighThreshold()
          Return the current high threshold value.
 PinDescriptor getIndex()
          Return the PinDescriptor associated with this input pin.
 IScalarInputThresholdListener[] getIScalarInputThresholdListeners()
          Returns an array of all the scalar input threshold listeners registered on this input device.
 int getLowThreshold()
          Return the current low threshold value.
 int getRange()
          Return the maximum possible value that could be returned from the input device.
 int getValue()
          Return the current value of the input.
 float getVoltage()
          Get the ADC value in voltage
 void removeIScalarInputThresholdListener(IScalarInputThresholdListener who)
          Removes the specified scalar input threshold listener so that it no longer receives callbacks from this input device.
 void setThresholds(int low, int high)
          Set the low and high threshold values for this scalar input.
 boolean supportsThresholdEvents()
          Returns whether the underlying hardware supports threshold events.
 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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

index

protected PinDescriptor index

range

protected int range

myController

protected IADCController myController
Constructor Detail

ScalarInput

public ScalarInput(PinDescriptor idx,
                   int r,
                   IADCController cntrl)
Method Detail

getIndex

public PinDescriptor getIndex()
Return the PinDescriptor associated with this input pin.

Specified by:
getIndex in interface IScalarInput
Returns:
the PinDescriptor associated with this input pin.

getRange

public int getRange()
             throws IOException
Return the maximum possible value that could be returned from the input device.

Specified by:
getRange in interface IScalarInput
Returns:
maximum possible value that could be returned from the input device
Throws:
IOException

getValue

public int getValue()
Return the current value of the input.

Specified by:
getValue in interface IScalarInput
Returns:
current value of the input
Throws:
IOException

getVoltage

public float getVoltage()
Get the ADC value in voltage

Returns:
Voltage applied to the ADC pin.

supportsThresholdEvents

public boolean supportsThresholdEvents()
Returns whether the underlying hardware supports threshold events.

Specified by:
supportsThresholdEvents in interface IScalarInput
Returns:
true if threshold events are supported

addIScalarInputThresholdListener

public void addIScalarInputThresholdListener(IScalarInputThresholdListener who)
Adds the specified scalar input threshold listener to receive callbacks from this input device. Callbacks occur when the scalar input reading falls below or equal to the low threshold value, or when it rises above or equal to the high threshold value.

Specified by:
addIScalarInputThresholdListener in interface IScalarInput
Parameters:
who - the scalar input threshold listener to add.

removeIScalarInputThresholdListener

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

Specified by:
removeIScalarInputThresholdListener in interface IScalarInput
Parameters:
who - the scalar input threshold listener to remove.

getIScalarInputThresholdListeners

public IScalarInputThresholdListener[] getIScalarInputThresholdListeners()
Returns an array of all the scalar input threshold listeners registered on this input device.

Specified by:
getIScalarInputThresholdListeners in interface IScalarInput
Returns:
all of this scalar input's IScalarInputThresholdListener or an empty array if no scalar input threshold listeners are currently registered.

enableThresholdEvents

public void enableThresholdEvents(boolean enable)
Enable or disable threshold events.

Specified by:
enableThresholdEvents in interface IScalarInput
Parameters:
enable - if true then listeners will be notified if the scalar input reading goes above the high threshold or below the low threshold.

areThresholdEventsEnabled

public boolean areThresholdEventsEnabled()
Return whether threshold events are enabled or not.

Specified by:
areThresholdEventsEnabled in interface IScalarInput
Returns:
true if listeners will be notified if the scalar input reading goes above the high threshold or below the low threshold.

setThresholds

public void setThresholds(int low,
                          int high)
Set the low and high threshold values for this scalar input. Callbacks occur when the scalar input 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 IScalarInput
Parameters:
low - the new low threshold value.
high - the new high threshold value.

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.

Parameters:
low - the new low threshold value.
high - the new high threshold value.

getLowThreshold

public int getLowThreshold()
Return the current low threshold value.

Specified by:
getLowThreshold in interface IScalarInput
Returns:
the current low threshold value.

getHighThreshold

public int getHighThreshold()
Return the current high threshold value.

Specified by:
getHighThreshold in interface IScalarInput
Returns:
the current high threshold value.

thresholdExceeded

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

Parameters:
val - scalar value taken after event triggered

SunSPOT API V3.0


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