Example: Front Panel Service

The Front Panel Service sets the colors and status (on/off) of the LEDs on the front of the STB. The number of LEDs and their colors may vary between STB models. This Service does not handle buttons on the front panel, but it does handle a segmented display.

The example first locates the Front Panel Service through the global toi object:

fps = toi.frontPanelService;

Status of LEDs

The Front Panel Service offers functions so you can determine the number of LEDs and their capabilities. See the documentation for Front Panel Service for more details. This example requests the number of LEDs and then prints out their status:

numLeds = fps.getLedCount();

for(var j=0; j < numLeds; j++) {
    alert("leds[" + j + "] is " + fps.getLedState(j).color);
}

The color parameter is actually defined as a TToiColor type in the front panel service.

Setting the State

To change the state of a LED, a ToiFrontPanelServiceLedState instance needs to be created using toi.statics (used for creating structures):

var fps = toi.frontPanelService;
var state = toi.statics.ToiFrontPanelServiceLedState.create(fps.COLOR_RED, 0);

fps.setLedState(currentLed, state);

Note how the example code surrounds the setting of values with exception handling, as different IP-STB models have different numbers of LEDs and abilities. It is important to handle the exceptions to know what hardware options are available.