I wrote a quick test to repeatedly switch on every third led attached to a BlinkStick Pro, starting at the first, then the second, then third LED, then back to the first. This creates the impression of running lights.
The program runs for a few cycles, but then I will get an error:
H:\dev\node\pWinStatusBlinkStick\test.js:42
if (oError) throw oError;
^
Error: could not send feature report to device
at Error (native)
at retryTransfer (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:1311:29)
at BlinkStick.setFeatureReport (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:1337:5)
at BlinkStick.setColors (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:688:10)
at fSetColors (H:\dev\node\pWinStatusBlinkStick\test.js:41:15)
at H:\dev\node\pWinStatusBlinkStick\test.js:31:5
at Array.forEach (native)
at fRun [as _onTimeout] (H:\dev\node\pWinStatusBlinkStick\test.js:17:17)
at Timer.listOnTimeout (timers.js:110:15)
This is the code I’m using:
var mBlinkStick = require('blinkstick'),
aoBlinkSticks = mBlinkStick.findAll();
var uBlinkSticksModeChanged = 0;
var uWalkerIndex = 0;
aoBlinkSticks.forEach(function (oBlinkStick) {
oBlinkStick.setMode(2, function () {
if (++uBlinkSticksModeChanged == aoBlinkSticks.length) {
fRun();
};
});
});
function fRun() {
uWalkerIndex++;
var uBlinkSticksUpdated = 0;
aoBlinkSticks.forEach(function (oBlinkStick) {
var aauColors = [];
for (var uChannel = 0; uChannel < 3; uChannel++) {
var auColors = [];
for (var uIndex = 0; uIndex < 64; uIndex++) {
if (uIndex % 3 == uWalkerIndex % 3) {
auColors.push(255, 255, 255);
} else {
auColors.push(0, 0, 0);
};
};
aauColors.push(auColors);
};
console.log(uWalkerIndex);
fSetColors(oBlinkStick, aauColors, function () {
if (++uBlinkSticksUpdated == aoBlinkSticks.length) {
setTimeout(fRun, 100);
}
});
});
};
function fSetColors(oBlinkStick, aauColors, fCallback) {
var auColors = aauColors.pop(),
uChannel = aauColors.length;
oBlinkStick.setColors(uChannel, auColors, function(oError) {
if (oError) throw oError;
if (aauColors.length > 0) {
fSetColors(oBlinkStick, aauColors, fCallback);
} else {
fCallback();
};
});
};
setInterval("", 100000000); // do not exit!