-
Notifications
You must be signed in to change notification settings - Fork 0
Prismatik Node.js API
This is not a full feature API that Prismatik provides from their Github.
The file is located here: prismatik-client.js
This should be cross-platform (using only Node.js methods).
To add this to your project, you need prismatik-client.js to your project and you need to reference it as usual with require.
var prismatik = require("./prismatik-client");
You can interface with Prismatik (when it is running). This API wraps a socket client to their application.
var prismatik = require("./prismatik-client");
// Connect to Prismatik
var options = {
host: "127.0.0.1", // Localhost
port: 3636 // Default Prismatik port
};
prismatik.connect(function(isConnected) {
if (isConnected) {
prismatik.lock(function(success) {
if (success) {
prismatik.setBrightness(100);
prismatik.setColorToAll(255, 255, 0); // Set all LEDs' colors to yellow
} else {
console.log("Could not lock, something else has already connected.");
prismatik.disconnect();
}
});
} else {
console.log("Failed to connect to Prismatik");
}
}, options);
- prismatik.connect(fn, opts)
- prismatik.disconnect(fn)
- prismatik.getCountLeds(fn)
- prismatik.getProfiles(fn)
- prismatik.getProfile(fn)
- prismatik.getStatus(fn)
- prismatik.getAPIStatus(fn)
- prismatik.setProfile(name, fn)
- prismatik.setGamma(n, fn)
- prismatik.setSmooth(n, fn)
- prismatik.setBrightness(n, fn)
- prismatik.setColorToAll(r, g, b, fn)
- prismatik.setColors(rgbArray, fn)
- prismatik.setColor(n, r, g, b, fn)
- prismatik.lock(fn)
- prismatik.unlock(fn)
- prismatik.on(evtName, fn)
- Params: fn - callback function
-
Params: [optional] opts - object with any of the following keys
- host: specifies which host to connect to Prismatik (default is localhost, 127.0.0.1)
- port: port specified in Prismatik application (default is 3636)
- apikey: if Prismatik specifies for an API key, then you have to match it
- Callback: fn - first argument is if socket has successfully connected to Prismatik
Connects to Prismatik with the options specified. If no options specified, it will use the defaults. The callback is triggered after connection or timeout with the first argument as a boolean to see if it connected or not. This does not mean that Lightpack has connected. Normally you lock after calling this or else no other commands will work.
- Callback: fn - first argument is either true or false if it worked or not
Disconnects the socket from Prismatik. This will also run unlock.
- Params: fn - callback function
- Callback: fn - first argument is a number multiples of 10 if connected, 0 if not
Returns the number of LEDs this API is connected to.
- Callback: fn - first argument is an array of profile names (strings) made using Prismatik
- Callback: fn - first argument is the current Prismatik's profile name (a string)
-
Callback: fn - first argument is one of the following
- "status:on"
- "status:off"
- "status:device error"
- "status:unknown"
Gets the status of what Prismatik is currently doing with this socket.
-
Callback: first argument is one of the following
- "statusapi:busy"
- "statusapi:idle"
Gets the status of the API.
- Params: name - string name of an existing profile from Prismatik
- Callback: fn - first argument is either true or false if it worked or not
Changes the current profile set in Prismatik.
- Params: n - set the gamma value from 0.01 to 10.0 (default is 2.2)
- Callback: fn - first argument is either true or false if it worked or not
- Params: n - set the smooth value from 0 to 255
- Callback: fn - first argument is either true or false if it worked or not
- Params: n - set the brightness value from 0 to 100
- Callback: fn - first argument is either true or false if it worked or not
- Params: r - set red part of color
- Params: g - set green part of color
- Params: b - set blue part of color
- Callback: fn - first argument is either true or false if it worked or not
Sets the colors to all LEDs.
-
Params: rgbArray - an array of colors with the following format
- rgb array: [r,b,g]
- single rgb value: rgb
- skip led: -1
- Callback: fn - true or false if it worked (or is connected)
This will set colors to multiple LEDs given a list of colors. Since this is slightly complicated to use, view the example below:
prismatik.setColors([
[255, 0, 0], // LED 0 - Red
-1, // LED 1 - Skip
[0, 255, 0], // LED 2 - Green
(255 | 255 & 0xFF00 | 0 & 0xFF0000) // LED 3 - Yellow
]);
- Params: n - which LED (0->10 or more) to set the color
- Params: r - red color (0->255)
- Params: g - red color (0->255)
- Params: b - red color (0->255)
- Callback: fn - true or false if it worked (or is connected)
This will set a color to one LED.
- Callback: fn - true or false if it worked (or is connected)
Locks this application to Prismatik and nothing else can use it. If the argument in the callback is false, then it failed to lock and you cannot use any of the functions in this API except disconnect.
- Callback: fn - true or false if it worked (or is connected)
Unlocks this application from Prismatik. You do not need to use this when disconnecting because disconnect will unlock as well.
-
Params: evtName - Event name, only one of the following:
- error: when there is a socket error, this callback will run
- Callback: fn - this function will run when an event occurs