LPL Topics
Event Handling
23-34 Using the LI-6400
23
Figure 23-15 illustrates (in Òpseudo-LPLÓ) how we might structure an LPL
program to handle three types of events. Essentially, we sit in a tight loop
waiting for something to happen, and when it does, we deal with it. The func-
tion HandleKeys, for example, would have to get the keystroke, and process
it.
In order for this outline to work as an LPL program, weÕd have to fill in the
routines such as ClockReady?, to signal us at desired times or time intervals.
Fortunately, LPL hides much of this work from the programmer. It turns out
that to actually implement the outline in Figure 23-15, one only needs to a)
register the functions to be called, and b) write those functions. Figure 23-16
illustrates how this actually looks in LPL.
We register the functions to be called using the ON... LPL keywords.
:FCT EventLoop
{
LOOP
KeysReady? IF HandleKeys THEN
ClockReady? IF HandleClock THEN
A/DReady? IF HandleA/D THEN
...
ENDLOOP
}
KeysReady? {...}
ClockReady? {...}
A/DReady? {...}
HandleKeys {
GETKEY ... }
HandleClock { ... }
HandleA/D { ... }
Figure 23-15. Illustration of the hard way to detect events
:FCT Main
{
&HandleKeys ONKBD
&HandleClock ONTIC
&HandleA/D 1 ONA2D
IDLE
}
HandleKeys { GETKEY ... }
HandleClock {...}
HandleA/D {...}
Figure 23-16. Programming for events in LPL.