porsager / busylight

node library for busylight
50 stars 17 forks source link

Unable to make busylight respond #13

Closed moozer closed 6 years ago

moozer commented 6 years ago

I seeing the "not responding" issue like in #9.

Could you supply a simple test.js, that works for you?

The device:

Dec  9 15:05:57 thinx kernel: [22922.118461] usb 1-6: new full-speed USB device number 24 using xhci_hcd
Dec  9 15:05:57 thinx kernel: [22922.261744] usb 1-6: New USB device found, idVendor=27bb, idProduct=3bca
Dec  9 15:05:57 thinx kernel: [22922.261749] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Dec  9 15:05:57 thinx kernel: [22922.261752] usb 1-6: Product: BUSYLIGHT
Dec  9 15:05:57 thinx kernel: [22922.261754] usb 1-6: Manufacturer: PLENOM APS
Dec  9 15:05:57 thinx kernel: [22922.263978] hid-generic 0003:27BB:3BCA.0011: hiddev1,hidraw2: USB HID v1.11 Device [PLENOM APS BUSYLIGHT] on usb-0000:00:14.0-6/input0

My test program

console.log("--- get --- ")
var busylight = require('busylight').get()
console.log(busylight)

console.log("--- light orange --- ")
busylight.light('orange')
console.log(busylight)
console.log("--- light orange done --- ")

the output below

$ nodejs test.js 
--- get --- 
Busylight {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  options: 
   [ { vendorId: 1240, productId: 63560 },
     { vendorId: 10171, productId: 15306 },
     { vendorId: 10171, productId: 15307 },
     { vendorId: 10171, productId: 15309 },
     vendorId: 10171 ],
  buffer: 
   [ 0,
     16,
     0,
     0,
     0,
     0,
     0,
     0,
     128,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     255,
     255,
     255,
     255,
     6,
     147 ],
  newProtocol: 10171,
  debug: false,
  connectAttempts: 0,
  getColorArray: [Function],
  _defaults: 
   { keepalive: true,
     color: [ 255, 255, 255 ],
     rate: 300,
     degamma: true,
     tone: 'OpenOffice',
     volume: 4 } }
--- light orange --- 
Busylight {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  options: 
   [ { vendorId: 1240, productId: 63560 },
     { vendorId: 10171, productId: 15306 },
     { vendorId: 10171, productId: 15307 },
     { vendorId: 10171, productId: 15309 },
     vendorId: 10171 ],
  buffer: 
   [ 0,
     16,
     0,
     0,
     0,
     0,
     0,
     0,
     128,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     0,
     255,
     255,
     255,
     255,
     6,
     147 ],
  newProtocol: 10171,
  debug: false,
  connectAttempts: 0,
  getColorArray: [Function],
  _defaults: 
   { keepalive: true,
     color: [ 255, 255, 255 ],
     rate: 300,
     degamma: true,
     tone: 'OpenOffice',
     volume: 4 } }
--- light orange done --- 

<and it hangs here>
porsager commented 6 years ago

Could you try to see if your busylight is listed when doing require('node-hid').devices() ?

moozer commented 6 years ago

Doing require('node-hid').devices() gives me an error related to node-hid not being installed - and since there are issues with npm not being in debian 9, I left it at that for now.

I have however solved my issue, it two problems combined. Permission and poor understanding of javascript :-)

I suspected the latter which is why I requested a simple test program. Brushing up on my javascript, I made a test program. It is included below for reference.

The other part is a permissions issue

# ls -al /dev/hidraw0
crw------- 1 root root 248, 0 Dec 14 23:08 /dev/hidraw0

which I read as not being allowed to talk directly with the device. I'm using Debian and my guess is that I must tweak a udev rule somewhere. When I log in as root, It works.

--

# cat test.js 
var busylight = require('busylight')

console.log( busylight.devices( true ) )

d = busylight.get()
d.debug = true

d.on('disconnected', function(err) {
  console.log(err);
});

d.on('connected', function() {

  console.log( "connected" )
  d.ring('Funky').blink(['red', 'yellow', 'blue', 'green'], 150);
});
porsager commented 6 years ago

Great you figured it out, and thanks a lot for reporting back ;)