-
Notifications
You must be signed in to change notification settings - Fork 3
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
"HID write failed: {}" error shows up after connecting gamepad in browser #398
Comments
@HitBox38 Hey, thanks for opening an issue! I'll have some time to take a closer look tonight or tomorrow and attempt to replicate. I have a few more questions,
|
I will note that when checking if the controller is connected using the following I didn't even think about the rumble or LED updates I was just trying to get button inputs to get myself familiar with this library. |
I tested two controllers but couldn't replicate the HID write error on 5.1.8 with Opera 104.0.4944.36 / Chromium 118.0.5993.118 or Chrome 117.0.5938.149. However the HID writes are not working in the browser anyway, so I'll push a patch to disable them. I'll also try to set up a working example on github pages. I noticed that inputs were broken for one of the two devices... does it make a difference if you call edit: Nevermind, I was able to replicate it. When I include the suggested |
I didn't notice that edit: Wait what do you mean setWired? I thought browser works only with Bluetooth. edit 2: I don't get any inputs at all. How did you use import { create } from "zustand";
import { Dualsense } from "dualsense-ts";
const controller = new Dualsense();
interface ControllerState {
controller: Dualsense;
connected: boolean;
setConnected: (value: boolean) => void;
}
export const useControllerStore = create<ControllerState>((set) => ({
controller,
connected: controller.connection.state,
setConnected: (value: boolean) => set(() => ({ connected: value })),
})); |
Sorry for the trouble, here's a little more background on the wired/wireless issue... Early on I found that the format of the updates coming from the controller changed slightly depending on whether it was connected via bluetooth or USB. In Node.js there's a function for detecting the wired/wireless state, but in the browser I couldn't find a good solution. I settled for hardcoding the wireless connection style until I could come up with something. The other day when I tested using a much newer controller, the results were different - it's sending updates in the same format regardless of whether the connection is wired/wireless. This I think this might help: import { create } from "zustand";
import { Dualsense } from "dualsense-ts";
const controller = new Dualsense();
controller.hid.provider.setWired(); // Here
interface ControllerState {
controller: Dualsense;
connected: boolean;
setConnected: (value: boolean) => void;
}
export const useControllerStore = create<ControllerState>((set) => ({
controller,
connected: controller.connection.state,
setConnected: (value: boolean) => set(() => ({ connected: value })),
})); If that works, I will make this the default connection style. |
Nope still doesn't work still has the same issue wired or not. |
What's the number model on your controllers? maybe it is a compatibility issue? mine is CFI-ZCT1W. |
I get the same error, my controller is also CFI-ZCT1W |
@daniloarcidiacono Thank you for the extra data point 🙏🏻 Both of my controllers list "MODEL: CFI-ZCT1W" as well, but the older one has "FCC ID: AK8CFIZCT1" while the newer one shows "FCC ID: AK8CFIZCT1A". The label layout is also different. I'm going to test/prioritize the newer one from now on. I'm almost ready with a fix, will wrap up testing and get a patch up ASAP. Apologies for the delay on this, been trying to squeeze the change in between some travel. Really appreciate that you both reached out here, thanks so much for the patience!! |
@daniloarcidiacono @HitBox38 I released 5.2.0 which should solve the problem, please let me know if it helps 🙏🏻 Here's an example app that should react to analog inputs: https://nsfm.github.io/dualsense-ts/ |
Hmm, I guess the described issue technically isn't solved since the console error still appears. But at least inputs should be working as expected. Either way I'll leave this open and take another crack at webhid rumble support to deal with that. |
Hello @nsfm thanks for the quick response, now I receive data from the controller, however the mapping seems off.
Here's the component I use: import { useContext, useEffect, useState } from "react";
import { DualsenseContext } from "../../context/DualsenseContext";
export const ConnectionComponent = () => {
const controller = useContext(DualsenseContext);
const [connected, setConnected] = useState(controller.connection.state);
const [content, setContent] = useState('');
useEffect(() => {
controller.hid.on("error", console.error);
controller.connection.on("change", ({ state }) => setConnected(state));
controller.hid.register((data) => {
setContent(JSON.stringify(controller.hid.state, null, 2));
});
}, []);
return (
<>
<p>{`Controller ${connected ? "" : "dis"}connected`}</p>
<pre>
{content}
</pre>
</>
);
}; Also, this is what's reported on my controller: |
@daniloarcidiacono Oh boy, well at least it's progress... I don't think this will solve it, but earlier I suggested using Otherwise I think I'll need to collect some example events from your controller and compare to mine. Tonight I'll update the demo app to print this info, or add another debugging method to the library to help with future support requests. I know there have been some software updates for the controllers but I don't have a PS5 to try them myself, so possibly even my newer controller is out of date 😅 By the way, is it possible for you to try the library in node.js? I'm curious if the same issue applies there. Either way, thanks for the quick response! |
@nsfm, I don't call Let me know how I can help you debug this issue. |
Appreciate it 🙏🏻 If you're up for it, the object I'd like to inspect is the If you can edit this file in your node_modules to log |
@nsfm we had the same idea :) process(buffer) {
// Bluetooth buffer starts with an extra byte
console.clear();
console.log(buffer.toString('hex')); My findings (connected via Bluetooth): More in depth:
I could not "map" the playstation button, the mute button, and the touchpad. edit: yikes, the buffer via USB is very different!
I wonder how the PS5 still detects the Playstation button, mute button, touchpad even via Bluetooth, seems there's more than HID? |
It seems that the mapping is already correct for the USB case. The only thing that seems suspicius is the "Dpad" attribute which changes when pressing "Triangle", "Square", "Circle" or "Cross" (but "Up", "Down" etc... are not affected). edit: yes, there are some issues. If I press cross + up buttons, "Up" is set to false |
Super helpful. If the inputs are coming in a different order now, this is gonna be fun... Any chance you can paste over the byte strings or arrays? I can use them to recreate the buffers and set up some unit tests If it interests you there are a few extra comments around the unmapped bytes in the node HID provider: https://github.com/nsfm/dualsense-ts/blob/main/src/hid/node_hid_provider.ts#L98 For example the one that changes like crazy is probably the counter to help ensure messages are processed in the right order. The dpad and shapes buttons are all included in the same byte as individual bits, even if the format hasn't changed there's a good chance I made some mistake dealing with the masking/shifting there... But otherwise those accessory buttons and touch inputs do appear later in the buffer for me. So far the main difference between BT/USB has been some extra bytes at the beginning so it's been enough to just offset the buffer by a few bytes. If the order of the inputs has changed, that will definitely create some headaches, but hopefully some of the static bytes act as a flag for this... I'll also double check the dpad handling on my controllers and review the pydualsense library and linux drivers again tonight. If you play around with the hid_providers and find working arrangements for your controller, feel free to put up a PR and I'll test it on my end to see what we can do about compatibility! Decoding the buffers was equal parts fun and suffering when I worked on it last year, but I'd love to have another contributor! |
Hey @daniloarcidiacono, I just released version 5.3.0 which adds some extra debugging utilities. You can get the raw HID buffer now using I also updated the example app: https://nsfm.github.io/dualsense-ts/ Now it will show the input states, and a buffer you can copy/paste over here that will help me recreate the problem. There's also a slider for adjusting the byte offset that gets applied to the buffer - you might be able to guess and check different values to see if it corrects the mapping issue. Would you mind trying it out and sharing some usb/bluetooth buffer examples? I was also able to reproduce the dpad bug so I opened a new issue: #408 |
Oh, just saw your PR 😅 I'll review |
@HitBox38 Thanks to @daniloarcidiacono, the input problems should be resolved in version 5.4.0 🙏🏻 |
Describe the bug
After granting permission to connect a DualSense gamepad using
controller.hid.provider.getRequest()
the following error shows up:To Reproduce
Package version: 5.1.8
steps:
controller.hid.provider.getRequest()
.Expected behavior
Successful connection with no errors.
Additional context
ReactContext
like in the documentation and zustand (4.4.4) to check if it's a problem in my end.The text was updated successfully, but these errors were encountered: