Initialization and calibration
Whenever we need to talk to the RCX, some initialization is required via the
ActiveX control. That’s the same whether we’re going
to calibrate or poll for values. The setup_RCX()
function
takes a single argument—the identification of which connector the
light sensor is connected to—and performs the initialization,
which is described later in Section 9.2.3.8.
The function returns a handle on the Win32::OLE
object that represents the ActiveX control, which in turn represents
the RCX via the IR tower:
my $rcx = &setup_RCX(SENSOR);
If the -l option is not specified, it means we’re going to
be running calibration. So we call the calibrate()
function to do this for us. We pass the RCX handle (in $rcx)
so the calibration can run properly:
# Either calibrate if no parameters given, or
# run with the parameter given as -l, which will
# be taken as the pivot between coffee and no coffee
&calibrate($rcx) unless defined($opts{'l'});
As with the setup_RCX() function,
calibrate() is described later.
Calibration mode will be terminated by ending the script with
Ctrl-C,
so the next thing we come across is the call to the function
set_status(), which represents the first stage
in the normal script mode; set_status() is used
to determine the initial coffee status.
A value is retrieved by calling the ActiveX control’s
Poll() function.
(Table 9-2 lists the ActiveX control’s functions and properties used in this script.) We specify that we’re after a sensor value (the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access