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
-
Build a frame in order to be sent to the L8
An L8 frame has the following structure:
MAGIC_BYTES|PayloadLength|Payload|PayloadCRC8The 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:SLCPdoes 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). TheparametersBufferargument 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#sendFramefor transmission.Name Type Description commandNumber parametersBufferBuffer | String optional -
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 xNumber yNumber fnfunction -
Clear the matrix by switching off all its LEDs
It is not necessary to execute this command between different
setMatrixcalls 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 -
Convenience method to stop scrolling text from being displayed.
The same behaviour is achievable by calling
L8#stopApplicationas the text scroller is an internal L8 application.Name Type Description fnfunction -
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 fnfunction -
Close an established connection to the L8
Name Type Description fnfunction -
createAccelerationStream(samplingRate){AccelerationStream}
-
Create an object stream of acceleration data.
The optional
samplingRatetime which is waited between asking the L8 for data in milliseconds.See
AccelerationStreamfor details about the created stream.Name Type Description samplingRateNumber optional -
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,gandbproperties.The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.
Name Type Description colorObject -
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,gandbproperties.The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.
Name Type Description colorObject -
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,gandbproperties.The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.
Name Type Description colorObject -
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 fnfunction -
Callback executed each time data has been received from the L8.
Name Type Description dataBuffer -
Open a connection to the given port using an optionally provided baudrate
If no baudrate is specified a default speed of
115200will 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
opencallback has been fired.Name Type Description portString baudrateNumber nullable fn -
Try to parse as many frames out of the given receiveBuffer, as possible.
The response is either an array containing a frame definition or
falseif the frame wasn't complete yet.Name Type Description receiveBufferObject -
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:frameReceivedevent.Name Type Description fnfunction -
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
falsemay be givenIf 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
parametersare 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 bufferBuffer expectedResponseBoolean | Object fn -
Set a specific LED inside the 8x8 L8 grid to a given color
The color needs to be represented as object with
r,gandbproperties.The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.
Name Type Description xNumber yNumber colorObject fnfunction -
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,gandbproperty.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 matrixArray 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 orientationString fnfunction -
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#stopApplicationor the convenience methodL8#clearScrollingTextSimply setting other colors to the LED matrix is not enough to cancel the scrolling text.The
textis supposed to be an ascii encoded stringColor is specified as object with the usual
r,g,bproperties ranging from 0-15.speeddefines the scrolling speed. It is supposed to be one of "slow", "medium" or "fast".loopis a boolean value specifying if the animation is supposed to be looped, after it completed once. If it is set tofalsethe 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 textString colorObject speedString loopBoolean fnfunction -
Set the SuperLED on the back of the L8 to the given color.
The color needs to be represented as object with
r,gandbproperties.The color values need to be within the limits [0,15]. Where 0 represents the lightest and 15 the highest value.
Name Type Description colorObject fnfunction -
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 fnfunction
Events
-
Event fired every time a frame is received
Type:
- Object
-
Event fired every time a frame is sent
The provied value is the raw buffer, which has been sent.
Type:
- Buffer