Skip to content

Commit

Permalink
[MINOR] Fix HID mapping for all report styles; Fix dpad conflicts (#408
Browse files Browse the repository at this point in the history
…) (#406)

- Improve detection of connection type to resolve compatibility issues
- Enable gyroscope and accelerometer values for all controllers
- Fix mapping of gyroscope and accelerometer values
- Fix dpad conflicts with primary buttons
- Reset all inputs when the controller is disconnected

Many thanks to @daniloarcidiacono for making this change possible!

co-authored-by: Danilo Arcidiacono <[email protected]>
co-authored-by: Nate Dube <[email protected]>
  • Loading branch information
daniloarcidiacono and nsfm authored Nov 19, 2023
1 parent 862cf4c commit a468f8b
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 212 deletions.
29 changes: 17 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to `dualsense-ts`
# Contributing to `dualsense-ts`

Thanks for caring enough about this project to check out these guidelines - new contributors are always welcome!

Expand All @@ -10,8 +10,8 @@ Please let us know by opening an [issue](https://github.com/nsfm/dualsense-ts/is

### Dependencies

* node v16
* yarn
- node v16
- yarn

### Building and Testing

Expand All @@ -32,16 +32,21 @@ yarn test
# Run unit tests with code coverage
yarn coverage

# Run in debug mode, with live compilation and source mapping for the Inspector
# Run the node example app, with live compilation and source mapping for the Inspector
yarn debug

# Run the webhid example app at localhost:3000
# This will update automatically as you save changes to the app, but if you
# modify the core library you must stop the server and run `yarn build`
yarn --cwd webhid_example start
```

### Operating System

The project and tools have been tested on these operating systems:

* Arch Linux x64 (kernel 5.16.15 onwards)
* Ubuntu 20.04.4 x64
- Arch Linux x64 (kernel 5.16.15 onwards)
- Ubuntu 20.04.4 x64

If your system isn't covered here and everything works, please open a PR and let us know!

Expand All @@ -51,12 +56,12 @@ Changes facilitating compatibility with new platforms are always welcome.

This project prefers to maintain a minimal dependency footprint within the final build.

* `dependencies` will face scrutiny; they should demonstrate significant value and come from a stable source.
* `optionalDependencies` are preferred over `dependencies`.
* `devDependencies` should simplify or improve the dev experience.
- `dependencies` will face scrutiny; they should demonstrate significant value and come from a stable source.
- `optionalDependencies` are preferred over `dependencies`.
- `devDependencies` should simplify or improve the dev experience.

### PR Merge Requirements

* CI checks must pass
* Test coverage maintained where appropriate
* Change should improve the repo :+1:
- CI checks must pass
- Test coverage maintained where appropriate
- Change should improve the repo :+1:
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ for await (const { pressure } of controller.left.trigger) {
### Rumble Support
Only supported in node.js with a wireless connection.
Only supported in node.js over USB at this time.
```typescript
controller.rumble(1.0); // 100% rumble intensity
Expand Down Expand Up @@ -201,13 +201,9 @@ export const ControllerConnection = () => {

### It's not working

`controller.hid` manages the connection to the device and provides useful error events:
Try out the [example app](https://nsfm.github.io/dualsense-ts/)'s debugger to look for clues. Please open an issue on Github if you have questions or something doesn't seem right.

```typescript
controller.hid.on("error", console.error);
```

Please open an issue Github if you're having trouble.
If inputs are not working or wrong, use the debugger to view the report buffer and include this with your issue to help us reproduce the problem.

## Migration Guide

Expand All @@ -217,3 +213,5 @@ Please open an issue Github if you're having trouble.

- [CamTosh](https://github.com/CamTosh)'s [node-dualsense](https://github.com/CamTosh/node-dualsense)
- [flok](https://github.com/flok)'s [pydualsense](https://github.com/flok/pydualsense)
- [nondebug](https://github.com/nondebug)'s [dualsense reference](https://github.com/nondebug/dualsense)
- [Contributors to `dualsense-ts` on Github](https://github.com/nsfm/dualsense-ts/graphs/contributors)
9 changes: 8 additions & 1 deletion nodehid_example/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { TriggerMode } from "../src/hid";
function main() {
try {
const controller = new Dualsense();
console.log(`Connected: ${controller.toString()}`);

controller.connection.on("change", ({ state }) => {
console.log(
`Connected: ${state} ${
state ? (controller.hid.provider.wireless ? "bluetooth" : "usb") : ""
}`
);
});

controller.left.trigger.on("change", (trigger) => {
controller.left.rumble(trigger.magnitude);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"author": "Nate Dube <[email protected]> (https://ndube.com)",
"contributors": [
"CamTosh",
"nsfm"
"nsfm",
"daniloarcidiacono"
],
"license": "GPL-3.0",
"private": false,
Expand Down
2 changes: 2 additions & 0 deletions src/dualsense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ export class Dualsense extends Input<Dualsense> {

this.left.analog.x[InputSet](state[InputId.LeftAnalogX]);
this.left.analog.y[InputSet](state[InputId.LeftAnalogY]);
this.left.analog.button[InputSet](state[InputId.LeftAnalogButton]);
this.left.bumper[InputSet](state[InputId.LeftBumper]);
this.left.trigger[InputSet](state[InputId.LeftTrigger]);
this.left.trigger.button[InputSet](state[InputId.LeftTriggerButton]);

this.right.analog.x[InputSet](state[InputId.RightAnalogX]);
this.right.analog.y[InputSet](state[InputId.RightAnalogY]);
this.right.analog.button[InputSet](state[InputId.RightAnalogButton]);
this.right.bumper[InputSet](state[InputId.RightBumper]);
this.right.trigger[InputSet](state[InputId.RightTrigger]);
this.right.trigger.button[InputSet](state[InputId.RightTriggerButton]);
Expand Down
8 changes: 8 additions & 0 deletions src/hid/byte_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Byte buffer abstraction over Buffer (NodeJS) and DataView (web).
*/
export interface ByteArray {
length: number;
readUint8(offset: number): number;
readUint16LE(offset: number): number;
}
Loading

0 comments on commit a468f8b

Please sign in to comment.