forsyth20121205-174063a80cc13 years agoHistory
254 lines · 5.1 KB · Text
RawDownload
.TH IR 2.SH NAMEir \- infrared remote control module.SH SYNOPSIS.EXinclude     "ir.m"; ir    := load Ir Ir->PATH; # for real remotessimir := load Ir Ir->SIMPATH; # for keyboard simulator init:       fn(irc: chan of int, pidc: chan of int): int;translate:  fn(key: int): int;.EE.SH DESCRIPTIONPrograms running with the Prefabtoolkit (see.IR prefab-intro (2))are controlled by an infrared remotecontrol device.If such a device is not present, the system may simulateit from the keyboard by loading the module in file.BR Ir->SIMPATH .Although originally designed for use with Prefab,these modules are general enough to be used directly by non-Prefabapplications..PPThe.B Irmodule defines codesfor representing the remote control keys.Whether the remote is real or simulated, the.B initfunction does the appropriate actions to initialize the device, and then spawnsa process to return the codes on the.I ircchannel.The process ID of that processis sent on the channel.I pidcwhen the process starts;.BR init 'scaller must receive it.It can be used to kill the controlling process when the application finishes..PPThe codes are:.PP.TP.BR Ir\->ChanUP ", " Ir\->ChanDNThe Channel-Up and Channel-Down buttons.The keyboard equivalents are.B rand.BR c ..TP.B Ir\->EnterThe Enter button.The keyboard equivalent is the \s-1SPACE\s0 bar..TP.B Ir\->EOFAn end of file from the remote device.After sending one, no more codes will be sent on.IR irc ..TP.B Ir\->ErrorAn unknown or invalid input from the remote device..TP.BR Ir\->FF ", " Ir\->RewThe Fast-Forward and Rewind buttons.The keyboard equivalents are.B kand.BR j ..TP.B Ir\->MuteThe Mute button.There is no keyboard equivalent..TP.B Ir\->PowerThe Power button.The keyboard equivalent is the.B Deletekey..TP.B Ir\->RclThe Recall button.The keyboard equivalent is.BR x ..TP.B Ir\->RecordThe Record button.There is no keyboard equivalent..TP.B Ir\->SelectThe Select button.The keyboard equivalent is the.B Returnor.B Enterkey..TP.BR Ir\->Up ", " Ir\->DnThe Up and Down buttons.The keyboard equivalents are.B iand.BR m ..TP.BR Ir\->VolUP ", " Ir\->VolDNThe Volume-Up and Volume-Down buttons.The keyboard equivalents are.B tand.BR v ..TP.BIr\->Zero\fR,\fP Ir\->One\fR,\fP Ir\->Two\fR, etc..PDThe digit buttons, 0 through 9.The keyboard equivalents are the corresponding numeral keys..PPThe.B translatefunction converts the device's raw codes into the constants defined bythe module.For example, with the simulated remote control,.B translate('3')returns.BR Ir->Three ..B Translateis only necessary for programs that wish to manage their own simulation of the remote..PPProgramsthat  drive the remote control directly,must load the 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..PP.EXimplement 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\en");        return;    }    irc := chan of int;    pidc := chan of int;    if(ir->init(irc, pidc) < 0){        sys->print("Can't initialize Ir device: %r\en");        return;    }    pid := <-pidc;    while((irraw := <-irc) != Ir->EOF) {        irval := ir->translate(irraw);        if(irval == Ir->Power)            break;        sys->print("command %d -> %d\en", irraw, irval);    }    kill(pid);}.EE.PP.IR Mux (1)provides one model for the use of an infrared remote control to controla group of applications..B Initis invoked once by.IR mux ,and the codes then multiplexed between its applications as follows..I Muxcreates a graphics context for each application(see.IR draw-context (2)).This context includes channels to the.B muxprogram and to the.B Irdevice:.B Draw->Context.ctomuxand.BR Draw->Context.cinput .Applications do not see the.B Ir->Rclcommand.Instead,.I muxprogram intercepts it and reactivates its own menu.The following example establishes communication with.I muxand then reads.B Ircommands until it see.BR Ir->Enter ..PP.EXimplement 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\en", key);    if(key == Ir->Enter)      break;  }   #  Tell mux this thread is going away.  ctxt.ctomux <-= Draw->AMexit;}.EE.SH SOURCE.B /appl/lib/ir.b.br.B /appl/lib/irmpath.b.br.B /appl/lib/irsim.b.SH SEE ALSO.IR limbo (1),.IR mux (1),.IR intro (2),.IR draw-intro (2),.IR prefab-intro (2)