Class: L8

L8

new L8()

Main API entry point providing all the public API in order to Control an L8 Smartlight

Fires:
Examples
 var L8 = require("l8smartlight").L8;

 var l8 = new L8();
 l8.open("/dev/YOUR_L8_SERIALPORT_DEVICE", null, function(error) {
     if (error) {
         throw new Error("Error occurred: " + error);
     }
     l8.setScrollingText("Hello World!", {r: 15, g: 0, b: 0}, "fast", false, function() {
         console.log("Now scrolling text ;)");
     });
 });

Alternatively you may use the automatically generated Promise API. All methods, which require a callback allow you to omit the callback and retrieve a Promise instead.

 var L8 = require("l8smartlight").L8;

 var l8 = new L8();
 l8.open("/dev/YOUR_L8_SERIALPORT_DEVICE", null).then(function() {
     return l8.clearMatrix();
 }).then(function(response) {
     return l8.setScrollingText("Hello World!", {r: 15, g: 0, b: 0}, "fast", false);
 }).then(function() {
     console.log("Now scrolling text ;)");
 }).catch(function(error) {
     console.error(error.stack);
 });

Members

isConnectedboolean

Indicator whether a connection is established or not.

privatereceiveBuffer_Object

Buffer for storing all received data, before it is processed.

privateserialport_SerialPort

SerialPort connection used for communication

static,constantL8.MAGIC_BYTESBuffer

Magic byte sequence used to identify any SLCP command or response

Methods

buildFrame(command, parametersBuffer){Buffer}

Build a frame in order to be sent to the L8

An L8 frame has the following structure:

MAGIC_BYTES|PayloadLength|Payload|PayloadCRC8

The Payload consists of a command as well as optional arguments

The command is an integer, as documented here: http://www.l8smartlight.com/dev/slcp/1.0/

The module:SLCP does encode all the specified commands into a human readable object structure. You may want to take a look at it, if you intend to use this method for sending raw commands.

The parameters are documented there as well. If a command does not have a parameter (eg. CMD_PING). The parametersBuffer argument to this function may be omitted.

The parameters may be provided as a hex string or a Buffer object for convenience.

The return value of this method is a ready to be sent Buffer, which can be given to L8#sendFrame for transmission.

Name Type Description
command Number
parametersBuffer Buffer | String optional

clearLED(x, y, fn)

Convenience function to switch of a single LED in the matrix.

The same behaviour is archivable by setting all color components of the LED to 0.

Name Type Description
x Number
y Number
fn function

clearMatrix(fn)

Clear the matrix by switching off all its LEDs

It is not necessary to execute this command between different setMatrix calls Only use it if you explicitly want to turn the matrix off.

This command does not affect the Super LED, which needs to be controlled separately.

Name Type Description
fn

clearScrollingText(fn)

Convenience method to stop scrolling text from being displayed.

The same behaviour is achievable by calling L8#stopApplication as the text scroller is an internal L8 application.

Name Type Description
fn function

clearSuperLED(fn)

Convenience function to switch off the SuperLED.

The same effect may be created by setting all color components of the LED to 0

Name Type Description
fn function

close(fn)

Close an established connection to the L8

Name Type Description
fn function

createAccelerationStream(samplingRate){AccelerationStream}

Create an object stream of acceleration data.

The optional samplingRate time which is waited between asking the L8 for data in milliseconds.

See AccelerationStream for details about the created stream.

Name Type Description
samplingRate Number optional

encodeBGRMatrixColor(color){Buffer}

Encode a color object to the BGR bytesequence accepted by the L8 as a matrix color (2-byte)

The color needs to be represented as object with r, g and b properties.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

Name Type Description
color Object

encodeBGRSingleColor(color){Buffer}

Encode a color object to the BGR bytesequence accepted by the L8 as a single color (3-byte)

The color needs to be represented as object with r, g and b properties.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

Name Type Description
color Object

encodeRGBSingleColor(color){Buffer}

Encode a color object to the RGB bytesequence accepted by the L8 as a single color (3-byte)

This color is for example used by the text scroller application

The color needs to be represented as object with r, g and b properties.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

Name Type Description
color Object

getAcceleration(fn)

Query the L8s accelerometer for data.

The data given to the callback is an object of the following form:

 {
     x: Number,
     y: Number,
     z: Number,
     lying: String,
     orientation: String,
     tap: Boolean,
     shake: Boolean
 }

The data structure corresponds to the response specified inside the L8 SLCP documentation about the CMD_L8_ACC_RESPONSE.

Name Type Description
fn function

privateonResponse_(data)

Callback executed each time data has been received from the L8.

Name Type Description
data Buffer

open(port, baudrate, fn)

Open a connection to the given port using an optionally provided baudrate

If no baudrate is specified a default speed of 115200 will be used.

After the port has been successfully opened the given callback will be fired

The operation is asynchronous. Further communication with the L8 is only feasible after the open callback has been fired.

Name Type Description
port String
baudrate Number nullable
fn

privateparseFrames_(receiveBuffer){Object}

Try to parse as many frames out of the given receiveBuffer, as possible.

The response is either an array containing a frame definition or false if the frame wasn't complete yet.

Name Type Description
receiveBuffer Object

ping(fn)

Ping the L8 in order to check if it is there.

The response is currently not handled automatically. If you want to check if a pong reply has been sent back using the L8#event:frameReceived event.

Name Type Description
fn function

sendFrame(buffer, expectedResponse, fn)

Send a raw buffer bytestream to the connected L8

If the expectedResponse property is set to true the callback will be hold back until a corresponding CMD_OK response from the L8 has been received. This response will be given to the callback then.

If the command does not answer with a callback false may be given

If the command does answer with another then the usual CMD_OK response it's command code and optional parameters need to be specified as object. The object has the following structure:

{command: Number, parameters: Buffer?}

The parameters are optional. If no parameters are specified any paramter will be accepted as soon as the command is matched.

Most commands will want to wait for the response.

Name Type Description
buffer Buffer
expectedResponse Boolean | Object
fn

setLED(x, y, color, fn)

Set a specific LED inside the 8x8 L8 grid to a given color

The color needs to be represented as object with r, g and b properties.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

Name Type Description
x Number
y Number
color Object
fn function

setMatrix(matrix, fn)

Set the complete matrix of LEDs with one command

This method should be used if you want display an "image" of sorts

The provided matrix needs to be a 64 elements long array of color objects.

Each of the color objects needs to provide an r, g and b property.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

The matrix is provided line by line. Starting in the upper left corner, while ending in the lower right.

Name Type Description
matrix Array
fn

setOrientation(orientation, fn)

Manually set the orientation of the L8

The orientation setting determines in which way the pixel matrix is drawn.

Valid orientations are:

  • up
  • down
  • left
  • right
  • auto

The orientation denotes, which side of the L8 is facing upwards. While the side with the power on switch is considered the Top side, while the one with the usb port is the Bottom side.

This command is not acquitted by an L8 response all cases. Instead the sent bytes are given to the callback in this situations.

Name Type Description
orientation String
fn function

setScrollingText(text, color, speed, loop, fn)

Start the internal L8 application to scroll text across the device

Once the scrolling has been started it needs to be stopped explicitly using L8#stopApplication or the convenience method L8#clearScrollingText Simply setting other colors to the LED matrix is not enough to cancel the scrolling text.

The text is supposed to be an ascii encoded string

Color is specified as object with the usual r, g, b properties ranging from 0-15.

speed defines the scrolling speed. It is supposed to be one of "slow", "medium" or "fast".

loop is a boolean value specifying if the animation is supposed to be looped, after it completed once. If it is set to false the scrolling application is exited after the first run through the text.

This command is not acquitted by an L8 response. Instead the sent bytes are given to the callback

Name Type Description
text String
color Object
speed String
loop Boolean
fn function

setSuperLED(color, fn)

Set the SuperLED on the back of the L8 to the given color.

The color needs to be represented as object with r, g and b properties.

The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.

Name Type Description
color Object
fn function

stopApplication(fn)

Stop the currently running L8 application on the device.

The L8 has certain predefined "Apps", which can be executed. This method stops the currently running application.

Name Type Description
fn function

Events

frameReceived

Event fired every time a frame is received

Type:
  • Object

frameSent

Event fired every time a frame is sent

The provied value is the raw buffer, which has been sent.

Type:
  • Buffer