dualsense-ts 2.0.13 → 2.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +31 -29
  2. package/dist/dualsense.d.ts.map +1 -1
  3. package/dist/dualsense.js +13 -3
  4. package/dist/dualsense.js.map +1 -1
  5. package/dist/elements/analog.js +2 -2
  6. package/dist/elements/increment.d.ts +6 -0
  7. package/dist/elements/increment.d.ts.map +1 -0
  8. package/dist/elements/increment.js +15 -0
  9. package/dist/elements/increment.js.map +1 -0
  10. package/dist/elements/index.d.ts +2 -0
  11. package/dist/elements/index.d.ts.map +1 -1
  12. package/dist/elements/index.js +2 -0
  13. package/dist/elements/index.js.map +1 -1
  14. package/dist/elements/touch.d.ts +13 -0
  15. package/dist/elements/touch.d.ts.map +1 -0
  16. package/dist/elements/touch.js +22 -0
  17. package/dist/elements/touch.js.map +1 -0
  18. package/dist/elements/touchpad.d.ts +3 -6
  19. package/dist/elements/touchpad.d.ts.map +1 -1
  20. package/dist/elements/touchpad.js +4 -11
  21. package/dist/elements/touchpad.js.map +1 -1
  22. package/dist/elements/unisense.d.ts.map +1 -1
  23. package/dist/elements/unisense.js +2 -2
  24. package/dist/elements/unisense.js.map +1 -1
  25. package/dist/hid/dualsense_hid.d.ts +1 -1
  26. package/dist/hid/dualsense_hid.d.ts.map +1 -1
  27. package/dist/hid/dualsense_hid.js +7 -7
  28. package/dist/hid/dualsense_hid.js.map +1 -1
  29. package/dist/input.d.ts +2 -2
  30. package/dist/input.d.ts.map +1 -1
  31. package/dist/input.js +4 -4
  32. package/dist/input.js.map +1 -1
  33. package/docs/Analog.md +90 -81
  34. package/docs/AnalogParams.md +7 -7
  35. package/docs/Axis.md +79 -72
  36. package/docs/Brightness.md +3 -3
  37. package/docs/CommandScopeA.md +7 -7
  38. package/docs/CommandScopeB.md +6 -6
  39. package/docs/Dpad.md +81 -74
  40. package/docs/DpadParams.md +8 -8
  41. package/docs/DualSenseCommand.md +45 -45
  42. package/docs/Dualsense.md +90 -83
  43. package/docs/DualsenseHID.md +42 -47
  44. package/docs/DualsenseHIDState.md +41 -41
  45. package/docs/DualsenseParams.md +17 -17
  46. package/docs/Exports.md +19 -16
  47. package/docs/Haptic.md +1 -1
  48. package/docs/Home.md +31 -29
  49. package/docs/Increment.md +1554 -0
  50. package/docs/Indicator.md +2 -2
  51. package/docs/Input.md +79 -70
  52. package/docs/InputId.md +41 -41
  53. package/docs/InputParams.md +4 -4
  54. package/docs/LedOptions.md +4 -4
  55. package/docs/Momentary.md +77 -70
  56. package/docs/Motion.md +2 -2
  57. package/docs/Mute.md +79 -72
  58. package/docs/PlayerID.md +5 -5
  59. package/docs/PulseOptions.md +3 -3
  60. package/docs/Touch.md +1781 -0
  61. package/docs/Touchpad.md +94 -120
  62. package/docs/Trigger.md +82 -75
  63. package/docs/TriggerMode.md +10 -10
  64. package/docs/Unisense.md +81 -74
  65. package/docs/UnisenseParams.md +7 -7
  66. package/package.json +2 -2
  67. package/src/dualsense.ts +22 -4
  68. package/src/elements/analog.ts +2 -2
  69. package/src/elements/increment.ts +9 -0
  70. package/src/elements/index.ts +2 -0
  71. package/src/elements/touch.ts +16 -0
  72. package/src/elements/touchpad.ts +9 -23
  73. package/src/elements/unisense.ts +4 -2
  74. package/src/hid/dualsense_hid.ts +13 -7
  75. package/src/input.ts +8 -4
@@ -7,9 +7,11 @@ export * from "./analog";
7
7
  export * from "./axis";
8
8
  export * from "./dpad";
9
9
  export * from "./gyroscope";
10
+ export * from "./increment";
10
11
  export * from "./momentary";
11
12
  export * from "./motion";
12
13
  export * from "./mute";
14
+ export * from "./touch";
13
15
  export * from "./touchpad";
14
16
  export * from "./trigger";
15
17
  export * from "./unisense";
@@ -0,0 +1,16 @@
1
+ import { Analog } from "./analog";
2
+ import { Increment } from "./increment";
3
+
4
+ /**
5
+ * Represents a touchpad touch, treated like an analog joystick input
6
+ * with [0,0] representing the center of the touchpad.
7
+ */
8
+ export class Touch extends Analog {
9
+ public readonly state: Touch = this;
10
+ public readonly contact = this.button;
11
+ public readonly tracker: Increment = new Increment();
12
+
13
+ public get active(): boolean {
14
+ return this.contact.active;
15
+ }
16
+ }
@@ -1,39 +1,25 @@
1
- import { Axis } from "./axis";
2
1
  import { Momentary } from "./momentary";
2
+ import { Touch } from "./touch";
3
3
  import { Input, InputParams } from "../input";
4
4
 
5
5
  export class Touchpad extends Input<Touchpad> {
6
6
  public readonly state: Touchpad = this;
7
7
 
8
8
  public get active(): boolean {
9
- return (
10
- this.x1.active ||
11
- this.y1.active ||
12
- this.x2.active ||
13
- this.y2.active ||
14
- this.button.active
15
- );
9
+ return this.left.contact.active;
16
10
  }
17
11
 
18
- public readonly x1;
19
- public readonly y1;
20
- public readonly x2;
21
- public readonly y2;
22
- public readonly button;
12
+ public readonly button: Momentary;
13
+
14
+ // Left is the default touch, outside multi-touch
15
+ public readonly left: Touch;
16
+ public readonly right: Touch;
23
17
 
24
18
  constructor(params: InputParams) {
25
19
  super(params);
26
20
 
27
21
  this.button = new Momentary({ icon: "[__]" });
28
-
29
- this.x1 = new Axis({ icon: "[X1]" });
30
-
31
- this.y1 = new Axis({ icon: "[Y1]" });
32
-
33
- this.x2 = new Axis({ icon: "[X2]" });
34
-
35
- this.y2 = new Axis({ icon: "[Y2]" });
22
+ this.left = new Touch();
23
+ this.right = new Touch();
36
24
  }
37
-
38
- public readonly direction: number = 0;
39
25
  }
@@ -26,13 +26,15 @@ export class Unisense extends Input<Unisense> {
26
26
  params?.trigger || {
27
27
  icon: "2",
28
28
  name: "Trigger",
29
- threshold: (1 / 255) * 6,
29
+ threshold: (1 / 255) * 3,
30
30
  }
31
31
  );
32
32
  this.bumper = new Momentary(
33
33
  params?.bumper || { icon: "1", name: "Bumper" }
34
34
  );
35
- this.analog = new Analog(params?.analog || { icon: "⨁", name: "Analog" });
35
+ this.analog = new Analog(
36
+ params?.analog || { icon: "⨁", name: "Analog", threshold: (1 / 128) * 3 }
37
+ );
36
38
  this.haptic = new Haptic();
37
39
  }
38
40
 
@@ -47,9 +47,9 @@ export interface DualsenseHIDState {
47
47
  [InputId.AccelZ]: number;
48
48
  }
49
49
 
50
- // Maps a HID input of 0...255 to -1...1
51
- export function mapAxis(value: number): number {
52
- return (2 / 255) * Math.max(0, Math.min(255, value)) - 1;
50
+ // Maps a HID input of 0...n to -1...1
51
+ export function mapAxis(value: number, max: number = 255): number {
52
+ return (2 / max) * Math.max(0, Math.min(max, value)) - 1;
53
53
  }
54
54
 
55
55
  // Maps a HID input of 0...255 to 0...1
@@ -163,12 +163,18 @@ export class DualsenseHID extends EventEmitter {
163
163
  // 1 reserved byte
164
164
  state[InputId.TouchId0] = report.readUint8(32) & 0x7f;
165
165
  state[InputId.TouchContact0] = (report.readUint8(32) & 0x80) === 0;
166
- state[InputId.TouchX0] = (report.readUint16LE(33) << 20) >> 20;
167
- state[InputId.TouchY0] = report.readUint16LE(34) >> 4;
166
+ state[InputId.TouchX0] = mapAxis(
167
+ (report.readUint16LE(33) << 20) >> 20,
168
+ 1920
169
+ );
170
+ state[InputId.TouchY0] = mapAxis(report.readUint16LE(34) >> 4, 1080);
168
171
  state[InputId.TouchId1] = report.readUint8(36) & 0x7f;
169
172
  state[InputId.TouchContact1] = (report.readUint8(36) & 0x80) === 0;
170
- state[InputId.TouchX1] = (report.readUint16LE(37) << 20) >> 20;
171
- state[InputId.TouchY1] = report.readUint16LE(38) >> 4;
173
+ state[InputId.TouchX1] = mapAxis(
174
+ (report.readUint16LE(37) << 20) >> 20,
175
+ 1920
176
+ );
177
+ state[InputId.TouchY1] = mapAxis(report.readUint16LE(38) >> 4, 1080);
172
178
  // 12 reserved bytes
173
179
  state[InputId.Status] = (report.readUint8(53) & 4) > 0;
174
180
 
package/src/input.ts CHANGED
@@ -75,9 +75,11 @@ export abstract class Input<Type>
75
75
  /**
76
76
  * Resolves on the next change to this input's state.
77
77
  */
78
- public next(): Promise<IteratorResult<this>> {
78
+ public next(
79
+ type: "press" | "release" | "change" = "change"
80
+ ): Promise<IteratorResult<this>> {
79
81
  return new Promise<IteratorResult<this>>((resolve) => {
80
- this.once("change", () => {
82
+ this.once(type, () => {
81
83
  resolve({ value: this, done: false });
82
84
  });
83
85
  });
@@ -86,9 +88,11 @@ export abstract class Input<Type>
86
88
  /**
87
89
  * Resolves on the next change to this input's state.
88
90
  */
89
- public promise(): Promise<this> {
91
+ public promise(
92
+ type: "press" | "release" | "change" = "change"
93
+ ): Promise<this> {
90
94
  return new Promise<this>((resolve) => {
91
- this.once("change", () => resolve(this));
95
+ this.once(type, () => resolve(this));
92
96
  });
93
97
  }
94
98