lejos.nxt
Class Button

java.lang.Object
  extended by lejos.nxt.Button
All Implemented Interfaces:
ListenerCaller

public class Button
extends Object
implements ListenerCaller

Abstraction for an NXT button. Example:

    Button.ENTER.waitForPressAndRelease();
    Sound.playTone (1000, 1);
 


Field Summary
static Button[] BUTTONS
          Array containing ENTER, LEFT, RIGHT, ESCAPE, in that order.
static Button ENTER
          The Enter button.
static Button ESCAPE
          The Escape button.
static int ID_ENTER
           
static int ID_ESCAPE
           
static int ID_LEFT
           
static int ID_RIGHT
           
static Button LEFT
          The Left button.
static Button RIGHT
          The Right button.
static String VOL_SETTING
           
 
Method Summary
 void addButtonListener(ButtonListener aListener)
          Adds a listener of button events.
 void callListeners()
          Call Button Listeners.
 int getId()
          Return the ID of the button.
static int getKeyClickLength()
          Return the current key click length.
static int getKeyClickTone(int key)
          Return the click freq for a particular key.
static int getKeyClickVolume()
          Return the current key click volume.
 boolean isPressed()
          Check if the button is pressed.
static void loadSettings()
          Load the current system settings associated with this class.
static int readButtons()
          Low-level API that reads status of buttons.
static void setKeyClickLength(int len)
          Set the len used for key clicks
static void setKeyClickTone(int key, int freq)
          Set the frequency used for a particular key.
static void setKeyClickVolume(int vol)
          Set the volume used for key clicks
static int waitForPress()
          wait for some button to be pressed (and released).
static int waitForPress(int timeout)
          wait for some button to be pressed (and released).
 void waitForPressAndRelease()
          Wait until the button is released.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_ENTER

public static final int ID_ENTER
See Also:
Constant Field Values

ID_LEFT

public static final int ID_LEFT
See Also:
Constant Field Values

ID_RIGHT

public static final int ID_RIGHT
See Also:
Constant Field Values

ID_ESCAPE

public static final int ID_ESCAPE
See Also:
Constant Field Values

VOL_SETTING

public static final String VOL_SETTING
See Also:
Constant Field Values

ENTER

public static final Button ENTER
The Enter button.


LEFT

public static final Button LEFT
The Left button.


RIGHT

public static final Button RIGHT
The Right button.


ESCAPE

public static final Button ESCAPE
The Escape button.


BUTTONS

public static final Button[] BUTTONS
Array containing ENTER, LEFT, RIGHT, ESCAPE, in that order.

Method Detail

getId

public final int getId()
Return the ID of the button. One of 1, 2, 4 or 8.


isPressed

public final boolean isPressed()
Check if the button is pressed.

Returns:
true if button is pressed, false otherwise.

waitForPressAndRelease

public final void waitForPressAndRelease()
Wait until the button is released.


waitForPress

public static int waitForPress(int timeout)
wait for some button to be pressed (and released).

Parameters:
timeout - The number of milliseconds to wait.
Returns:
the ID of that button, the same as readButtons(); 0 if timeout

waitForPress

public static int waitForPress()
wait for some button to be pressed (and released).

Returns:
the ID of that button, the same as readButtons();

addButtonListener

public void addButtonListener(ButtonListener aListener)
Adds a listener of button events. Each button can serve at most 4 listeners.


readButtons

public static int readButtons()
Low-level API that reads status of buttons.

Returns:
An integer with possibly some bits set: 0x01 (ENTER button pressed) 0x02 (LEFT button pressed), 0x04 (RIGHT button pressed), 0x08 (ESCAPE button pressed). If all buttons are released, this method returns 0.

callListeners

public void callListeners()
Call Button Listeners. Used by ListenerThread.

Specified by:
callListeners in interface ListenerCaller

setKeyClickVolume

public static void setKeyClickVolume(int vol)
Set the volume used for key clicks

Parameters:
vol -

getKeyClickVolume

public static int getKeyClickVolume()
Return the current key click volume.

Returns:
current click volume

setKeyClickLength

public static void setKeyClickLength(int len)
Set the len used for key clicks

Parameters:
len - the click duration

getKeyClickLength

public static int getKeyClickLength()
Return the current key click length.

Returns:
key click duration

setKeyClickTone

public static void setKeyClickTone(int key,
                                   int freq)
Set the frequency used for a particular key. Setting this to 0 disables the click. Note that key may also be a corded set of keys.

Parameters:
key - the NXT key
freq - the frequency

getKeyClickTone

public static int getKeyClickTone(int key)
Return the click freq for a particular key.

Returns:
key click duration

loadSettings

public static void loadSettings()
Load the current system settings associated with this class. Called automatically to initialize the class. May be called if it is required to reload any settings.