-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
21 lines (18 loc) · 869 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var test = require('tape')
var Ndarray = require('ndarray')
var repeat = require('repeat-array')
var equal = require('buffer-equal')
var apa102 = require('./')
// For example, to update all 30 LEDs on a 1-meter strip, you should send a 32-bit start frame, thirty 32-bit LED frames, and a 16-bit end frame, for a total of 1008 bits (126 bytes).
test('30 white pixels', function (t) {
var pixel = [0xFF, 0xFF, 0xFF]
var pixels = Ndarray(repeat(pixel, 30), [30, 3])
var result = apa102(pixels).slice()
t.ok(equal(result.slice(0, 4), Buffer([0x00, 0x00, 0x00, 0x00])), '32-bit start frame')
for (var i = 1; i < 1 + 30; i++) {
t.ok(equal(result.slice(i * 4, (i + 1) * 4), Buffer([0xFF, 0xFF, 0xFF, 0xFF])), '32-bit LED frame #' + i)
}
t.ok(equal(result.slice(i * 4), Buffer([0x00, 0x00])), '16-bit end frame')
t.equal(result.length, 126)
t.end()
})