|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectCarAPI
Copyright (c) 2003 Sony Ericsson Mobile Communications AB
All Rights Reserved.
CarAPI is the interface between the GUI and the other classes. It provides methods for GUI to control the Bluetooth car and check its status. CarConnection in the other hand retrieves the control commands from CarAPI and send them to the car.
Field Summary | |
static int |
CAR_CHARGING
Constant for car charging. |
static int |
CAR_DIRECTION_LEFT
Constant for car turning left. |
static int |
CAR_DIRECTION_LIGHT_LEFT
Constant for car turning left lightly. |
static int |
CAR_DIRECTION_LIGHT_RIGHT
Constant for car turning right lightly. |
static int |
CAR_DIRECTION_RIGHT
Constant for car turning right. |
static int |
CAR_DIRECTION_STRAIGHT
Constant for car going straight. |
static int |
CAR_NO_LINK
Constant for no connection to the car. |
static int |
CAR_READY
Constant for car ready to drive. |
static int |
CAR_SPEED_1
Constant for car driving forward with speed 1. |
static int |
CAR_SPEED_2
Constant for car driving forward with speed 2. |
static int |
CAR_SPEED_3
Constant for car driving forward with speed 3. |
static int |
CAR_SPEED_N
Constant for car stopped. |
static int |
CAR_SPEED_R
Constant for car driving backward. |
boolean |
timeToCloseConnection
Flag indicating that the car connection should close as soon as possible. |
Constructor Summary | |
CarAPI(BluetoothCar bluetoothCar)
Constructs a new CarAPI object. |
Method Summary | |
void |
decSpeed()
Decrease the speed by one. |
int |
getAndClearDirection()
Clears the flag and retrieves the direction set for the Bluetooth car. |
int |
getAndClearSpeed()
Clears the flag and retrieves the speed set for the Bluetooth car. |
int |
getDirection()
Retrieves the direction set for the Bluetooth car. |
int |
getSpeed()
Retrieves the speed set for the Bluetooth car. |
int |
getStatus()
Returns the current status of the Bluetooth car. |
void |
incSpeed()
Increase the speed by one. |
boolean |
isAppActive()
Check if the MIDlet is in Active state and shown. |
boolean |
isDirectionChanged()
Check if a new direction is set for the Bluetooth car. |
boolean |
isSpeedChanged()
Check if a new speed is set for the Bluetooth car. |
void |
setAppActive(boolean active)
Called when the MIDlet switches between the Paused
and the Active state and when the Canvas in
GUI switches between being hidden and shown.
|
void |
setDirection(int d)
Controls the speed of the car. |
void |
setSpeed(int s)
Controls the speed of the car. |
void |
setStatus(int s)
Sets the current status of the Bluetooth car. |
void |
startDisconnectTimer()
Starts a timer that will set the flag timeToCloseConnection, which is checked by the processEvents method in CarConnection (looped from SPPServer). |
void |
stop()
This will stop the car. |
void |
stopTimer()
Stops the disconnectTimer. |
void |
stopWaiting()
Releases any thread that is trapped in wait mode in the waitUntilActive() method above. |
void |
turnLeft()
Sets the car direction to turn one step to the left. |
void |
turnRight()
Sets the car direction to turn one step to the right. |
void |
waitUntilActive()
Puts the calling thread into wait mode if the MIDlet is inactive or not visible and if there is no connection to the car and the GUI has processed that state (i.e. the CAR_NO_LINK state). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int CAR_READY
public static final int CAR_CHARGING
public static final int CAR_NO_LINK
public static final int CAR_SPEED_3
public static final int CAR_SPEED_2
public static final int CAR_SPEED_1
public static final int CAR_SPEED_N
public static final int CAR_SPEED_R
public static final int CAR_DIRECTION_LEFT
public static final int CAR_DIRECTION_LIGHT_LEFT
public static final int CAR_DIRECTION_STRAIGHT
public static final int CAR_DIRECTION_LIGHT_RIGHT
public static final int CAR_DIRECTION_RIGHT
public boolean timeToCloseConnection
Constructor Detail |
public CarAPI(BluetoothCar bluetoothCar)
CarAPI
object.
Method Detail |
public boolean isAppActive()
MIDlet
is in Active state and shown.
true
if the MIDlet
is Active,
false
otherwise.public void setAppActive(boolean active)
MIDlet
switches between the Paused
and the Active state and when the Canvas
in
GUI
switches between being hidden and shown.
The GUI Canvas
becomes hidden when it's partly or completely
obscured by another application window.
If we are entering the Paused state or being hidden, the car is
stopped and the disconnectTimer
is started.
If we are entering the Active state or being shown, any thread
trapped in the waitUntilActive()
method will be signalled
to exit from its wait state and the disconnectTimer
is stopped.
active
- true
if we are entering the Active
state or being shown, false
if we are
entering the Paused state or being hidden.public void startDisconnectTimer()
public void stopTimer()
public void waitUntilActive()
public void stopWaiting()
public void setStatus(int s)
s
- the status to be set. It has to be either
CAR_READY
, CAR_CHARGING
, or
CAR_NO_LINK
.public int getStatus()
public boolean isSpeedChanged()
true
if the car speed has changedfalse
otherwisepublic void setSpeed(int s)
s
- this can be CAR_SPEED_R
,
CAR_SPEED_N
, CAR_SPEED_1
,
CAR_SPEED_2
, or CAR_SPEED_3
.public void incSpeed()
public void decSpeed()
public int getSpeed()
CAR_SPEED_R
,
CAR_SPEED_N
, CAR_SPEED_1
,
CAR_SPEED_2
, or CAR_SPEED_3
.public int getAndClearSpeed()
CAR_SPEED_R
,
CAR_SPEED_N
, CAR_SPEED_1
,
CAR_SPEED_2
, or CAR_SPEED_3
.public boolean isDirectionChanged()
true
if the car direction has changedfalse
otherwisepublic void setDirection(int d)
d
- this can be CAR_DIRECTION_LEFT
,
CAR_DIRECTION_LIGHT_LEFT
,
CAR_DIRECTION_STRAIGHT
,
CAR_DIRECTION_LIGHT_RIGHT
, or
CAR_DIRECTION_RIGHT
.public void turnLeft()
public void turnRight()
public int getDirection()
CAR_DIRECTION_LEFT
,
CAR_DIRECTION_LIGHT_LEFT
,
CAR_DIRECTION_STRAIGHT
,
CAR_DIRECTION_LIGHT_RIGHT
, or
CAR_DIRECTION_RIGHT
.public int getAndClearDirection()
CAR_DIRECTION_LEFT
,
CAR_DIRECTION_LIGHT_LEFT
,
CAR_DIRECTION_STRAIGHT
,
CAR_DIRECTION_LIGHT_RIGHT
, or
CAR_DIRECTION_RIGHT
.public void stop()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |