Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dualshock 4 controller not registering events #28

Open
tiferrei opened this issue Nov 9, 2016 · 5 comments
Open

Dualshock 4 controller not registering events #28

tiferrei opened this issue Nov 9, 2016 · 5 comments

Comments

@tiferrei
Copy link

tiferrei commented Nov 9, 2016

Hello there, I opened an issue from my replies on issue #27, when I connect my Dualshock 4 controller to my Mac, wireless or with the cable, events are detected by cylon-joystick-explorer, however with this code:

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    joystick: { adaptor: 'joystick' }
  },

  devices: {
    controller: { driver: 'dualshock-4' }
  },

  work: function(my) {
    ["square", "circle", "x", "triangle"].forEach(function(button) {
      my.controller.on(button + ":press", function() {
        console.log("Button " + button + " pressed.");
      });

      my.controller.on(button + ":release", function() {
        console.log("Button " + button + " released.");
      });
    });

    my.controller.on("left_x:move", function(pos) {
      console.log("Left Stick - X:", pos);
    });

    my.controller.on("right_x:move", function(pos) {
      console.log("Right Stick - X:", pos);
    });

    my.controller.on("left_y:move", function(pos) {
      console.log("Left Stick - Y:", pos);
    });

    my.controller.on("right_y:move", function(pos) {
      console.log("Right Stick - Y:", pos);
    });
  }
}).start();

I only get the output:

[Robot 1] - Starting connections.
[Robot 1] - Starting connection 'joystick'.
[Robot 1] - Starting devices.
[Robot 1] - Starting device 'controller'.
[Robot 1] - Working.

Node Version: 7.0.0
macOS Version: 10.12.2 Beta (16C41b)

Am I doing something wrong in here?

Thank you,
tiferrei

@tiferrei
Copy link
Author

I have also tested this with the cable plugged into an Ubuntu VM, exactly the same thing happens.

@manoelfilho
Copy link

@tiferrei Resolved your issue? I am trying use the cylon-joystick com PS4 controller. It works with buttons, but with axis it goes into infnit loop. Ex: my.controller.on("right_x:move" ...

@tiferrei
Copy link
Author

@manoelfilho nope, still having issues with it.

@jamesrabbitt
Copy link

I'm having this issue on an intermittent basis with a DS3 connected via USB. Any solutions?

@Nobi322
Copy link

Nobi322 commented Sep 9, 2018

I fix similar problem by edit node_modules\cylon-joystick\lib\driver.js(47:7) commenting check by description && d.description === this.description. Because on my RPi dualshock is recognized like "Wireless Controller" but in config it's "PLAYSTATION(R)4 Controller".
So without this check it works perfect.

`/**

  • Starts event handlers for the gamepad
  • @param {Function} callback to be triggered when started
  • @return {void}
    */
    Driver.prototype.start = function(callback) {
    this.handleJoystickEvents();

var devices = this.connection.getDevices();

// assign first controller matching description
for (var i = 0; i < devices.length; i++) {
var d = devices[i];

var match = (
  d.productID.toString() === this.productID.toString() &&
  d.vendorID.toString() === this.vendorID.toString() /*&&
  d.description === this.description*/
);

if (match) {
  this.controllerId = d.deviceID;
  break;
}

}

callback();
};`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants