rdepena / node-dualshock-controller

Eventing API layer over HID for the Sony DualShock 3 and DualShock 4 controllers
208 stars 46 forks source link

Bluetooth Connection issue #64

Open shubshub opened 7 years ago

shubshub commented 7 years ago

So I've been looking at a few different places on sending data to the Dualshock 4 over Bluetooth, I've done the CRC-32 Hash I've got the report ID and everything according to the program there are no errors, However nothing was happening when I did device.write(buff) atleast not from what I could see

I don't know if I was sending the data wrong if I was missing just the tiniest thing, but reading more into it according to what this is saying here http://www.spinics.net/lists/linux-input/msg29517.html

image

The last bit (The comments at the bottom) state that the USB stuff is output reports (Which I assume is the basic device.write since that worked perfectly over USB) and I'm guessing by SET_REPORT is a send Feature Report? as said here https://github.com/torvalds/linux/blob/7ae123edd37a47e178eb9a6631fe4a7108262c10/include/linux/hid.h#L738

Here is an image of the data I am trying to send to the Feature Report and also it failing image

I've also been reading over http://www.psdevwiki.com/ps4/DS4-BT However it has only been minimal help to me and hasn't actually helped me figure out what I am doing incorrectly.

If anyone or even you have any suggestions that would be excellent :)

Basically I am trying to set the LED lights on the Controller and also the rumble motors

17,128,0,255,4,0,45,47,18,18,18,255,255,0,0,0,0,0,0,0,0,0,67,67,0,77,133,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,233,3,16,74 rumbleLeft: 45, // 0-255 (Rumble left intensity)
rumbleRight: 47, // 0-255 (Rumble right intensity)
red: 18, // 0-255 (Red intensity)
green: 18, // 0-255 (Blue intensity)
blue: 18, // 0-255 (Green intensity)
flashOn: 255, // 0-255 (Flash on time)
flashOff: 255 // 0-255 (Flash off time)

todbot commented 7 years ago

Hi,

This repo: https://github.com/todbot/node-hid-ds4-test is an example of being able to set the rumble and LED on a DS4 over Bluetooth.

However, upon sending the output report to update the rumble & LED, the controller stops streaming data on reportId 1. It's unclear to me why this happens or how to restart it. Other drivers seem to switch to getting input data from reportId 11, but I've not seen exactly how to enable that either.

If anyone has further insight into what's going on, please help. Thanks!

shubshub commented 7 years ago

So I replicated what you did there however I seem to be getting a negative number on the last crc32 byte, Why is this happening? @todbot

Also I already know about the reportId 11 input thing I've solved that on my end you just read the controller data but ignore the first 2-3 bytes

todbot commented 7 years ago

it's not negative. These are bytes, not numbers. Javascript console output just represents them incorrectly.

Please post working code about how you solved it, when taking into account updating the rumble & LED.

shubshub commented 7 years ago

Idk what I'm doing wrong but your code doesn't do anything to my controller :/ Did it work for you?

Also for the ReportID 11 thing just do data.slice(2) and feed that into the button check

image This is my output and the controller stuff doesn't change at all

For what its worth it must be something else because it works flawlessly with DS4Windows but obviously I'm trying to make a game with this LED thing so I cant just use DS4Windows

Here is the code I used by the way,

CRC Code http://pastebin.com/KiazwqCu

this.setExtras = function(data) {
        device.getFeatureReport(0x02, 78); //Set the Report ID to 0x11 for the Input thingy
        let buff = Array(78-4).fill(0);
        //alert(JSON.stringify(data));
        /*Object.keys(data).forEach(k => {
            buff[indexes[k]] = data[k];
        });*/
        buff[0] = 0x11;
        buff[1] = 0x80;
        buff[3] = 0x0f;
        buff[6] = data["rumbleRight"];
        buff[7] = data["rumbleLeft"];
        buff[8] = data["red"];
        buff[9] = data["green"];
        buff[10] = data["blue"];
        buff[11] = data["flashOn"];
        buff[12] = data["flashOff"];
        //buff[4] = 0x04;
        //buff[22] = 0x43;
        //buff[23] = 0x43;
        //buff[25] = 0x4d;
        //buff[26] = 0x85;

        //alert(buff[0]);
        //alert(buff.length);
        var tempBuff = buff.slice(0);
        tempBuff.unshift(0xA2);
        var crc32 = calcAndDisplayCrc( tempBuff );
        console.log(crc32);
        //crc32 = new Uint8Array((new Int32Array([crc32])).buffer)
        buff[74] = crc32[3];//(crc32 & 0x000000ff) >> 0;
        buff[75] = crc32[2];//(crc32 & 0x0000ff00) >> 8;
        buff[76] = crc32[1];//(crc32 & 0x00ff0000) >> 16;
        buff[77] = crc32[0];//(crc32 & 0xff000000) >> 24;
        console.log(crc32);
        console.log("outbuf:","len:",buff.length, "vals:",buff.join(','));
        globalTempBuff = buff;
        //device.read(function(data){console.log(data)});
        //b4b57cf9
        //294A3A3323
        //let temp = buff;
        //temp.unshift(0x02)

image

At this rate I'm probably going to end up writing my own dualshock library :P with credit to @rdepena for any borrowed code

shubshub commented 7 years ago

I'm gonna have another crack at trying to figure this out when I get home tonight (roughly 6-12 hours) I know its not because of the bluetooth adapter because it works perfectly fine with DS4Windows but I cant figure out why, even after doing some debugging of the DS4Windows source didnt help that much (Except with the reportid 11 controller data stuff) If you wanna try and get it before me then please do share :D

shubshub commented 7 years ago

Did you have any luck? (Assuming it didn't already work with your own personal controller)

shubshub commented 7 years ago

I've updated my comment above with a code that you can just copy paste to test it if you want @todbot @rdepena

connorc0405 commented 7 years ago

@todbot Have you figured out how to receive input reports after setting rumble & LEDs?

Pecacheu commented 6 years ago

Moved comment to: https://github.com/node-hid/node-hid/issues/184#issuecomment-357082901

todbot commented 6 years ago

This sounds like an issue for hidapi then? I'd ask about it there https://github.com/signal11/hidapi (because node-hid is just a simple wrapper around hidapi)

Pecacheu commented 6 years ago

Okay, I'll move it to node-hid #184...