Skip to content

Commit 2fa427a

Browse files
fix: add Xbox VID/PIDs and Share button mapping (#185)
1 parent 3c30e49 commit 2fa427a

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

src/js/gamepad-helper.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GamepadHelper {
2525
XBOX: 'xbox',
2626
PLAYSTATION: 'playstation',
2727
SWITCH: 'switch',
28-
STANDARD: 'standard'
28+
STANDARD: 'standard',
2929
};
3030

3131
/**
@@ -92,13 +92,15 @@ class GamepadHelper {
9292
gamepad_api_ids: [
9393
"Xbox 360 Controller (XInput STANDARD GAMEPAD)",
9494
],
95+
vendor_product_ids: ["045e:028e"],
9596
type: this.CONTROLLER_TYPES.XBOX
9697
},
9798
6: {
9899
name: "Xbox One/Series",
99100
gamepad_api_ids: [
100101
"HID-compliant game controller (STANDARD GAMEPAD Vendor: 045e Product: 0b13)",
101102
],
103+
vendor_product_ids: ["045e:02ea", "045e:0b12", "045e:0b13", "045e:0b20"],
102104
type: this.CONTROLLER_TYPES.XBOX
103105
},
104106
7: {
@@ -177,12 +179,13 @@ class GamepadHelper {
177179
14: 'DLeft',
178180
15: 'DRight',
179181
16: 'Home',
182+
17: 'Share',
180183
},
181184
axisMap: {
182185
0: 'Left Stick X',
183186
1: 'Left Stick Y',
184187
2: 'Right Stick X',
185-
3: 'Right Stick Y'
188+
3: 'Right Stick Y',
186189
}
187190
},
188191

@@ -212,7 +215,7 @@ class GamepadHelper {
212215
0: 'Left Stick X',
213216
1: 'Left Stick Y',
214217
2: 'Right Stick X',
215-
3: 'Right Stick Y'
218+
3: 'Right Stick Y',
216219
}
217220
},
218221

@@ -242,7 +245,7 @@ class GamepadHelper {
242245
0: 'Left Stick X',
243246
1: 'Left Stick Y',
244247
2: 'Right Stick X',
245-
3: 'Right Stick Y'
248+
3: 'Right Stick Y',
246249
}
247250
},
248251

@@ -253,7 +256,7 @@ class GamepadHelper {
253256
0: 'Axis 0',
254257
1: 'Axis 1',
255258
2: 'Axis 2',
256-
3: 'Axis 3'
259+
3: 'Axis 3',
257260
}
258261
}
259262
};
@@ -307,7 +310,8 @@ class GamepadHelper {
307310
13: 'D-Pad Down.svg',
308311
14: 'D-Pad Left.svg',
309312
15: 'D-Pad Right.svg',
310-
16: 'Home.svg'
313+
16: 'Home.svg',
314+
17: 'Share.svg',
311315
}
312316
},
313317
[this.CONTROLLER_TYPES.PLAYSTATION]: {
@@ -330,7 +334,7 @@ class GamepadHelper {
330334
14: 'D-Pad Left.svg',
331335
15: 'D-Pad Right.svg',
332336
16: 'Home.svg',
333-
17: 'Touch Pad Press.svg'
337+
17: 'Touch Pad Press.svg',
334338
}
335339
},
336340
[this.CONTROLLER_TYPES.SWITCH]: {
@@ -353,7 +357,7 @@ class GamepadHelper {
353357
14: 'Pro D-Pad Left.svg',
354358
15: 'Pro D-Pad Right.svg',
355359
16: 'Home.svg',
356-
17: 'Capture.svg'
360+
17: 'Capture.svg',
357361
}
358362
}
359363
};

tests/gamepad-helper.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ describe('GamepadHelper', () => {
5656
expect(helper.vendorProductLookup['054c:0ce6'].name).toBe('Sony DualSense (PS5)');
5757
expect(helper.vendorProductLookup['057e:2009'].name).toBe('Nintendo Switch Pro Controller');
5858
expect(helper.vendorProductLookup['1209:0001'].name).toBe('Generic Gamepad');
59+
expect(helper.vendorProductLookup['045e:028e'].name).toBe('Xbox 360');
60+
expect(helper.vendorProductLookup['045e:02ea'].name).toBe('Xbox One/Series');
61+
expect(helper.vendorProductLookup['045e:0b12'].name).toBe('Xbox One/Series');
62+
expect(helper.vendorProductLookup['045e:0b13'].name).toBe('Xbox One/Series');
63+
expect(helper.vendorProductLookup['045e:0b20'].name).toBe('Xbox One/Series');
5964
});
6065

6166
test('initializes controller mappings correctly', () => {
@@ -130,6 +135,18 @@ describe('GamepadHelper', () => {
130135
type: 'standard',
131136
name: 'Generic Gamepad'
132137
},
138+
{
139+
browserController: 'Firefox Xbox 360',
140+
gamepadId: '045e-028e-Sunshine (libvirtualhid) X-Box 360 Controller',
141+
type: 'xbox',
142+
name: 'Xbox 360'
143+
},
144+
{
145+
browserController: 'Firefox Xbox Series',
146+
gamepadId: '045e-0b13-Sunshine (libvirtualhid) X-Box Series Controller',
147+
type: 'xbox',
148+
name: 'Xbox One/Series'
149+
},
133150
{
134151
browserController: 'Chrome DualShock 4',
135152
gamepadId: 'HID VHF Driver (STANDARD GAMEPAD Vendor: 054c Product: 05c4)',
@@ -154,6 +171,24 @@ describe('GamepadHelper', () => {
154171
type: 'standard',
155172
name: 'Generic Gamepad'
156173
},
174+
{
175+
browserController: 'Chrome Xbox 360',
176+
gamepadId: 'Sunshine (libvirtualhid) X-Box 360 Controller (STANDARD GAMEPAD Vendor: 045e Product: 028e)',
177+
type: 'xbox',
178+
name: 'Xbox 360'
179+
},
180+
{
181+
browserController: 'Chrome Xbox One',
182+
gamepadId: 'Sunshine (libvirtualhid) X-Box One Controller (STANDARD GAMEPAD Vendor: 045e Product: 0b20)',
183+
type: 'xbox',
184+
name: 'Xbox One/Series'
185+
},
186+
{
187+
browserController: 'Chrome Xbox Series',
188+
gamepadId: 'Sunshine (libvirtualhid) X-Box Series Controller (STANDARD GAMEPAD Vendor: 045e Product: 0b13)',
189+
type: 'xbox',
190+
name: 'Xbox One/Series'
191+
},
157192
])('returns a VID/PID match for $browserController', ({ gamepadId, type, name }) => {
158193
expect(helper.getGamepadInfo(gamepadId)).toEqual({ type, name });
159194
});
@@ -201,6 +236,8 @@ describe('GamepadHelper', () => {
201236
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 0)).toBe('A');
202237
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 4)).toBe('LB');
203238
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 12)).toBe('DUp');
239+
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 17)).toBe('Share');
240+
expect(helper.getButtonName(helper.CONTROLLER_TYPES.XBOX, 18)).toBe('B18');
204241
});
205242

206243
test('returns correct button names for PlayStation controller', () => {
@@ -393,6 +430,11 @@ describe('GamepadHelper', () => {
393430
expect(path).toBe('/assets/img/gamepads/xbox/Buttons Outline/White/SVG/A.svg');
394431
});
395432

433+
test('returns the Share icon for Xbox button 17', () => {
434+
const path = helper.getButtonImagePath(helper.CONTROLLER_TYPES.XBOX, 17);
435+
expect(path).toBe('/assets/img/gamepads/xbox/Buttons Outline/White/SVG/Share.svg');
436+
});
437+
396438
test('returns correct path for PlayStation controller buttons', () => {
397439
const path = helper.getButtonImagePath(helper.CONTROLLER_TYPES.PLAYSTATION, 3);
398440
expect(path).toBe('/assets/img/gamepads/playstation/Buttons Outline/White/SVG/Triangle.svg');

0 commit comments

Comments
 (0)