177 lines · 5.0 KB · Text
RawDownload
= ir: infrared remote control module     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, pidc: chan of int): int;    translate:  fn(key: int): int; Programs   running  with  the  Prefab  toolkit  (see  prefab-intro(2))  are  controlled  by  an  infrared  remote  controldevice.  If such a device is not present, the system may sim‐ulate it from the keyboard by  loading  the  module  in  fileIr->SIMPATH.   Although originally designed for use with Pre‐fab, these modules are general enough to be used directly  bynon-Prefab applications. The  Ir module defines codes for representing the remote con‐trol keys.  Whether the remote is real or simulated, the initfunction  does  the  appropriate  actions  to  initialize thedevice, and then spawns a process to return the codes on  theirc  channel.   The process ID of that process is sent on thechannel pidc when the  process  starts;  init's  caller  mustreceive  it.   It can be used to kill the controlling processwhen the application finishes. The codes are: Ir->ChanUP, Ir->ChanDN       The Channel-Up and Channel-Down buttons.  The keyboard       equivalents are r and c. Ir->Enter       The  Enter  button.   The  keyboard  equivalent is the       SPACE bar. Ir->EOF       An end of file from the remote device.  After  sending       one, no more codes will be sent on irc. Ir->Error       An unknown or invalid input from the remote device. Ir->FF, Ir->Rew       The  Fast-Forward  and  Rewind  buttons.  The keyboard       equivalents are k and j. Ir->Mute       The Mute button.  There is no keyboard equivalent. Ir->Power       The Power button.   The  keyboard  equivalent  is  the       Delete key. Ir->Rcl       The Recall button.  The keyboard equivalent is x. Ir->Record       The Record button.  There is no keyboard equivalent. Ir->Select       The  Select  button.   The  keyboard equivalent is the       Return or Enter key. Ir->Up, Ir->Dn       The Up and Down buttons.  The keyboard equivalents are       i and m. Ir->VolUP, Ir->VolDN       The  Volume-Up  and Volume-Down buttons.  The keyboard       equivalents are t and v. Ir->Zero, Ir->One, Ir->Two, etc.       The digit buttons, 0 through 9.  The keyboard  equiva‐       lents are the corresponding numeral keys. The  translate  function converts the device's raw codes intothe constants defined by the module.  For example,  with  thesimulated  remote  control, translate('3') returns Ir->Three.Translate is only necessary for programs that wish to  managetheir own simulation of the remote. Programs  that   drive the remote control directly, must loadthe appropriate Ir implementation module and  initialise  it.The  following example uses the absence of a simulator moduleto 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;    pidc := chan of int;    if(ir->init(irc, pidc) < 0){        sys->print("Can't initialize Ir device: %r\n");        return;    }    pid := <-pidc;    while((irraw := <-irc) != Ir->EOF) {        irval := ir->translate(irraw);        if(irval == Ir->Power)            break;        sys->print("command %d -> %d\n", irraw, irval);    }    kill(pid);} Mux(1) provides one model for the use of an  infrared  remotecontrol  to control a group of applications.  Init is invokedonce by mux, and  the  codes  then  multiplexed  between  itsapplications  as follows.  Mux creates a graphics context foreach  application  (see   draw-context(2)).    This   contextincludes  channels  to  the mux program and to the Ir device:Draw->Context.ctomux and Draw->Context.cinput.   Applicationsdo  not see the Ir->Rcl command.  Instead, mux program inter‐cepts it and reactivates its own menu.  The following exampleestablishes communication with mux and then reads Ir commandsuntil it see Ir->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.cinput;    sys->print("command %d\n", key);    if(key == Ir->Enter)      break;  }   #  Tell mux this thread is going away.  ctxt.ctomux <-= Draw->AMexit;} == source/appl/lib/ir.b/appl/lib/irmpath.b/appl/lib/irsim.b == see ALSOlimbo(1), mux(1), intro(2), draw-intro(2), prefab-intro(2) 

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t