Control LED systems

Prev Next

This article describes how to control an external LED system through runtime commands sent to the Grassfish Player.

These commands are issued using the sendMessageToPlayer method of the GFSpotBase interface.

Command syntax

The LED control interface follows a simple command protocol. The commands are interpreted by the player and routed to the physical or simulated LED device.

Note

Command processing depends on the player type and version. For example, the Android player can interpret LED commands natively without additional configuration. Other platforms, such as Qt-based players, may require an additional LED control add-on for full functionality.


Turn LED on with color:

sendMessageToPlayer("LEDOn", "<hexColor>");

  • "LEDOn": Use this command to switch on the LED.

  • <hexColor>: Specify the LED’s color using the RGB color value in hexadecimal format (#FF0000).


Turn LED off:

sendMessageToPlayer("LEDOff");

  • "LEDOff": Use this command to switch off the LED entirely.


Access the interface

To communicate with the player, the spot must include the gfSpotBase.js library. This JavaScript file is typically added as a script dependency and is responsible for providing the global GFSpotBase object.

To include the library globally, use the following command:

window.GFSpotBase = new GFSpotBase();

This makes the API accessible throughout the spot runtime.

Note

Before using any methods, the spot should check whether window.GFSpotBase is available to avoid runtime errors.

Example implementation

The following example shows a minimal implementation using a service-based abstraction:

private setLedOn(hexColor: string | null) {
  if (hexColor) {
    GfSpotBaseService.sendMessageToPlayer("LEDOn", hexColor);
  }
}

private setLedOff() {
  GfSpotBaseService.sendMessageToPlayer("LEDOff");
}

Abstraction layer

This example shows how to use a common approach to encapsulate GFSpotBase access in a service class:

  • This wrapper provides a safe abstraction for all player communication tasks, including LED control.

  • We recommended to use such a structure to improve modularity, testability, and error handling.

class GfSpotBaseService {
  private _spotBase: any;

  constructor() {
    if (window.GFSpotBase) {
      this._spotBase = window.GFSpotBase;
    } else {
      throw "NoSpotBaseException";
    }
  }

  sendMessageToPlayer(...args: (string | number)[]): void {
    this._spotBase.sendMessageToPlayer(...args);
  }
}