jBotBrain.hw
Class Button

java.lang.Object
  extended by jBotBrain.hw.Button

public class Button
extends Object

Abstraction for a button. Device is equipped with four buttons: S1, S2, S3, S4 (as you can see on PCB).
Example of usage:

    Button.S2.waitForPress();
    Button.S4.isPressed();
    int s1Id = Button.BUTTONS[0].getId();
 


Field Summary
static Button[] BUTTONS
          Array containing S1, S2, S3, S4, in that order.
static Button S1
          The S1 button.
static int S1_BUTTON
          The S1 button value.
static Button S2
          The S2 button.
static int S2_BUTTON
          The S2 button value.
static Button S3
          The S3 button.
static int S3_BUTTON
          The S3 button value.
static Button S4
          The S4 button.
static int S4_BUTTON
          The S4 button value.
 
Method Summary
 int getId()
          Return the ID of the button.
 boolean isPressed()
          Check if the button is pressed.
static int readButtons()
          Low-level API that reads status of buttons.
static int waitForPress()
          wait for some button to be pressed
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

S4_BUTTON

public static final int S4_BUTTON
The S4 button value. Used when reading raw value.

See Also:
Constant Field Values

S3_BUTTON

public static final int S3_BUTTON
The S3 button value. Used when reading raw value.

See Also:
Constant Field Values

S2_BUTTON

public static final int S2_BUTTON
The S2 button value. Used when reading raw value.

See Also:
Constant Field Values

S1_BUTTON

public static final int S1_BUTTON
The S1 button value. Used when reading raw value.

See Also:
Constant Field Values

S1

public static final Button S1
The S1 button.


S2

public static final Button S2
The S2 button.


S3

public static final Button S3
The S3 button.


S4

public static final Button S4
The S4 button.


BUTTONS

public static final Button[] BUTTONS
Array containing S1, S2, S3, S4, in that order.

Method Detail

getId

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

See Also:
S1_BUTTON, S2_BUTTON, S3_BUTTON, S4_BUTTON

isPressed

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

Returns:
true if button is pressed, false otherwise.

waitForPress

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

Returns:
the ID of that button, the same as readButtons();
See Also:
S1_BUTTON, S2_BUTTON, S3_BUTTON, S4_BUTTON

readButtons

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

Returns:
An integer with possibly some bits set: 0x01 (S3 button pressed) 0x02 (S4 button pressed), 0x04 (S2 button pressed), 0x08 (S1 button pressed). If all buttons are released, this method returns 0.
See Also:
S1_BUTTON, S2_BUTTON, S3_BUTTON, S4_BUTTON