Start of Tutorial > Start of Trail |
Note that this lesson already refers to the actual re-organization of the remotecontrol package in the CVS: in future
the package will be part of josx.rcxcomm
whereas in the actual leJOS release 2.1.0 it's located in
josx.platform.rcx
yet.
josx.rcxcomm.remotecontrol
package is mainly supposed to be used in connection with the LEGO®
remote control contained in the
(however, as we will see, there is also a class which enables you to simulate
commands sent by it).
josx.rcxcomm.remotecontrol.RemoteControlSensor
.
josx.platform.rcx.SerialListener
, which constantly checks
the IR sensor on front of the RCX for incoming IR signals.
josx.rcxcomm.remotecontrol.RemoteControlListener
interface which declares the following
methods that correspond to the buttons of the remote control:
public void addRemoteControlListener(RemoteControlListener aListener)
method.
One of the drawbacks of the usage of infrared signals by LEGO MINDSTORMS™ instead of, say, radio waves, is that the IR sensor of the RCX has to point straight to the remote control when pressing a button - else the signal will never arrive at the sensor and will simply get lost. Sometimes, though, it might help to point the remote control towards the ceiling of the room.
josx.rcxcomm.remotecontrol.RemoteControlSensor
somewhere in the code running on your RCXjosx.rcxcomm.remotecontrol.RemoteControlListener
interface:
add to the body of each of its methods the code that may be executed when the associated button on the remote control
is pressed. A natural implementation for the soundPressed()
method, for example, might be to play a sound
by calling Sound.beep()
; after all, you are completely free in the action your program takes as a reaction
to any remote control command!
If your application is interested only in a part of the messages of the remote control, you can just extend the
josx.rcxcomm.remotecontrol.RemoteControlAdapter
(that implements the listener interface with empty
method bodies) and override only the methods you are interested in.
josx.rcxcomm.remotecontrol.RemoteControlMessenger
that is - as all the communication classes supposed
to run rather on the PC than on the RCX - contained in the pcrcxcomm.jar
.
public void send(byte[] aMessageCode)
method, where aMessageCode
has to be one of the public RemoteControlMessenger
message opcode
constants (see there).
Note there is a ready-made tool available which simulates the LEGO® remote control on the PC either as a Java™ application or as a JSP web page, named Maroc.
Of course you are free to use the rcxcomm classes to send messages to the remote control
sensor by yourself. The RemoteControlSensor
accepts not only native message bytes sent by the
LEGO® remote control but also the F7 LEGO firmware protocol, which means that you can use josx.rcxcomm.RCXF7Port
as well.
Keep in mind, though, that the remote control sensor class will respond to opcodes belonging to
LEGO® remote control commands only.
examples/comms/remotectl
section of the leJOS tree.
Start of Tutorial > Start of Trail |