From 2b80d7521183e2981954ba2b9cad64ed07824a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Mon, 26 Sep 2016 01:40:54 +0200 Subject: [PATCH] Make the test LED actually blink. --- usb/blink-test-led.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/usb/blink-test-led.js b/usb/blink-test-led.js index 3f284954..2c90c707 100755 --- a/usb/blink-test-led.js +++ b/usb/blink-test-led.js @@ -18,18 +18,22 @@ usbInterface.claim(); var endpointIn = usbInterface.endpoints[0]; var endpointOut = usbInterface.endpoints[1]; -var str = '0'; -console.log('Sending "%s"', str); -endpointOut.transfer(str, function(err) { - if (err) { - console.error("USB error: %s", err); - process.exit(1); - } - endpointIn.transfer(64, function(err2, receivedStr) { - if (err2) { - console.error("USB error: %s", err2); - process.exit(2); +var state = '1'; + +setInterval(function() { + console.log('Sending ', state); + state = state === '1' ? '0' : '1' + endpointOut.transfer(state, function(err) { + if (err) { + console.error("USB error: %s", err); + process.exit(1); } - console.log('Received "%s"', receivedStr); - }) -}); + endpointIn.transfer(64, function(err2, receivedStr) { + if (err2) { + console.error("USB error: %s", err2); + process.exit(2); + } + console.log('Received "%s"', receivedStr); + }) + }); +}, 500)