Package lejos.hardware.device
Class MindSensorsNumPad
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.I2CSensor
-
- lejos.hardware.device.MindSensorsNumPad
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorConstants,SensorMode,SensorModes,SampleProvider
public class MindSensorsNumPad extends I2CSensor
LeJOS driver for the Mindsensors NumericPad.- Author:
- Rudolf Lapie
-
-
Field Summary
Fields Modifier and Type Field Description static intERRORstatic intID_HASHstatic intID_KEY0static intID_KEY1static intID_KEY2static intID_KEY3static intID_KEY4static intID_KEY5static intID_KEY6static intID_KEY7static intID_KEY8static intID_KEY9static intID_STAR-
Fields inherited from class lejos.hardware.sensor.I2CSensor
address, DEFAULT_I2C_ADDRESS, port, REG_PRODUCT_ID, REG_VENDOR_ID, REG_VERSION, retryCount
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
currentMode, modes
-
Fields inherited from interface lejos.hardware.sensor.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, BROWN, GREEN, GREEN_INDEX, MAX_TYPE, MIN_TYPE, MODE_RAW, NXT_ADC_RES, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HIGHSPEED, TYPE_HIGHSPEED_9V, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
-
-
Constructor Summary
Constructors Constructor Description MindSensorsNumPad(I2CPort port)Constructor for objects of the NumericPad of Mindsensors.MindSensorsNumPad(Port port)Constructor for objects of the NumericPad of Mindsensors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddiscardEvents()This method discards any events.protected voidinit()static java.lang.StringmaskToString(int x)The lower 12 bits (Bits 0 to 11) are converted to a string containing 0 to 9, *, and # depending on whether which of bits are set.intreadButtons()Returns a Bitmask.intwaitForAnyEvent()Waits for some button to be pressed or released.intwaitForAnyEvent(int timeout)Waits for some button to be pressed or released.intwaitForAnyPress()Waits for some button to be pressed.intwaitForAnyPress(int timeout)Waits for some button to be pressed.-
Methods inherited from class lejos.hardware.sensor.I2CSensor
fetchString, getAddress, getData, getData, getPort, getProductID, getRetryCount, getVendorID, getVersion, sendData, sendData, sendData, setAddress, setRetryCount
-
Methods inherited from class lejos.hardware.sensor.BaseSensor
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
Field Detail
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
ID_KEY0
public static final int ID_KEY0
- See Also:
- Constant Field Values
-
ID_KEY1
public static final int ID_KEY1
- See Also:
- Constant Field Values
-
ID_KEY2
public static final int ID_KEY2
- See Also:
- Constant Field Values
-
ID_KEY3
public static final int ID_KEY3
- See Also:
- Constant Field Values
-
ID_KEY4
public static final int ID_KEY4
- See Also:
- Constant Field Values
-
ID_KEY5
public static final int ID_KEY5
- See Also:
- Constant Field Values
-
ID_KEY6
public static final int ID_KEY6
- See Also:
- Constant Field Values
-
ID_KEY7
public static final int ID_KEY7
- See Also:
- Constant Field Values
-
ID_KEY8
public static final int ID_KEY8
- See Also:
- Constant Field Values
-
ID_KEY9
public static final int ID_KEY9
- See Also:
- Constant Field Values
-
ID_STAR
public static final int ID_STAR
- See Also:
- Constant Field Values
-
ID_HASH
public static final int ID_HASH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MindSensorsNumPad
public MindSensorsNumPad(I2CPort port)
Constructor for objects of the NumericPad of Mindsensors. It assumes that you didn't change the I??C address of the device.- Parameters:
port- the port number (SensorPort.S1 ... SensorPort.S4) to which the numeric pad is connected.
-
MindSensorsNumPad
public MindSensorsNumPad(Port port)
Constructor for objects of the NumericPad of Mindsensors. It assumes that you didn't change the I??C address of the device.- Parameters:
port- the port number (SensorPort.S1 ... SensorPort.S4) to which the numeric pad is connected.
-
-
Method Detail
-
init
protected void init()
-
readButtons
public int readButtons()
Returns a Bitmask. Bits 0 to 9 correspond to the Number Keys 0 to 9. Bit 10 corresponds to the star and Bit 11 to the hash key.- Returns:
- the bitmask, or
ERRORif an I2C error has occured
-
discardEvents
public void discardEvents()
This method discards any events.
-
waitForAnyEvent
public int waitForAnyEvent()
Waits for some button to be pressed or released. Which buttons have been released or pressed is returned as a bitmask. The lower twenve bits (bits 0 to 11) indicate, which buttons have been pressed. Bits 16 to 27 indicate which buttons have been released.- Returns:
- the bitmask
-
waitForAnyEvent
public int waitForAnyEvent(int timeout)
Waits for some button to be pressed or released. Which buttons have been released or pressed is returned as a bitmask. The lower twenve bits (bits 0 to 11) indicate, which buttons have been pressed. Bits 16 to 27 indicate which buttons have been released.- Parameters:
timeout- The maximum number of milliseconds to wait- Returns:
- the bitmask
-
waitForAnyPress
public int waitForAnyPress()
Waits for some button to be pressed. If a button is already pressed, it must be released and pressed again.- Returns:
- the ID of the button that has been pressed or in rare cases a bitmask of button IDs
-
waitForAnyPress
public int waitForAnyPress(int timeout)
Waits for some button to be pressed. If a button is already pressed, it must be released and pressed again.- Parameters:
timeout- The maximum number of milliseconds to wait- Returns:
- the ID of the button that has been pressed or in rare cases a bitmask of button IDs, 0 if the given timeout is reached
-
maskToString
public static java.lang.String maskToString(int x)
The lower 12 bits (Bits 0 to 11) are converted to a string containing 0 to 9, *, and # depending on whether which of bits are set. The returned string contains these character in that order.
-
-