SunSPOT API V3.0


com.sun.spot.sensorboard.peripheral
Class Switch

java.lang.Object
  extended by com.sun.spot.sensorboard.peripheral.Switch
All Implemented Interfaces:
IInputPinListener, ISwitch

public class Switch
extends Object
implements ISwitch, IInputPinListener

Class implementing simple switches, assuming a mapping of open=LOW, closed=HIGH. If the sense of the switch is reversed compose an InvertingInputPin onto the pin input.

Author:
Syntropy, modified Ron Goldman

Constructor Summary
Switch(IInputPin input)
          Constructor.
 
Method Summary
 void addISwitchListener(ISwitchListener who)
          Adds the specified switch listener to receive callbacks from this switch.
 ISwitchListener[] getISwitchListeners()
          Returns an array of all the switch listeners registered on this switch.
 boolean isClosed()
          Return true if the switch IS pressed.
 boolean isOpen()
          Return true if the switch is NOT pressed
 void pinSetHigh(IInputPin pin)
          Callback from associated InputPin to when switch released.
 void pinSetLow(IInputPin pin)
          Callback from associated InputPin to when switch pressed.
 void removeISwitchListener(ISwitchListener who)
          Removes the specified switch listener so that it no longer receives callbacks from this switch.
 void waitForChange()
          Block the current thread until the switch's state changes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Switch

public Switch(IInputPin input)
Constructor. Stores the single-bit input to be used.

Parameters:
input - the single-bit input to be used
Method Detail

isOpen

public boolean isOpen()
Return true if the switch is NOT pressed

Specified by:
isOpen in interface ISwitch
Returns:
true if the switch is NOT pressed

isClosed

public boolean isClosed()
Return true if the switch IS pressed.

Specified by:
isClosed in interface ISwitch
Returns:
true if the switch IS pressed

waitForChange

public void waitForChange()
Block the current thread until the switch's state changes. (This now uses interrupts and no longer polls.) Note: waitForChange does not inhibit deep sleep.

Specified by:
waitForChange in interface ISwitch

addISwitchListener

public void addISwitchListener(ISwitchListener who)
Adds the specified switch listener to receive callbacks from this switch.

Specified by:
addISwitchListener in interface ISwitch
Parameters:
who - the switch listener to add.

removeISwitchListener

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

Specified by:
removeISwitchListener in interface ISwitch
Parameters:
who - the switch listener to remove.

getISwitchListeners

public ISwitchListener[] getISwitchListeners()
Returns an array of all the switch listeners registered on this switch.

Specified by:
getISwitchListeners in interface ISwitch
Returns:
all of this switch's SwitchListeners or an empty array if no switch listeners are currently registered.

pinSetLow

public void pinSetLow(IInputPin pin)
Callback from associated InputPin to when switch pressed. Spawns threads to notify any registered ISwitchListeners.

Specified by:
pinSetLow in interface IInputPinListener

pinSetHigh

public void pinSetHigh(IInputPin pin)
Callback from associated InputPin to when switch released. Spawns threads to notify any registered ISwitchListeners.

Specified by:
pinSetHigh in interface IInputPinListener

SunSPOT API V3.0


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