test-bigredbutton.js 853 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Interface with the Dream Cheeky Big Red button
  3. * http://dreamcheeky.com/big-red-button
  4. *
  5. * Uses info gleened from:
  6. * http://ddurdle.blogspot.com/2013/12/using-usb-big-red-button-panic-button.html
  7. *
  8. * @author Tod Kurt (https://github.com/todbot)
  9. */
  10. /*jslint node: true */
  11. "use strict";
  12. var HID = require('..');
  13. var device = new HID.HID(7476, 13);
  14. var buttonGetDataCmd = [ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 ];
  15. device.on('data', function(data) {
  16. var msg = '';
  17. var buttonState = data[0];
  18. if( buttonState === 0x17 ) {
  19. msg = "Lid opened!";
  20. } else if( buttonState === 0x16 ) {
  21. msg = "Button pushed!";
  22. } else if( buttonState === 0x15 ) {
  23. msg = "waiting...";
  24. }
  25. console.log('button data', data, msg);
  26. });
  27. setInterval( function() {
  28. device.write( buttonGetDataCmd );
  29. }, 100);