diff --git a/usb/pulse-leds.js b/usb/pulse-leds.js index 038a47f4..fb9028f9 100755 --- a/usb/pulse-leds.js +++ b/usb/pulse-leds.js @@ -28,51 +28,142 @@ var state = 1; var ledsLeft = new Buffer(ledMatrixSize); var ledsRight = new Buffer(ledMatrixSize); +ledsLeft.fill(0) +ledsRight.fill(0) var ledIndex = 0; var matrixId = 0; +function disableUnusedLeds() { + var buffer = new Buffer([ + writeLedDriverCommandId, + leftLedDriverAddress, + 19, + 0, + 0, 0b00111111, + 0, 0b00111111, + 0, 0b00111111, + 0, 0b00011111, + 0, 0b00011111, + 0, 0b00011111, + 0, 0b00011111, + 0, 0b00011111, + 0, 0b00011111, + ]); + + endpointOut.transfer(buffer, function(err) { + if (err) { + console.error("USB error: %s", err); + process.exit(1); + } + updateLeds(); + }); +} + function updateLeds() { - console.log('update') - endpointOut.transfer(Buffer.concat([ +// console.log('update') + var buffer = Buffer.concat([ new Buffer([ writeLedDriverCommandId, matrixId ? rightLedDriverAddress : leftLedDriverAddress, ledCountToUpdatePerCommand, 0x24 + ledIndex ]), - (matrixId ? ledsRight : ledsLeft).slice(ledIndex, ledCountToUpdatePerCommand) - ]), function(err) { + (matrixId ? ledsRight : ledsLeft).slice(ledIndex, ledIndex + ledCountToUpdatePerCommand) + ]); + console.log('iter: '+i+' out:', util.bufferToString(buffer)) + endpointOut.transfer(buffer, function(err) { if (err) { console.error("USB error: %s", err); process.exit(1); } - console.log('update success') +// console.log('update success') endpointIn.transfer(64, function(err2, receivedBuffer) { if (err2) { console.error("USB error: %s", err2); process.exit(2); } - console.log('Received', util.bufferToString(receivedBuffer)); +// console.log('Received', util.bufferToString(receivedBuffer)); ledIndex += ledCountToUpdatePerCommand; if (ledIndex >= ledMatrixSize) { ledIndex = 0; + matrixId = matrixId ? 0 : 1; } - matrixId = matrixId ? 0 : 1; updateLeds(); }) }); } -updateLeds(); +disableUnusedLeds(); + var i = 0; -setInterval(function() { - console.log('iter') - ledsLeft.fill(0) + +var lettersLeds =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, 0, 1, 0, 0, 0, 1, 0], + N: [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0], + O: [1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1], + P: [1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0], + Q: [1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1], + R: [1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0], + S: [1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1], + T: [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + U: [0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1], + V: [0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], + W: [0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0], + X: [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0], + Y: [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0], + Z: [1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1], +} + +var iconLedsToLedMatrix = [0x08, 0x09, 0x0a]; +var layerLedsToLedMatrix = [0x0d, 0x1d, 0x2d]; + +var characterLedsToLedMatrix = [ + [0x0b, 0x1b, 0x29, 0x2a, 0x2b, 0x0c, 0x1c, 0x28, 0x1a, 0x2c, 0x38, 0x39, 0x18, 0x19], + [0x3a, 0x4a, 0x58, 0x59, 0x5a, 0x3b, 0x4b, 0x4c, 0x49, 0x5b, 0x5c, 0x68, 0x3c, 0x48], + [0x69, 0x79, 0x7c, 0x88, 0x89, 0x6a, 0x7a, 0x7b, 0x78, 0x8a, 0x8b, 0x8c, 0x6b, 0x6c] +] + +function setLetter(letterLeds, position) { + for (var i=0; i<14; i++) { + ledsLeft[characterLedsToLedMatrix[position][i]] = letterLeds[i] ? 0xff : 0; + } +} + +setLetter(lettersLeds['A'], 0); +setLetter(lettersLeds['B'], 1); +setLetter(lettersLeds['C'], 2); + +/*setInterval(function() { +// console.log('iter', i); + ledsLeft.fill(0); ledsLeft[i] = 0xff; if (++i >= ledMatrixSize) { i = 0; } -}, 100) +}, 100); +*/ \ No newline at end of file