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.
- package/README.md +31 -29
- package/dist/dualsense.d.ts.map +1 -1
- package/dist/dualsense.js +13 -3
- package/dist/dualsense.js.map +1 -1
- package/dist/elements/analog.js +2 -2
- package/dist/elements/increment.d.ts +6 -0
- package/dist/elements/increment.d.ts.map +1 -0
- package/dist/elements/increment.js +15 -0
- package/dist/elements/increment.js.map +1 -0
- package/dist/elements/index.d.ts +2 -0
- package/dist/elements/index.d.ts.map +1 -1
- package/dist/elements/index.js +2 -0
- package/dist/elements/index.js.map +1 -1
- package/dist/elements/touch.d.ts +13 -0
- package/dist/elements/touch.d.ts.map +1 -0
- package/dist/elements/touch.js +22 -0
- package/dist/elements/touch.js.map +1 -0
- package/dist/elements/touchpad.d.ts +3 -6
- package/dist/elements/touchpad.d.ts.map +1 -1
- package/dist/elements/touchpad.js +4 -11
- package/dist/elements/touchpad.js.map +1 -1
- package/dist/elements/unisense.d.ts.map +1 -1
- package/dist/elements/unisense.js +2 -2
- package/dist/elements/unisense.js.map +1 -1
- package/dist/hid/dualsense_hid.d.ts +1 -1
- package/dist/hid/dualsense_hid.d.ts.map +1 -1
- package/dist/hid/dualsense_hid.js +7 -7
- package/dist/hid/dualsense_hid.js.map +1 -1
- package/dist/input.d.ts +2 -2
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +4 -4
- package/dist/input.js.map +1 -1
- package/docs/Analog.md +90 -81
- package/docs/AnalogParams.md +7 -7
- package/docs/Axis.md +79 -72
- package/docs/Brightness.md +3 -3
- package/docs/CommandScopeA.md +7 -7
- package/docs/CommandScopeB.md +6 -6
- package/docs/Dpad.md +81 -74
- package/docs/DpadParams.md +8 -8
- package/docs/DualSenseCommand.md +45 -45
- package/docs/Dualsense.md +90 -83
- package/docs/DualsenseHID.md +42 -47
- package/docs/DualsenseHIDState.md +41 -41
- package/docs/DualsenseParams.md +17 -17
- package/docs/Exports.md +19 -16
- package/docs/Haptic.md +1 -1
- package/docs/Home.md +31 -29
- package/docs/Increment.md +1554 -0
- package/docs/Indicator.md +2 -2
- package/docs/Input.md +79 -70
- package/docs/InputId.md +41 -41
- package/docs/InputParams.md +4 -4
- package/docs/LedOptions.md +4 -4
- package/docs/Momentary.md +77 -70
- package/docs/Motion.md +2 -2
- package/docs/Mute.md +79 -72
- package/docs/PlayerID.md +5 -5
- package/docs/PulseOptions.md +3 -3
- package/docs/Touch.md +1781 -0
- package/docs/Touchpad.md +94 -120
- package/docs/Trigger.md +82 -75
- package/docs/TriggerMode.md +10 -10
- package/docs/Unisense.md +81 -74
- package/docs/UnisenseParams.md +7 -7
- package/package.json +2 -2
- package/src/dualsense.ts +22 -4
- package/src/elements/analog.ts +2 -2
- package/src/elements/increment.ts +9 -0
- package/src/elements/index.ts +2 -0
- package/src/elements/touch.ts +16 -0
- package/src/elements/touchpad.ts +9 -23
- package/src/elements/unisense.ts +4 -2
- package/src/hid/dualsense_hid.ts +13 -7
- package/src/input.ts +8 -4
package/src/elements/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/elements/touchpad.ts
CHANGED
|
@@ -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
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
public readonly
|
|
22
|
-
public readonly
|
|
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.
|
|
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
|
}
|
package/src/elements/unisense.ts
CHANGED
|
@@ -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) *
|
|
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(
|
|
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
|
|
package/src/hid/dualsense_hid.ts
CHANGED
|
@@ -47,9 +47,9 @@ export interface DualsenseHIDState {
|
|
|
47
47
|
[InputId.AccelZ]: number;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// Maps a HID input of 0...
|
|
51
|
-
export function mapAxis(value: number): number {
|
|
52
|
-
return (2 /
|
|
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] = (
|
|
167
|
-
|
|
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] = (
|
|
171
|
-
|
|
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(
|
|
78
|
+
public next(
|
|
79
|
+
type: "press" | "release" | "change" = "change"
|
|
80
|
+
): Promise<IteratorResult<this>> {
|
|
79
81
|
return new Promise<IteratorResult<this>>((resolve) => {
|
|
80
|
-
this.once(
|
|
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(
|
|
91
|
+
public promise(
|
|
92
|
+
type: "press" | "release" | "change" = "change"
|
|
93
|
+
): Promise<this> {
|
|
90
94
|
return new Promise<this>((resolve) => {
|
|
91
|
-
this.once(
|
|
95
|
+
this.once(type, () => resolve(this));
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
98
|
|