Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-blink1

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-blink1 - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test.js

43

blink1.js

@@ -104,2 +104,6 @@ var HID = require('node-hid');

Blink1.prototype._validateIndex = function(index) {
this._validateNumber(index, 'index', 0, 2);
};
Blink1.prototype._readResponse = function(callback) {

@@ -149,3 +153,3 @@ if (this._isValidCallback(callback)) {

Blink1.prototype.degamma = function(n) {
return Math.floor(((1 << Math.floor(n / 32)) - 1) +
return Math.floor(((1 << Math.floor(n / 32)) - 1) +
Math.floor((1 << Math.floor(n / 32)) * Math.floor((n % 32) + 1) + 15) / 32);

@@ -155,3 +159,3 @@ };

Blink1.prototype.fadeToRGB = function(fadeMillis, r, g, b, callback) {
Blink1.prototype.fadeToRGB = function(fadeMillis, r, g, b, index, callback) {
this._validateFadeMillis(fadeMillis);

@@ -162,4 +166,14 @@ this._validateRGB(r, g, b);

this._sendCommand('c', this.degamma(r), this.degamma(g), this.degamma(b), dms >> 8, dms % 0xff);
if (this._isValidCallback(index)) {
// backwards compatible API, no index
callback = index;
index = 0;
} else if (index === undefined) {
index = 0;
}
this._validateIndex(index);
this._sendCommand('c', this.degamma(r), this.degamma(g), this.degamma(b), dms >> 8, dms % 0xff, index);
if(this._isValidCallback(callback)) {

@@ -180,2 +194,23 @@ setTimeout(callback, fadeMillis);

Blink1.prototype.rgb = function(index, callback) {
if (this._isValidCallback(index)) {
callback = index;
index = 0;
} else if (index === undefined) {
index = 0;
}
this._sendCommand('r', index, 0, 0, 0, 0, index);
this._readResponse(function(response) {
var r = response[2];
var g = response[3];
var b = response[4];
if(this._isValidCallback(callback)) {
callback(r, g, b);
}
});
};
Blink1.prototype._serverDown = function(on, millis, callback) {

@@ -237,3 +272,3 @@ var dms = millis / 10;

this._validatePosition(position);
this._sendCommand('R', 0, 0, 0, 0, 0, position, 0);

@@ -240,0 +275,0 @@

9

package.json
{
"name": "node-blink1",
"description": "A node.js library for the blink(1).",
"version": "0.1.2",
"version": "0.1.3",
"author": {

@@ -18,4 +18,4 @@ "name": "Sandeep Mistry",

"keywords": [
"blink(1)",
"blink1"
"blink(1)",
"blink1"
],

@@ -29,3 +29,4 @@ "dependencies": {

"should": "latest",
"mockery": "latest"
"mockery": "latest",
"async": "~0.9.0"
},

@@ -32,0 +33,0 @@ "scripts": {

@@ -46,7 +46,7 @@ node-blink1

Blink1.devices(); // returns array of serial numbers
Create blink(1) object without serial number, uses first device:
var blink1 = new Blink1();
Create blink(1) object with serial number, to get list of serial numbers use

@@ -59,16 +59,23 @@ `Blink1.devices()`:

blink1.version(callback(version))
blink1.version(callback(version));
__Set colors__
Fade to RGB, optional callback called after `fadeMillis` ms:
blink1.fadeToRGB(fadeMillis, r, g, b, [callback]) // r, g, b: 0 - 255
blink1.fadeToRGB(fadeMillis, r, g, b, [callback]); // r, g, b: 0 - 255
blink1.fadeToRGB(fadeMillis, r, g, b, [index, callback]); // r, g, b: 0 - 255
// index (mk2 only): 0 - 2
Set RGB:
blink1.setRGB(r, g, b, [callback]) // r, g, b: 0 - 255
blink1.setRGB(r, g, b, [callback]); // r, g, b: 0 - 255
Get RGB (mk2 only):
blink1.rgb([index,] callback(r, g, b));
__Other methods__
Set server down (enable, disable), optional callback called after `millis` ms:

@@ -79,3 +86,3 @@

blink1.disableServerDown(millis, [callback]) // off
Play (start playing the pattern lines at the specified position):

@@ -88,7 +95,14 @@

blink1.pause = function([callback])
Write pattern line (set the parameters for a pattern line, at the specified position):
blink1.writePatternLine(fadeMillis, r, g, b, position, [callback]) // r, g, b: 0 - 255
A simple example of this, used to flash red on & off is:
```javascript
blink1.writePatternLine(200, 255, 0, 0, 0);
blink1.writePatternLine(200, 0, 0, 0, 1);
blink1.play(0);
```
Read pattern line (at the position):

@@ -105,3 +119,3 @@

Copyright (C) 2013 Sandeep Mistry <sandeep.mistry@gmail.com>
Copyright (C) 2014 Sandeep Mistry <sandeep.mistry@gmail.com>

@@ -108,0 +122,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

@@ -302,2 +302,3 @@

var B = 40;
var INDEX = 1;

@@ -388,2 +389,24 @@ beforeEach(setupBlink1);

});
it('should throw an error when index is less than 0', function() {
(function(){
blink1.fadeToRGB(FADE_MILLIS, R, G, B, -1);
}).should.throwError('index must be between 0 and 2');
});
it('should throw an error when index is greater than 2', function() {
(function(){
blink1.fadeToRGB(FADE_MILLIS, R, G, B, 3);
}).should.throwError('index must be between 0 and 2');
});
it('should send fadetorgb index feature report', function() {
blink1.fadeToRGB(FADE_MILLIS, R, G, B, INDEX);
sentFeatureReport.should.eql([FEATURE_REPORT_ID, 0x63, blink1.degamma(R), blink1.degamma(G), blink1.degamma(B), (FADE_MILLIS / 10) >> 8, (FADE_MILLIS / 10) % 0xff, INDEX, 0]);
});
it('should call back (index)', function(done) {
blink1.fadeToRGB(FADE_MILLIS, blink1.degamma(R), blink1.degamma(G), blink1.degamma(B), INDEX, done);
});
});

@@ -464,2 +487,58 @@

describe('#Blink1.rgb', function() {
var INDEX = 1;
var R = 1;
var G = 2;
var B = 3;
beforeEach(function() {
setupBlink1();
recvFeatureReport = [FEATURE_REPORT_ID, 0x72, R, G, B, 0, 0, 0, 0];
});
afterEach(teardownBlink1);
it('should send rgb feature report', function() {
blink1.rgb();
sentFeatureReport.should.eql([FEATURE_REPORT_ID, 0x72, 0, 0, 0, 0, 0, 0, 0]);
});
it('should call back with r, g, b', function(done) {
blink1.rgb(function(r, g, b) {
done();
});
});
it('should call back with correct r, g, b', function(done) {
blink1.rgb(function(r, g, b) {
r.should.eql(R);
g.should.eql(G);
b.should.eql(B);
done();
});
});
it('should send rgb index feature report', function() {
blink1.rgb(INDEX);
sentFeatureReport.should.eql([FEATURE_REPORT_ID, 0x72, INDEX, 0, 0, 0, 0, INDEX, 0]);
});
it('should call back with r, g, b (index)', function(done) {
blink1.rgb(INDEX, function(r, g, b) {
done();
});
});
it('should call back with correct r, g, b (index)', function(done) {
blink1.rgb(INDEX, function(r, g, b) {
r.should.eql(R);
g.should.eql(G);
b.should.eql(B);
done();
});
});
});
describe('#Blink1.enableServerDown', function() {

@@ -466,0 +545,0 @@ var MILLIS = 10;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc