[Top] [Prev] [Next]

ir

ir - infrared remote control

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.
init

The init function takes the appropriate actions to initialize the device, and then spawns a process to return the codes on the irc channel. This is done for both the real and simulated devices. Init is typically invoked once, such as by mux, and the codes are then multiplexed between the applications. Most programs need not call init.

translate

The translate function converts the device's raw codes into the constants defined by the module. For example, with the simulated remote control, translate('3') returns Three. Translate is only necessary for programs that wish to manage their own simulation of the remote control.

Codes

Keyboard Equivalent

ChanUP, ChanDN

The Channel-Up and Channel-Down buttons.

r and c

Enter

The Enter button.

SPACE bar

EOF

An end of file from the remote device. After sending one, no more codes will be sent on irc.

Error

An unknown or invalid input from the remote device.

FF, Rew

The Fast-Forward and Rewind buttons.

k and j

Mute

The Mute button.

none

Power

The Power button.

Delete key

Rcl

The Recall button. Typical applications do not see this command. Instead, the mux program intercepts the command and reactivates its menu.

x

Record

The Record button.

none

Select

The Select button.

Return or Enter key

Up, Dn

The Up and Down buttons.

i and m

VolUP, VolDN

The Volume-Up and Volume-Down buttons.

t and v

Zero, One, Two, etc.

The digit buttons, 0 through 9.

corresponding numeral keys

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



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.