ir — Inferno 1.1ed
ir
Synopsis
include "ir.m"; ir := load Ir Ir->PATH; # for real remotes simir := load Ir Ir->SIMPATH; # for keyboard simulator init: fn(irc: chan of int): int; translate: fn(key: int) : int;
Description
Programs running with the Limbo Prefab Modules toolkit are controlled by an infrared remote control device. If such a device is not present, the system may simulate it from the keyboard by loading the module in file Ir->SIMPATH. The Ir module defines codes for representing the remote control keys (see below). They are typically sent over the Context.cir (see context ) channel, which is managed by mux.Examples
Application programs using the remote control run under mux, which creates a graphics context for the application. This context includes channels to the mux program and to the Ir device: Draw->Context.ctomux and Draw->Context.cir. The following example establishes communication with mux and then reads Ir commands until it sees Enter.
implement Command;
include "sys.m";
include "draw.m";
include "ir.m";
Command: module
{
init: fn(ref Draw->Context; list of string);
};
init(ctxt: ref Draw->Context; argv: list of string);
{
sys:= load Sys Sys->PATH;
# Tell mux to start sending input.
ctxt.ctomux <-= Draw->AMstartinput;
for(;;) {
key:= <-ctxt.cir;
sys->print("command %d\n", key);
if(key == Ir->Enter)
break;
}
# Tell mux this thread is going away.
ctxt.ctomux <-= Draw->AMexit;
}
Programs such as mux that drive the remote control directly must load the appropriate module and initialize it. This example uses the absence of a simulator module to infer that a real remote control is available.
implement Irtest;
include "sys.m";
include "draw.m";
include "ir.m";
Irtest: module
{
init: fn(ctxt: ref Draw->Context, argv: list of string);
};
init(nil: ref Draw->Context, nil: list of string)
{
sys:= load Sys Sys->PATH;
# First try the keyboard Ir simulator.
# If that is not present, use Ir directly.
ir:= load Ir Ir->SIMPATH;
if(ir == nil)
ir = load Ir Ir->PATH;
if(ir == nil){
sys->print("Ir module not loaded: %r\n");
return;
}
irc:= chan of int;
if(ir->init(irc) < 0){
sys->print("Can't initialize Ir device: %r\n");
return;
}
for(;;){
irval:= <-irc;
sys->print("command %d\n", irval);
}
}
See Also
limbo , Limbo Modules , and Limbo Draw Modules
infernosupport@lucent.com Copyright © 1996,Lucent Technologies, Inc. All rights reserved.