SunSPOT API V6.0


com.sun.spot.sensorboard.io
Class BinaryScalar

java.lang.Object
  extended by com.sun.spot.resources.Resource
      extended by com.sun.spot.sensorboard.io.BinaryScalar
All Implemented Interfaces:
IResource, IInputPin, ITransducer, IScalarInputThresholdListener

public class BinaryScalar
extends Resource
implements IInputPin, IInputPin, IScalarInputThresholdListener

Class to allow using a ScalarInput as though it is an GPIO InputPin.

Author:
arshan

Constructor Summary
BinaryScalar(IScalarInput pin)
          Constructor.
 
Method Summary
 void addIInputPinListener(IInputPinListener who)
          Adds the specified input pin listener to receive callbacks from this input pin.
 void addIInputPinListener(IInputPinListener who)
          Old style IInputPinListener.
 SensorEvent createSensorEvent()
          Create a SensorEvent of the appropriate type for this sensor.
 String getDescription()
          This method returns a readable description of the sensor.
 IInputPinListener[] getIInputPinListeners()
          Returns an array of all the input pin listeners registered on this input pin.
 PinDescriptor getIndex()
           
 double getMaxSamplingRate()
          Return the maximum sampling rate per second for this sensor.
 int getRange()
           
 int getValue()
           
 boolean isHigh()
          Return true if the input bit is high.
 boolean isLow()
          Return true if the input bit is low.
 void removeIInputPinListener(IInputPinListener who)
          Removes the specified input pin listener so that it no longer receives callbacks from this input pin.
 void removeIInputPinListener(IInputPinListener who)
          Old style IInputPinListener.
 void saveEventState(SensorEvent evt)
          Save the current sensor state in the specified event.
 void thresholdChanged(IScalarInput in, int low, int high)
          Callback for when the scalar input thresholds are changed.
 void thresholdExceeded(IScalarInput in, int val)
          Callback for when the scalar input value goes above or below the specified thresholds.
 void waitForChange()
          Either polls or blocks until interrupt from a-to-d.
 
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, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Constructor Detail

BinaryScalar

public BinaryScalar(IScalarInput pin)
Constructor. The threshold for low/high is range/2.

Parameters:
pin - ScalarInput Pin to use
Method Detail

getValue

public int getValue()
             throws IOException
Throws:
IOException

getRange

public int getRange()
             throws IOException
Throws:
IOException

isLow

public boolean isLow()
Description copied from interface: IInputPin
Return true if the input bit is low.

Specified by:
isLow in interface IInputPin
Returns:
true if the input bit is low.

isHigh

public boolean isHigh()
Description copied from interface: IInputPin
Return true if the input bit is high.

Specified by:
isHigh in interface IInputPin
Returns:
true if the input bit is high.

waitForChange

public void waitForChange()
Either polls or blocks until interrupt from a-to-d.

Specified by:
waitForChange in interface IInputPin

getIndex

public PinDescriptor getIndex()

addIInputPinListener

public void addIInputPinListener(IInputPinListener who)
Adds the specified input pin listener to receive callbacks from this input pin.

Specified by:
addIInputPinListener in interface IInputPin
Parameters:
who - the input pin listener to add.

removeIInputPinListener

public void removeIInputPinListener(IInputPinListener who)
Removes the specified input pin listener so that it no longer receives callbacks from this input pin. 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 pin.

Specified by:
removeIInputPinListener in interface IInputPin
Parameters:
who - the input pin listener to remove.

getIInputPinListeners

public IInputPinListener[] getIInputPinListeners()
Returns an array of all the input pin listeners registered on this input pin.

Specified by:
getIInputPinListeners in interface IInputPin
Returns:
all of this input pin's listeners or an empty array if no input pin listeners are currently registered.

addIInputPinListener

public void addIInputPinListener(IInputPinListener who)
Old style IInputPinListener.


removeIInputPinListener

public void removeIInputPinListener(IInputPinListener who)
Old style IInputPinListener.


thresholdExceeded

public void thresholdExceeded(IScalarInput in,
                              int val)
Callback for when the scalar input value goes above or below the specified thresholds.

Specified by:
thresholdExceeded in interface IScalarInputThresholdListener
Parameters:
in - the IScalarInput that has crossed a threshold.
val - the current scalar input reading.

thresholdChanged

public void thresholdChanged(IScalarInput in,
                             int low,
                             int high)
Callback for when the scalar input thresholds are changed.

Specified by:
thresholdChanged in interface IScalarInputThresholdListener
Parameters:
in - the IScalarInput that had its threshold values changed.
low - the new scalar input low threshold value.
high - the new scalar input high threshold value.

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
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
Returns:
the maximum sampling rate per second for this sensor or 0 if not applicable.

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
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
Parameters:
evt - the event to store the sensor state in

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.