test-ps3-rumbleled.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Press Playstation button to start DS3 controller transmitting
  3. // After receiving data, press dpad left & right to trigger rumble
  4. // Press action buttons (triagle, square, etc) to change LEDs
  5. //
  6. /*jslint node: true */
  7. "use strict";
  8. var HID = require('..');
  9. var hid = new HID.HID(1356, 616);
  10. try {
  11. // note: this fails for bluetooth connections, so we catch
  12. console.log('features', hid.getFeatureReport(0xf2, 17));
  13. } catch(err) {
  14. console.log("couldn't send 0xf2 getFeature, on bluetooth?");
  15. }
  16. // from: https://github.com/ros-drivers/joystick_drivers/blob/indigo-devel/ps3joy/scripts/ps3joy_node.py
  17. function setRumbleLed(hidDevice, rumbleL, rumbleR, led_cmd )
  18. {
  19. // write output report with report id 0x01
  20. hidDevice.write([
  21. 0x01, // <- feature report id
  22. 0x00, 0xfe, rumbleL, 0xfe, rumbleR,
  23. 0x00, 0x00, 0x00, 0x00, led_cmd,
  24. 0xff, 0x27, 0x10, 0x00, 0x32,
  25. 0xff, 0x27, 0x10, 0x00, 0x32,
  26. 0xff, 0x27, 0x10, 0x00, 0x32,
  27. 0xff, 0x27, 0x10, 0x00, 0x32,
  28. 0x00, 0x00, 0x00, 0x00, 0x00,
  29. 0x00, 0x00, 0x00, 0x00, 0x00,
  30. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  31. ]);
  32. }
  33. hid.gotData = function (err, data) {
  34. console.log('got ps3 data', data);
  35. // map left & right d-pad to rumble, and right action buttons to LEDs
  36. setRumbleLed( hid, data[15], data[17], data[3]>>3 );
  37. this.read(this.gotData.bind(this));
  38. };
  39. hid.read(hid.gotData.bind(hid));
  40. /*
  41. * data is 48-byte Buffer with byte values:
  42. * index- info
  43. * 00 - unknown 0x01
  44. * 01 - unknown 0x00
  45. * 02 - start, select, dpad digital bitfield (see data[14]-[17] for analog values)
  46. * 03 - action button, shoulder, triggers digital bitfield (see data[18]-[25] for analog values)
  47. * 04 - playstation button
  48. * 05 -
  49. * 06 - left joystick analog left-right
  50. * 07 - left joystick analog up-down
  51. * 08 - right joystick analog left-right
  52. * 09 - right joystick analog up-down
  53. * 10,11,12,13 - unknown 0x00
  54. * 14 - dpad up analog pressure
  55. * 15 - dpad right analog pressure
  56. * 16 - dpad down analog pressure
  57. * 17 - dpad left analog pressure
  58. * 18 - left trigger analog pressure
  59. * 19 - right trigger analog pressure
  60. * 20 - left shoulder analog pressure
  61. * 21 - right shoulder analog pressure
  62. * 22 - triangle action analog pressure
  63. * 23 - cicle action analog pressure
  64. * 24 - X action analog pressure
  65. * 25 - square action analog pressure
  66. * 26,27,28
  67. * 29 - charge state
  68. * 30 - connection type
  69. * 31,32,33,34,35,36,37,38,39
  70. * 40,41 - X-axis accelerometer
  71. * 42,43 - Y-axis accelerometer
  72. * 44,45 - Z-axis accelerometer
  73. * 46,47 - Z-axis gyro
  74. */
  75. // from: https://github.com/ribbotson/USB-Host/blob/master/ps3/PS3USB/ps3_usb.h
  76. // from: https://code.google.com/p/openaxis/