[Top] [Prev] [Next]

ir - infrared remote control

include   "ir.m";
ir     := load Ir Ir->PATH;    # for real remotes
simir  := load Ir Ir->SIMPATH; # for keyboard simulator
init:      fn(c, p: chan of int) : int;
translate: fn(c: int)            : int;

Description

Programs running with the Prefab module 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 SIMPATH. The Ir module defines codes for representing the remote control keys. These codes are typically sent over the Context.cir channel, which is managed by Mux. (See context - graphics environment in Chapter 11 and Limbo Prefab Module in Chapter 12

init

The init function takes the appropriate actions to initialize the device, and then spawns a process to return the c the codes on the irc channel and p the process id on the pid channel. This is done for both real and simulated devices. The init function 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. The translate function is only necessary for programs that need to manage their own simulation of the remote control.

Codes
Code

Description of Code

Keyboard Equivalent

ChanUP, ChanDN

The Channel-Up and Channel-Down buttons

r and c

Enter

The Enter button

SPACE

EOF

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

None

Error

An unknown or invalid input from the remote device

None

FF, Rew

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 application 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 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 interface for the application. This includes channels to the Mux program and to the Ir device: Context.ctomux and 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;   
    pid:= chan of int;   

    if(ir->init(irc,pid) < 0){     
      sys->print("Can't initialize Ir device: %r\n");     
        return;   
    }   
      <- pid;
      for(;;){     
              irval:= <-irc;     
      sys->print("command %d\n", irval);   
    } 
}

See Also
Draw Module in Chapter 11

Introduction to Limbo Modules in Chapter 7

limbo - Limbo compiler in Chapter 4



[Top] [Prev] [Next]

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