The following module can be used to test the above code. It simply prints the name of the button that was pressed.
implement Irtest; include "sys.m"; include "draw.m"; FD : import Sys; include "ir.m"; Irtest : module { init : fn(nil : ref Draw->Context, nil : list of string); }; ir : Ir; sys : Sys; init (nil : ref Draw->Context, nil : list of string) { c : int; stderr : ref FD; irchan := chan of int; sys = load Sys Sys->PATH; stderr = sys->fildes(2); # If the real IR remote application can # be found, use it, otherwise use the simulator: ir = load Ir Ir->PATH; if (ir == nil) ir = load Ir Ir->SIMPATH; if (ir == nil) { # %r format code means the last sys error # string sys->fprint(stderr, "load ir: %r\n"); return; } if (ir->init(irchan) != 0) { sys->fprint(stderr, "Ir.init: %r\n"); return; } names := array[] of { "Zero", "One", . . . "Mute", }; for(;;) { c = <- irchan; if (c == ir->Error) sys->print("Error %d\n", c); else sys->print("%s\n", names[c]); } }