lejos.nxt.addon
Class TouchPanel

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.TouchPanel
All Implemented Interfaces:
SensorConstants

public class TouchPanel
extends I2CSensor

This Class manages the MINDSENSORS Touch Panel.

Version:
1.0
Author:
Daniele Benedettelli, January 2012

Nested Class Summary
 class TouchPanel.VirtualButton
          The inner class VirtualButton is used to read the touch panel 8 virtual buttons.
 
Field Summary
static byte BTN_L1
           
static byte BTN_L2
           
static byte BTN_L3
           
static byte BTN_L4
           
static byte BTN_R1
           
static byte BTN_R2
           
static byte BTN_R3
           
static byte BTN_R4
           
 TouchPanel.VirtualButton L1
          Virtual button 1 at left (topmost)
 TouchPanel.VirtualButton L2
          Virtual button 2 at left
 TouchPanel.VirtualButton L3
          Virtual button 3 at left
 TouchPanel.VirtualButton L4
          Virtual button 4 at left (downmost)
 TouchPanel.VirtualButton R1
          Virtual button 1 at right (topmost)
 TouchPanel.VirtualButton R2
          Virtual button 2 at right
 TouchPanel.VirtualButton R3
          Virtual button 3 at right
 TouchPanel.VirtualButton R4
          Virtual button 4 at right (downmost)
 
Fields inherited from class lejos.nxt.I2CSensor
address, DEFAULT_I2C_ADDRESS, port, REG_PRODUCT_ID, REG_VENDOR_ID, REG_VERSION
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, 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
TouchPanel(I2CPort port)
          Instantiates a new Touch Panel sensor.
 
Method Summary
 void calibrate()
          Starts the calibration routine.
 boolean getButtonLastState(byte btnId)
          Gets the button state after last readButtons call.
 ArrayList<Point> getGesture()
          Read all available points from the device.
 Point getPoint()
          Gets the point where the touch panel is being touched.
 boolean isAnyButtonDown()
          Checks if any virtual button is down.
 boolean isNoButtonDown()
          Checks if no virtual button is down.
 byte readButtons()
          Private function to read the buttons register.
 boolean restoreDefaultCalibration()
          Restores calibration data to factory defaults
 boolean saveCalibration()
          Commits calibration data to permanent memory
 boolean setCalibratedMode(boolean yes)
          Sets the mode (calibrated or not)
 boolean setSamplingRate(int rate)
          Sets the gesture sampling rate,
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getPort, getProductID, getVendorID, getVersion, sendData, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BTN_L4

public static final byte BTN_L4
See Also:
Constant Field Values

BTN_L3

public static final byte BTN_L3
See Also:
Constant Field Values

BTN_L2

public static final byte BTN_L2
See Also:
Constant Field Values

BTN_L1

public static final byte BTN_L1
See Also:
Constant Field Values

BTN_R4

public static final byte BTN_R4
See Also:
Constant Field Values

BTN_R3

public static final byte BTN_R3
See Also:
Constant Field Values

BTN_R2

public static final byte BTN_R2
See Also:
Constant Field Values

BTN_R1

public static final byte BTN_R1
See Also:
Constant Field Values

R1

public final TouchPanel.VirtualButton R1
Virtual button 1 at right (topmost)


R2

public final TouchPanel.VirtualButton R2
Virtual button 2 at right


R3

public final TouchPanel.VirtualButton R3
Virtual button 3 at right


R4

public final TouchPanel.VirtualButton R4
Virtual button 4 at right (downmost)


L1

public final TouchPanel.VirtualButton L1
Virtual button 1 at left (topmost)


L2

public final TouchPanel.VirtualButton L2
Virtual button 2 at left


L3

public final TouchPanel.VirtualButton L3
Virtual button 3 at left


L4

public final TouchPanel.VirtualButton L4
Virtual button 4 at left (downmost)

Constructor Detail

TouchPanel

public TouchPanel(I2CPort port)
Instantiates a new Touch Panel sensor.

Parameters:
port - the port the sensor is attached to
Method Detail

calibrate

public void calibrate()
Starts the calibration routine. The user is instructed how to calibrate the touch panel.


getPoint

public Point getPoint()
Gets the point where the touch panel is being touched.

Returns:
the point

getButtonLastState

public boolean getButtonLastState(byte btnId)
Gets the button state after last readButtons call.

Parameters:
btnId - the button id
Returns:
the button last state

readButtons

public byte readButtons()
Private function to read the buttons register. To read buttons, use the VirtualButton R1,R2,R3,R4,L1,L2,L3,L4 methods isDown() and isUp()

Returns:
the byte

isAnyButtonDown

public boolean isAnyButtonDown()
Checks if any virtual button is down.

Returns:
true, if any button is down.

isNoButtonDown

public boolean isNoButtonDown()
Checks if no virtual button is down.

Returns:
true, if no button is down.

setCalibratedMode

public boolean setCalibratedMode(boolean yes)
Sets the mode (calibrated or not)

Returns:
true, if successful

saveCalibration

public boolean saveCalibration()
Commits calibration data to permanent memory

Returns:
true, if successful

restoreDefaultCalibration

public boolean restoreDefaultCalibration()
Restores calibration data to factory defaults

Returns:
true, if successful

setSamplingRate

public boolean setSamplingRate(int rate)
                        throws IllegalArgumentException
Sets the gesture sampling rate,

Parameters:
rate - can be a number from 1 to 8, 1 being the fastest, 8 being the slowest, default is 4
Returns:
true, if successful
Throws:
IllegalArgumentException - if rate is outside the range 1..8

getGesture

public ArrayList<Point> getGesture()
Read all available points from the device. Maximum available points are 110.

Returns:
the array of Points