-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.js
57 lines (42 loc) · 1.13 KB
/
display.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Created by martin on 15.07.2015.
*/
"use strict";
var ws281x;
var winston = require('winston');
var NUM_LEDS = 7,
logger,
outputBuffer = new Uint32Array(NUM_LEDS),
pixelData = new Uint32Array(NUM_LEDS);
exports.NUM_LEDS = NUM_LEDS;
exports.PIXEL_DATA = pixelData;
exports.render = function() {
if (ws281x) {
outputBuffer.set(pixelData);
ws281x.render(outputBuffer);
}
};
exports.init = function(serverLogger) {
logger = serverLogger || winston;
ws281x = require('rpi-ws281x-native');
if (ws281x) {
logger.info("********* Initializing display *********");
ws281x.init(NUM_LEDS);
} else {
logger.warn("********* Display not available *********");
}
// ---- trap the SIGINT and reset before exit
process.on('SIGINT', function () {
ws281x.reset();
process.nextTick(function () { process.exit(0); });
});
//pixelData[0] = 0xffffff;
exports.render();
};
exports.color = function(value, led) {
pixelData[led | 0] = value;
if (ws281x) {
outputBuffer.set(pixelData);
ws281x.render(outputBuffer);
}
};