-
Notifications
You must be signed in to change notification settings - Fork 12
/
dualsense-explorer.html
1149 lines (1006 loc) · 44.6 KB
/
dualsense-explorer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>DualSense Explorer</title>
</head>
<body>
<h1>DualSense Explorer</h1>
<p>
Use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API">WebHID API</a> to connect to a <a href="https://direct.playstation.com/en-us/accessories/accessory/dualsense-wireless-controller.3005715">Sony PlayStation 5 DualSense Wireless Controller</a>.
</p>
<h3>Instructions</h3>
<p>
Connect the controller to your computer using either <b>Bluetooth</b> or a <b>USB cable</b>.
</p>
<p>
Then, click <button type="button" onclick="requestDevice()">Connect DualSense</button>, select <b>Wireless Controller</b> and click the <b>Connect</b> button.
</p>
<p>
This page requires a Chromium-based browser like <a href="https://www.google.com/chrome/">Google Chrome</a> or <a href="https://www.microsoft.com/edge">Microsoft Edge</a>. It uses WebHID API, which is only available on Windows, macOS, chromeOS, and Linux.
</p>
<hr />
<h3>Device information</h3>
Connected device: <input type="text" id="productname" disabled /><br />
Vendor and Product ID: <input type="text" id="vidpid" style="width:100;" disabled /><br />
Connection type: <input type="text" id="connectiontype" style="width:100;" disabled /><br />
<hr />
<h3>Input report</h3>
<textarea id="inputreport" cols="48" rows="6" disabled></textarea><br />
<input type="checkbox" id="buttoncross" class="cb-disabled" disabled>Cross button</input><br />
<input type="checkbox" id="buttoncircle" disabled>Circle button</input><br />
<input type="checkbox" id="buttonsquare" disabled>Square button</input><br />
<input type="checkbox" id="buttontriangle" disabled>Triangle button</input><br />
<input type="checkbox" id="buttonl1" disabled>L1 button</input><br />
<input type="checkbox" id="buttonr1" disabled>R1 button</input><br />
<input type="checkbox" id="buttonl2" disabled/><input type="text" id="triggerl2" style="text-align:right; width:50;" disabled />L2 trigger<br />
<input type="checkbox" id="buttonr2" disabled/><input type="text" id="triggerr2" style="text-align:right; width:50;" disabled />R2 trigger<br />
<input type="checkbox" id="buttoncreate" disabled>Create button</input><br />
<input type="checkbox" id="buttonoptions" disabled>Options button</input><br />
<input type="checkbox" id="buttonl3" disabled>L3 button</input><br />
<input type="checkbox" id="buttonr3" disabled>R3 button</input><br />
<input type="checkbox" id="dpadup" disabled>Dpad up</input><br />
<input type="checkbox" id="dpaddown" disabled>Dpad down</input><br />
<input type="checkbox" id="dpadleft" disabled>Dpad left</input><br />
<input type="checkbox" id="dpadright" disabled>Dpad right</input><br />
<input type="checkbox" id="buttonps" disabled>PS button</input><br />
<input type="checkbox" id="buttontouchpad" disabled>Touchpad button</input><br />
<input type="checkbox" id="buttonmute" disabled>Mute button</input><br />
<input type="text" id="leftstickx" style="text-align:right; width:50;" disabled />Left thumbstick X<br />
<input type="text" id="leftsticky" style="text-align:right; width:50;" disabled />Left thumbstick Y<br />
<input type="text" id="rightstickx" style="text-align:right; width:50;" disabled />Right thumbstick X<br />
<input type="text" id="rightsticky" style="text-align:right; width:50;" disabled />Right thumbstick Y<br />
<input type="checkbox" id="touch0active" disabled>Touchpoint 0 active</input><br />
<input type="text" id="touch0id" style="text-align:right; width:50;" disabled />Touchpoint 0 ID<br />
<input type="text" id="touch0x" style="text-align:right; width:50;" disabled />Touchpoint 0 X<br />
<input type="text" id="touch0y" style="text-align:right; width:50;" disabled />Touchpoint 0 Y<br />
<input type="checkbox" id="touch1active" disabled>Touchpoint 1 active</input><br />
<input type="text" id="touch1id" style="text-align:right; width:50;" disabled />Touchpoint 1 ID<br />
<input type="text" id="touch1x" style="text-align:right; width:50;" disabled />Touchpoint 1 X<br />
<input type="text" id="touch1y" style="text-align:right; width:50;" disabled />Touchpoint 1 Y<br />
<input type="text" id="gyrox" style="text-align:right; width:50;" disabled />Gyroscope X<br />
<input type="text" id="gyroy" style="text-align:right; width:50;" disabled />Gyroscope Y<br />
<input type="text" id="gyroz" style="text-align:right; width:50;" disabled />Gyroscope Z<br />
<input type="text" id="accelx" style="text-align:right; width:50;" disabled />Accelerometer X<br />
<input type="text" id="accely" style="text-align:right; width:50;" disabled />Accelerometer Y<br />
<input type="text" id="accelz" style="text-align:right; width:50;" disabled />Accelerometer Z<br />
<input type="checkbox" id="l2force" disabled>L2 adaptive trigger effect</input><br />
<input type="text" id="l2state" style="text-align:right; width:50;" disabled />L2 trigger state<br />
<input type="checkbox" id="r2force" disabled>R2 adaptive trigger effect</input><br />
<input type="text" id="r2state" style="text-align:right; width:50;" disabled />R2 trigger state<br />
<input type="checkbox" id="batterycharging" disabled>Charging</input><br />
<input type="checkbox" id="batteryfull" disabled>Fully charged</input><br />
<input type="text" id="batterylevel" style="text-align:right; width:50;" disabled />Battery level<br />
<hr />
<h3>Output report</h3>
<textarea id="outputreport" cols="48" rows="6" disabled></textarea><br />
<input type="range" id="lightbarr" min="0" max="255" value="255">Lightbar Red<br />
<input type="range" id="lightbarg" min="0" max="255" value="255">Lightbar Green<br />
<input type="range" id="lightbarb" min="0" max="255" value="255">Lightbar Blue<br />
<input type="checkbox" id="playerLed1">Player LED 1<br />
<input type="checkbox" id="playerLed2">Player LED 2<br />
<input type="checkbox" id="playerLed3">Player LED 3<br />
<input type="checkbox" id="playerLed4">Player LED 4<br />
<input type="checkbox" id="playerLed5">Player LED 5<br />
<input type="checkbox" id="muteLed">Microphone Mute LED<br />
<input type="text" id="l2effectmode" style="text-align:right; width:50;" value="26" />L2 trigger effect mode<br />
<input type="text" id="l2effectparam1" style="text-align:right; width:50;" value="90" />L2 trigger effect parameter 1<br />
<input type="text" id="l2effectparam2" style="text-align:right; width:50;" value="A0" />L2 trigger effect parameter 2<br />
<input type="text" id="l2effectparam3" style="text-align:right; width:50;" value="FF" />L2 trigger effect parameter 3<br />
<input type="text" id="l2effectparam4" style="text-align:right; width:50;" />L2 trigger effect parameter 4<br />
<input type="text" id="l2effectparam5" style="text-align:right; width:50;" />L2 trigger effect parameter 5<br />
<input type="text" id="l2effectparam6" style="text-align:right; width:50;" />L2 trigger effect parameter 6<br />
<input type="text" id="l2effectparam7" style="text-align:right; width:50;" />L2 trigger effect parameter 7<br />
<input type="text" id="r2effectmode" style="text-align:right; width:50;" value="26" />R2 trigger effect mode<br />
<input type="text" id="r2effectparam1" style="text-align:right; width:50;" value="90" />R2 trigger effect parameter 1<br />
<input type="text" id="r2effectparam2" style="text-align:right; width:50;" value="A0" />R2 trigger effect parameter 2<br />
<input type="text" id="r2effectparam3" style="text-align:right; width:50;" value="FF" />R2 trigger effect parameter 3<br />
<input type="text" id="r2effectparam4" style="text-align:right; width:50;" />R2 trigger effect parameter 4<br />
<input type="text" id="r2effectparam5" style="text-align:right; width:50;" />R2 trigger effect parameter 5<br />
<input type="text" id="r2effectparam6" style="text-align:right; width:50;" />R2 trigger effect parameter 6<br />
<input type="text" id="r2effectparam7" style="text-align:right; width:50;" />R2 trigger effect parameter 7<br />
<script>
const VENDOR_ID_SONY = 0x054c;
const PRODUCT_ID_DUAL_SENSE = 0x0ce6;
const USAGE_PAGE_GENERIC_DESKTOP = 0x0001;
const USAGE_ID_GD_GAME_PAD = 0x0005;
// Expected report sizes, not including the report ID byte.
const DUAL_SENSE_USB_INPUT_REPORT_0x01_SIZE = 63;
const DUAL_SENSE_BT_INPUT_REPORT_0x01_SIZE = 9;
const DUAL_SENSE_BT_INPUT_REPORT_0x31_SIZE = 77;
const productNameText = document.getElementById('productname');
const vidPidText = document.getElementById('vidpid');
const connectionTypeText = document.getElementById('connectiontype');
const inputReportTextArea = document.getElementById('inputreport');
const buttonCrossCheckbox = document.getElementById('buttoncross');
const buttonCircleCheckbox = document.getElementById('buttoncircle');
const buttonSquareCheckbox = document.getElementById('buttonsquare');
const buttonTriangleCheckbox = document.getElementById('buttontriangle');
const buttonL1Checkbox = document.getElementById('buttonl1');
const buttonR1Checkbox = document.getElementById('buttonr1');
const buttonL2Checkbox = document.getElementById('buttonl2');
const buttonR2Checkbox = document.getElementById('buttonr2');
const triggerL2Text = document.getElementById('triggerl2');
const triggerR2Text = document.getElementById('triggerr2');
const buttonCreateCheckbox = document.getElementById('buttoncreate');
const buttonOptionsCheckbox = document.getElementById('buttonoptions');
const buttonL3Checkbox = document.getElementById('buttonl3');
const buttonR3Checkbox = document.getElementById('buttonr3');
const dpadUpCheckbox = document.getElementById('dpadup');
const dpadDownCheckbox = document.getElementById('dpaddown');
const dpadLeftCheckbox = document.getElementById('dpadleft');
const dpadRightCheckbox = document.getElementById('dpadright');
const buttonPSCheckbox = document.getElementById('buttonps');
const buttonTouchpadCheckbox = document.getElementById('buttontouchpad');
const buttonMuteCheckbox = document.getElementById('buttonmute');
const leftStickXText = document.getElementById('leftstickx');
const leftStickYText = document.getElementById('leftsticky');
const rightStickXText = document.getElementById('rightstickx');
const rightStickYText = document.getElementById('rightsticky');
const touch0ActiveCheckbox = document.getElementById('touch0active');
const touch0IdText = document.getElementById('touch0id');
const touch0XText = document.getElementById('touch0x');
const touch0YText = document.getElementById('touch0y');
const touch1ActiveCheckbox = document.getElementById('touch1active');
const touch1IdText = document.getElementById('touch1id');
const touch1XText = document.getElementById('touch1x');
const touch1YText = document.getElementById('touch1y');
const gyroXText = document.getElementById('gyrox');
const gyroYText = document.getElementById('gyroy');
const gyroZText = document.getElementById('gyroz');
const accelXText = document.getElementById('accelx');
const accelYText = document.getElementById('accely');
const accelZText = document.getElementById('accelz');
const l2ForceCheckbox = document.getElementById('l2force');
const l2StateText = document.getElementById('l2state');
const r2ForceCheckbox = document.getElementById('r2force');
const r2StateText = document.getElementById('r2state');
const batteryChargingCheckbox = document.getElementById('batterycharging');
const batteryFullCheckbox = document.getElementById('batteryfull');
const batteryLevelText = document.getElementById('batterylevel');
const outputReportTextArea = document.getElementById('outputreport');
const lightbarRedSlider = document.getElementById('lightbarr');
const lightbarGreenSlider = document.getElementById('lightbarg');
const lightbarBlueSlider = document.getElementById('lightbarb');
const playerLed1Checkbox = document.getElementById('playerLed1');
const playerLed2Checkbox = document.getElementById('playerLed2');
const playerLed3Checkbox = document.getElementById('playerLed3');
const playerLed4Checkbox = document.getElementById('playerLed4');
const playerLed5Checkbox = document.getElementById('playerLed5');
const muteLedCheckbox = document.getElementById('muteLed');
const l2EffectModeText = document.getElementById('l2effectmode');
const l2EffectParam1Text = document.getElementById('l2effectparam1');
const l2EffectParam2Text = document.getElementById('l2effectparam2');
const l2EffectParam3Text = document.getElementById('l2effectparam3');
const l2EffectParam4Text = document.getElementById('l2effectparam4');
const l2EffectParam5Text = document.getElementById('l2effectparam5');
const l2EffectParam6Text = document.getElementById('l2effectparam6');
const l2EffectParam7Text = document.getElementById('l2effectparam7');
const r2EffectModeText = document.getElementById('r2effectmode');
const r2EffectParam1Text = document.getElementById('r2effectparam1');
const r2EffectParam2Text = document.getElementById('r2effectparam2');
const r2EffectParam3Text = document.getElementById('r2effectparam3');
const r2EffectParam4Text = document.getElementById('r2effectparam4');
const r2EffectParam5Text = document.getElementById('r2effectparam5');
const r2EffectParam6Text = document.getElementById('r2effectparam6');
const r2EffectParam7Text = document.getElementById('r2effectparam7');
const hex8 = value => { return ('00' + (value >>> 0).toString(16)).substr(-2); };
const hex16 = value => { return ('0000' + (value >>> 0).toString(16)).substr(-4); };
const hex32 = value => { return ('00000000' + (value >>> 0).toString(16)).substr(-8); };
const parseHex = value => {
if (value == '')
return 0;
return parseInt(value, 16);
};
// Generate CRC32 lookup table.
const makeCRCTable = () => {
let c;
const crcTable = [];
for (let n = 0; n < 256; ++n) {
c = n;
for (let k = 0; k < 8; ++k)
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
crcTable[n] = (c >>> 0);
}
return crcTable;
};
// Compute CRC32 for `prefixBytes` concatenated with `dataView`.
const crc32 = (prefixBytes, dataView) => {
if (window.crcTable === undefined)
window.crcTable = makeCRCTable();
let crc = (-1 >>> 0);
for (const byte of prefixBytes)
crc = (crc >>> 8) ^ window.crcTable[(crc ^ byte) & 0xFF];
for (let i = 0; i < dataView.byteLength; ++i)
crc = (crc >>> 8) ^ window.crcTable[(crc ^ dataView.getUint8(i)) & 0xFF];
return (crc ^ (-1)) >>> 0;
};
// Given a DualSense Bluetooth output report with `reportId` and `reportData`,
// compute the CRC32 checksum and write it to the last four bytes of `reportData`.
const fillDualSenseChecksum = (reportId, reportData) => {
const crc = crc32([0xa2, reportId], new DataView(reportData.buffer, 0, reportData.byteLength - 4));
reportData[reportData.byteLength - 4] = (crc >>> 0) & 0xff;
reportData[reportData.byteLength - 3] = (crc >>> 8) & 0xff;
reportData[reportData.byteLength - 2] = (crc >>> 16) & 0xff;
reportData[reportData.byteLength - 1] = (crc >>> 24) & 0xff;
};
// Normalize an 8-bit thumbstick axis to the range [-1, +1].
const normalizeThumbStickAxis = value => {
return (2 * value / 0xFF) - 1.0;
};
// Normalize an 8-bit trigger axis to the range [0, +1].
const normalizeTriggerAxis = value => {
return value / 0xFF;
};
// Normalize a digital button value to the range [0, +1].
const normalizeButton = value => {
return value ? 1.0 : 0.0;
};
class DualSenseHid {
constructor(hidDevice) {
this.device_ = hidDevice;
this.connectionType_ = null;
// UI controls that affect the output report.
this.checkboxPlayerLeds_ = 0x00;
this.sliderLightbarRed_ = 0xFF;
this.sliderLightbarGreen_ = 0xFF;
this.sliderLightbarBlue_ = 0xFF;
// Output report state.
this.outputSeq_ = 1;
this.playerLeds_ = 0x00;
this.muteLed_ = 0x00;
this.motorLeft_ = 0x00;
this.motorRight_ = 0x00;
this.l2EffectMode_ = 0x26;
this.l2EffectParam1_ = 0x90;
this.l2EffectParam2_ = 0xA0;
this.l2EffectParam3_ = 0xFF;
this.l2EffectParam4_ = 0x00;
this.l2EffectParam5_ = 0x00;
this.l2EffectParam6_ = 0x00;
this.l2EffectParam7_ = 0x00;
this.r2EffectMode_ = 0x26;
this.r2EffectParam1_ = 0x90;
this.r2EffectParam2_ = 0xA0;
this.r2EffectParam3_ = 0xFF;
this.r2EffectParam4_ = 0x00;
this.r2EffectParam5_ = 0x00;
this.r2EffectParam6_ = 0x00;
this.r2EffectParam7_ = 0x00;
this.lightbarRed_ = 0xFF;
this.lightbarGreen_ = 0xFF;
this.lightbarBlue_ = 0xFF;
// WebHID API doesn't indicate whether we are connected through the controller's
// USB or Bluetooth interface. The protocol is different depending on the connection
// type so we will try to detect it based on the collection information.
this.connectionType_ = 'unknown';
for (const c of this.device_.collections) {
if (c.usagePage != USAGE_PAGE_GENERIC_DESKTOP || c.usage != USAGE_ID_GD_GAME_PAD)
continue;
// Compute the maximum input report byte length and compare against known values.
let maxInputReportBytes = c.inputReports.reduce((max, report) => {
return Math.max(max, report.items.reduce((sum, item) => { return sum + item.reportSize * item.reportCount; }, 0));
}, 0);
if (maxInputReportBytes == 504)
this.connectionType_ = 'usb';
else if (maxInputReportBytes == 616)
this.connectionType_ = 'bluetooth';
}
}
initialize() {
this.initializeUI();
this.device_.oninputreport = e => { this.onInputReport(e); }
}
async readFeatureReport05() {
// By default, bluetooth-connected DualSense only sends input report 0x01 which omits motion and touchpad data.
// Reading feature report 0x05 causes it to start sending input report 0x31.
//
// Note: The Gamepad API will do this for us if it enumerates the gamepad.
// Other applications like Steam may have also done this already.
if (this.connectionType_ == 'bluetooth')
await device.receiveFeatureReport(0x05);
}
initializeUI() {
const onPlayerLedsChanged = e => {
this.checkboxPlayerLeds_ = (playerLed1Checkbox.checked ? 0x01 : 0x00)
| (playerLed2Checkbox.checked ? 0x02 : 0x00)
| (playerLed3Checkbox.checked ? 0x04 : 0x00)
| (playerLed4Checkbox.checked ? 0x08 : 0x00)
| (playerLed5Checkbox.checked ? 0x10 : 0x00);
};
playerLed1Checkbox.onchange = onPlayerLedsChanged;
playerLed2Checkbox.onchange = onPlayerLedsChanged;
playerLed3Checkbox.onchange = onPlayerLedsChanged;
playerLed4Checkbox.onchange = onPlayerLedsChanged;
playerLed5Checkbox.onchange = onPlayerLedsChanged;
const onMuteLedChanged = e => {
this.muteLed_ = muteLedCheckbox.checked ? 0x01 : 0x00;
};
muteLedCheckbox.onchange = onMuteLedChanged;
const onLightbarColorChanged = e => {
this.sliderLightbarRed_ = lightbarRedSlider.value;
this.sliderLightbarGreen_ = lightbarGreenSlider.value;
this.sliderLightbarBlue_ = lightbarBlueSlider.value;
}
lightbarRedSlider.oninput = onLightbarColorChanged;
lightbarGreenSlider.oninput = onLightbarColorChanged;
lightbarBlueSlider.oninput = onLightbarColorChanged;
const onTriggerEffectChanged = e => {
this.l2EffectMode_ = parseHex(l2EffectModeText.value);
this.l2EffectParam1_ = parseHex(l2EffectParam1Text.value);
this.l2EffectParam2_ = parseHex(l2EffectParam2Text.value);
this.l2EffectParam3_ = parseHex(l2EffectParam3Text.value);
this.l2EffectParam4_ = parseHex(l2EffectParam4Text.value);
this.l2EffectParam5_ = parseHex(l2EffectParam5Text.value);
this.l2EffectParam6_ = parseHex(l2EffectParam6Text.value);
this.l2EffectParam7_ = parseHex(l2EffectParam7Text.value);
this.r2EffectMode_ = parseHex(r2EffectModeText.value);
this.r2EffectParam1_ = parseHex(r2EffectParam1Text.value);
this.r2EffectParam2_ = parseHex(r2EffectParam2Text.value);
this.r2EffectParam3_ = parseHex(r2EffectParam3Text.value);
this.r2EffectParam4_ = parseHex(r2EffectParam4Text.value);
this.r2EffectParam5_ = parseHex(r2EffectParam5Text.value);
this.r2EffectParam6_ = parseHex(r2EffectParam6Text.value);
this.r2EffectParam7_ = parseHex(r2EffectParam7Text.value);
}
l2EffectModeText.onchange = onTriggerEffectChanged;
l2EffectParam1Text.onchange = onTriggerEffectChanged;
l2EffectParam2Text.onchange = onTriggerEffectChanged;
l2EffectParam3Text.onchange = onTriggerEffectChanged;
l2EffectParam4Text.onchange = onTriggerEffectChanged;
l2EffectParam5Text.onchange = onTriggerEffectChanged;
l2EffectParam6Text.onchange = onTriggerEffectChanged;
l2EffectParam7Text.onchange = onTriggerEffectChanged;
r2EffectModeText.onchange = onTriggerEffectChanged;
r2EffectParam1Text.onchange = onTriggerEffectChanged;
r2EffectParam2Text.onchange = onTriggerEffectChanged;
r2EffectParam3Text.onchange = onTriggerEffectChanged;
r2EffectParam4Text.onchange = onTriggerEffectChanged;
r2EffectParam5Text.onchange = onTriggerEffectChanged;
r2EffectParam6Text.onchange = onTriggerEffectChanged;
r2EffectParam7Text.onchange = onTriggerEffectChanged;
}
onConnectionError() {
productNameText.value = '';
vidPidText.value = '';
connectionTypeText.value = '';
inputReportTextArea.value = '';
outputReportTextArea.value = '';
delete window.dshid;
}
handleUsbInputReport01(report) {
if (report.byteLength != DUAL_SENSE_USB_INPUT_REPORT_0x01_SIZE)
return;
let axes0 = report.getUint8(0);
let axes1 = report.getUint8(1);
let axes2 = report.getUint8(2);
let axes3 = report.getUint8(3);
let axes4 = report.getUint8(4);
let axes5 = report.getUint8(5);
let seqNum = report.getUint8(6);
let buttons0 = report.getUint8(7);
let buttons1 = report.getUint8(8);
let buttons2 = report.getUint8(9);
let buttons3 = report.getUint8(10);
let timestamp0 = report.getUint8(11);
let timestamp1 = report.getUint8(12);
let timestamp2 = report.getUint8(13);
let timestamp3 = report.getUint8(14);
let gyroX0 = report.getUint8(15);
let gyroX1 = report.getUint8(16);
let gyroY0 = report.getUint8(17);
let gyroY1 = report.getUint8(18);
let gyroZ0 = report.getUint8(19);
let gyroZ1 = report.getUint8(20);
let accelX0 = report.getUint8(21);
let accelX1 = report.getUint8(22);
let accelY0 = report.getUint8(23);
let accelY1 = report.getUint8(24);
let accelZ0 = report.getUint8(25);
let accelZ1 = report.getUint8(26);
let sensorTimestamp0 = report.getUint8(27);
let sensorTimestamp1 = report.getUint8(28);
let sensorTimestamp2 = report.getUint8(29);
let sensorTimestamp3 = report.getUint8(30);
// byte 31?
let touch00 = report.getUint8(32);
let touch01 = report.getUint8(33);
let touch02 = report.getUint8(34);
let touch03 = report.getUint8(35);
let touch10 = report.getUint8(36);
let touch11 = report.getUint8(37);
let touch12 = report.getUint8(38);
let touch13 = report.getUint8(39);
// byte 40?
let r2feedback = report.getUint8(41);
let l2feedback = report.getUint8(42);
// bytes 43-51?
let battery0 = report.getUint8(52);
let battery1 = report.getUint8(53);
// bytes 54-58?
// bytes 59-62 CRC32 checksum
let lsx = normalizeThumbStickAxis(axes0);
let lsy = normalizeThumbStickAxis(axes1);
let rsx = normalizeThumbStickAxis(axes2);
let rsy = normalizeThumbStickAxis(axes3);
let l2axis = normalizeTriggerAxis(axes4);
let r2axis = normalizeTriggerAxis(axes5);
let dpad = buttons0 & 0x0f;
let up = normalizeButton(dpad == 0 || dpad == 1 || dpad == 7);
let down = normalizeButton(dpad == 3 || dpad == 4 || dpad == 5);
let left = normalizeButton(dpad == 5 || dpad == 6 || dpad == 7);
let right = normalizeButton(dpad == 1 || dpad == 2 || dpad == 3);
let square = normalizeButton(buttons0 & 0x10);
let cross = normalizeButton(buttons0 & 0x20);
let circle = normalizeButton(buttons0 & 0x40);
let triangle = normalizeButton(buttons0 & 0x80);
let l1 = normalizeButton(buttons1 & 0x01);
let r1 = normalizeButton(buttons1 & 0x02);
let l2 = normalizeButton(buttons1 & 0x04);
let r2 = normalizeButton(buttons1 & 0x08);
let create = normalizeButton(buttons1 & 0x10);
let options = normalizeButton(buttons1 & 0x20);
let l3 = normalizeButton(buttons1 & 0x40);
let r3 = normalizeButton(buttons1 & 0x80);
let ps = normalizeButton(buttons2 & 0x01);
let touchpad = normalizeButton(buttons2 & 0x02);
let mute = normalizeButton(buttons2 & 0x04);
let touch0active = !(touch00 & 0x80);
let touch0id = (touch00 & 0x7F);
let touch0x = ((touch02 & 0x0F) << 8) | touch01;
let touch0y = (touch03 << 4) | ((touch02 & 0xF0) >> 4);
let touch1active = !(touch10 & 0x80);
let touch1id = (touch10 & 0x7F);
let touch1x = ((touch12 & 0x0F) << 8) | touch11;
let touch1y = (touch13 << 4) | ((touch12 & 0xF0) >> 4);
let gyrox = (gyroX1 << 8) | gyroX0;
if (gyrox > 0x7FFF) gyrox -= 0x10000;
let gyroy = (gyroY1 << 8) | gyroY0;
if (gyroy > 0x7FFF) gyroy -= 0x10000;
let gyroz = (gyroZ1 << 8) | gyroZ0;
if (gyroz > 0x7FFF) gyroz -= 0x10000;
let accelx = (accelX1 << 8) | accelX0;
if (accelx > 0x7FFF) accelx -= 0x10000;
let accely = (accelY1 << 8) | accelY0;
if (accely > 0x7FFF) accely -= 0x10000;
let accelz = (accelZ1 << 8) | accelZ0;
if (accelz > 0x7FFF) accelz -= 0x10000;
let batteryLevelPercent = (battery0 & 0x0f) * 100 / 8;
let batteryFull = !!(battery0 & 0x20);
let batteryCharging = !!(battery1 & 0x08);
buttonCrossCheckbox.checked = cross;
buttonCircleCheckbox.checked = circle;
buttonSquareCheckbox.checked = square;
buttonTriangleCheckbox.checked = triangle;
buttonL1Checkbox.checked = l1;
buttonR1Checkbox.checked = r1;
buttonL2Checkbox.checked = l2;
buttonR2Checkbox.checked = r2;
triggerL2Text.value = Math.round(l2axis * 100) + '%';
triggerR2Text.value = Math.round(r2axis * 100) + '%';
buttonCreateCheckbox.checked = create;
buttonOptionsCheckbox.checked = options;
buttonL3Checkbox.checked = l3;
buttonR3Checkbox.checked = r3;
dpadUpCheckbox.checked = up;
dpadDownCheckbox.checked = down;
dpadLeftCheckbox.checked = left;
dpadRightCheckbox.checked = right;
buttonPSCheckbox.checked = ps;
buttonTouchpadCheckbox.checked = touchpad;
buttonMuteCheckbox.checked = mute;
leftStickXText.value = Number(lsx).toFixed(2);
leftStickYText.value = Number(lsy).toFixed(2);
rightStickXText.value = Number(rsx).toFixed(2);
rightStickYText.value = Number(rsy).toFixed(2);
touch0ActiveCheckbox.checked = touch0active;
touch0IdText.value = touch0id;
touch0XText.value = touch0x;
touch0YText.value = touch0y;
touch1ActiveCheckbox.checked = touch1active;
touch1IdText.value = touch1id;
touch1XText.value = touch1x;
touch1YText.value = touch1y;
gyroXText.value = gyrox;
gyroYText.value = gyroy;
gyroZText.value = gyroz;
accelXText.value = accelx;
accelYText.value = accely;
accelZText.value = accelz;
l2ForceCheckbox.checked = l2feedback & 0x10;
l2StateText.value = l2feedback & 0x0F;
r2ForceCheckbox.checked = r2feedback & 0x10;
r2StateText.value = r2feedback & 0x0F;
batteryChargingCheckbox.checked = batteryCharging;
batteryFullCheckbox.checked = batteryFull;
batteryLevelText.value = batteryLevelPercent + '%';
}
handleBluetoothInputReport01(report) {
if (report.byteLength != DUAL_SENSE_BT_INPUT_REPORT_0x01_SIZE)
return;
let axes0 = report.getUint8(0);
let axes1 = report.getUint8(1);
let axes2 = report.getUint8(2);
let axes3 = report.getUint8(3);
let buttons0 = report.getUint8(4);
let buttons1 = report.getUint8(5);
let buttons2 = report.getUint8(6);
let axes4 = report.getUint8(7);
let axes5 = report.getUint8(8);
let lsx = normalizeThumbStickAxis(axes0);
let lsy = normalizeThumbStickAxis(axes1);
let rsx = normalizeThumbStickAxis(axes2);
let rsy = normalizeThumbStickAxis(axes3);
let l2axis = normalizeTriggerAxis(axes4);
let r2axis = normalizeTriggerAxis(axes5);
let dpad = buttons0 & 0x0f;
let up = normalizeButton(dpad == 0 || dpad == 1 || dpad == 7);
let down = normalizeButton(dpad == 3 || dpad == 4 || dpad == 5);
let left = normalizeButton(dpad == 5 || dpad == 6 || dpad == 7);
let right = normalizeButton(dpad == 1 || dpad == 2 || dpad == 3);
let square = normalizeButton(buttons0 & 0x10);
let cross = normalizeButton(buttons0 & 0x20);
let circle = normalizeButton(buttons0 & 0x40);
let triangle = normalizeButton(buttons0 & 0x80);
let l1 = normalizeButton(buttons1 & 0x01);
let r1 = normalizeButton(buttons1 & 0x02);
let l2 = normalizeButton(buttons1 & 0x04);
let r2 = normalizeButton(buttons1 & 0x08);
let create = normalizeButton(buttons1 & 0x10);
let options = normalizeButton(buttons1 & 0x20);
let l3 = normalizeButton(buttons1 & 0x40);
let r3 = normalizeButton(buttons1 & 0x80);
let ps = normalizeButton(buttons2 & 0x01);
let touchpad = normalizeButton(buttons2 & 0x02);
buttonCrossCheckbox.checked = cross;
buttonCircleCheckbox.checked = circle;
buttonSquareCheckbox.checked = square;
buttonTriangleCheckbox.checked = triangle;
buttonL1Checkbox.checked = l1;
buttonR1Checkbox.checked = r1;
buttonL2Checkbox.checked = l2;
buttonR2Checkbox.checked = r2;
triggerL2Text.value = Math.round(l2axis * 100) + '%';
triggerR2Text.value = Math.round(r2axis * 100) + '%';
buttonCreateCheckbox.checked = create;
buttonOptionsCheckbox.checked = options;
buttonL3Checkbox.checked = l3;
buttonR3Checkbox.checked = r3;
dpadUpCheckbox.checked = up;
dpadDownCheckbox.checked = down;
dpadLeftCheckbox.checked = left;
dpadRightCheckbox.checked = right;
buttonPSCheckbox.checked = ps;
buttonTouchpadCheckbox.checked = touchpad;
buttonMuteCheckbox.checked = false;
leftStickXText.value = Number(lsx).toFixed(2);
leftStickYText.value = Number(lsy).toFixed(2);
rightStickXText.value = Number(rsx).toFixed(2);
rightStickYText.value = Number(rsy).toFixed(2);
touch0ActiveCheckbox.checked = false;
touch0IdText.value = 'N/A';
touch0XText.value = '';
touch0YText.value = '';
touch1ActiveCheckbox.checked = false;
touch1IdText.value = 'N/A';
touch1XText.value = '';
touch1YText.value = '';
batteryChargingCheckbox.checked = false;
batteryFullCheckbox.checked = false;
batteryLevelText.value = 'N/A';
}
handleBluetoothInputReport31(report) {
if (report.byteLength != DUAL_SENSE_BT_INPUT_REPORT_0x31_SIZE)
return;
// byte 0?
let axes0 = report.getUint8(1);
let axes1 = report.getUint8(2);
let axes2 = report.getUint8(3);
let axes3 = report.getUint8(4);
let axes4 = report.getUint8(5);
let axes5 = report.getUint8(6);
// byte 7?
let buttons0 = report.getUint8(8);
let buttons1 = report.getUint8(9);
let buttons2 = report.getUint8(10);
// byte 11?
let timestamp0 = report.getUint8(12);
let timestamp1 = report.getUint8(13);
let timestamp2 = report.getUint8(14);
let timestamp3 = report.getUint8(15);
let gyroX0 = report.getUint8(16);
let gyroX1 = report.getUint8(17);
let gyroY0 = report.getUint8(18);
let gyroY1 = report.getUint8(19);
let gyroZ0 = report.getUint8(20);
let gyroZ1 = report.getUint8(21);
let accelX0 = report.getUint8(22);
let accelX1 = report.getUint8(23);
let accelY0 = report.getUint8(24);
let accelY1 = report.getUint8(25);
let accelZ0 = report.getUint8(26);
let accelZ1 = report.getUint8(27);
// bytes 28-32?
let touch00 = report.getUint8(33);
let touch01 = report.getUint8(34);
let touch02 = report.getUint8(35);
let touch03 = report.getUint8(36);
let touch10 = report.getUint8(37);
let touch11 = report.getUint8(38);
let touch12 = report.getUint8(39);
let touch13 = report.getUint8(40);
// byte 41?
let r2feedback = report.getUint8(42);
let l2feedback = report.getUint8(43);
// bytes 44-52?
let battery0 = report.getUint8(53);
let battery1 = report.getUint8(54);
// bytes 55-76?
let lsx = normalizeThumbStickAxis(axes0);
let lsy = normalizeThumbStickAxis(axes1);
let rsx = normalizeThumbStickAxis(axes2);
let rsy = normalizeThumbStickAxis(axes3);
let l2axis = normalizeTriggerAxis(axes4);
let r2axis = normalizeTriggerAxis(axes5);
let dpad = buttons0 & 0x0f;
let up = normalizeButton(dpad == 0 || dpad == 1 || dpad == 7);
let down = normalizeButton(dpad == 3 || dpad == 4 || dpad == 5);
let left = normalizeButton(dpad == 5 || dpad == 6 || dpad == 7);
let right = normalizeButton(dpad == 1 || dpad == 2 || dpad == 3);
let square = normalizeButton(buttons0 & 0x10);
let cross = normalizeButton(buttons0 & 0x20);
let circle = normalizeButton(buttons0 & 0x40);
let triangle = normalizeButton(buttons0 & 0x80);
let l1 = normalizeButton(buttons1 & 0x01);
let r1 = normalizeButton(buttons1 & 0x02);
let l2 = normalizeButton(buttons1 & 0x04);
let r2 = normalizeButton(buttons1 & 0x08);
let create = normalizeButton(buttons1 & 0x10);
let options = normalizeButton(buttons1 & 0x20);
let l3 = normalizeButton(buttons1 & 0x40);
let r3 = normalizeButton(buttons1 & 0x80);
let ps = normalizeButton(buttons2 & 0x01);
let touchpad = normalizeButton(buttons2 & 0x02);
let mute = normalizeButton(buttons2 & 0x04);
let touch0active = !(touch00 & 0x80);
let touch0id = (touch00 & 0x7F);
let touch0x = ((touch02 & 0x0F) << 8) | touch01;
let touch0y = (touch03 << 4) | ((touch02 & 0xF0) >> 4);
let touch1active = !(touch10 & 0x80);
let touch1id = (touch10 & 0x7F);
let touch1x = ((touch12 & 0x0F) << 8) | touch11;
let touch1y = (touch13 << 4) | ((touch12 & 0xF0) >> 4);
let gyrox = (gyroX1 << 8) | gyroX0;
if (gyrox > 0x7FFF) gyrox -= 0x10000;
let gyroy = (gyroY1 << 8) | gyroY0;
if (gyroy > 0x7FFF) gyroy -= 0x10000;
let gyroz = (gyroZ1 << 8) | gyroZ0;
if (gyroz > 0x7FFF) gyroz -= 0x10000;
let accelx = (accelX1 << 8) | accelX0;
if (accelx > 0x7FFF) accelx -= 0x10000;
let accely = (accelY1 << 8) | accelY0;
if (accely > 0x7FFF) accely -= 0x10000;
let accelz = (accelZ1 << 8) | accelZ0;
if (accelz > 0x7FFF) accelz -= 0x10000;
let batteryLevelPercent = (battery0 & 0x0f) * 100 / 8;
let batteryFull = !!(battery0 & 0x20);
let batteryCharging = !!(battery1 & 0x08);
buttonCrossCheckbox.checked = cross;
buttonCircleCheckbox.checked = circle;
buttonSquareCheckbox.checked = square;
buttonTriangleCheckbox.checked = triangle;
buttonL1Checkbox.checked = l1;
buttonR1Checkbox.checked = r1;
buttonL2Checkbox.checked = l2;
buttonR2Checkbox.checked = r2;
triggerL2Text.value = Math.round(l2axis * 100) + '%';
triggerR2Text.value = Math.round(r2axis * 100) + '%';
buttonCreateCheckbox.checked = create;
buttonOptionsCheckbox.checked = options;
buttonL3Checkbox.checked = l3;
buttonR3Checkbox.checked = r3;
dpadUpCheckbox.checked = up;
dpadDownCheckbox.checked = down;
dpadLeftCheckbox.checked = left;
dpadRightCheckbox.checked = right;
buttonPSCheckbox.checked = ps;
buttonTouchpadCheckbox.checked = touchpad;
buttonMuteCheckbox.checked = mute;
leftStickXText.value = Number(lsx).toFixed(2);
leftStickYText.value = Number(lsy).toFixed(2);
rightStickXText.value = Number(rsx).toFixed(2);
rightStickYText.value = Number(rsy).toFixed(2);
touch0ActiveCheckbox.checked = touch0active;
touch0IdText.value = touch0id;
touch0XText.value = touch0x;
touch0YText.value = touch0y;
touch1ActiveCheckbox.checked = touch1active;
touch1IdText.value = touch1id;
touch1XText.value = touch1x;
touch1YText.value = touch1y;
gyroXText.value = gyrox;
gyroYText.value = gyroy;
gyroZText.value = gyroz;
accelXText.value = accelx;
accelYText.value = accely;
accelZText.value = accelz;
l2ForceCheckbox.checked = l2feedback & 0x10;
l2StateText.value = l2feedback & 0x0F;
r2ForceCheckbox.checked = r2feedback & 0x10;
r2StateText.value = r2feedback & 0x0F;
batteryChargingCheckbox.checked = batteryCharging;
batteryFullCheckbox.checked = batteryFull;
batteryLevelText.value = batteryLevelPercent + '%';
}
onInputReport(event) {
let reportId = event.reportId;
let report = event.data;
let reportString = hex8(reportId);
for (let i = 0; i < report.byteLength; ++i)
reportString += ' ' + hex8(report.getUint8(i));
inputReportTextArea.value = reportString;
productNameText.value = event.device.productName;
vidPidText.value = hex16(event.device.vendorId) + ':' + hex16(event.device.productId);
connectionTypeText.value = this.connectionType_;
if (this.connectionType_ == 'usb') {
if (reportId == 0x01)
this.handleUsbInputReport01(report);
else
return;
} else if (this.connectionType_ == 'bluetooth') {
if (reportId == 0x01)
this.handleBluetoothInputReport01(report);
else if (reportId == 0x31)
this.handleBluetoothInputReport31(report);
else
return;
} else {
return;
}
}
async sendOutputReport() {
const pads = navigator.getGamepads();
this.lightbarRed_ = this.sliderLightbarRed_;
this.lightbarGreen_ = this.sliderLightbarGreen_;
this.lightbarBlue_ = this.sliderLightbarBlue_;
if (pads[0]) {
this.motorLeft_ = pads[0].buttons[6].value * 0xFF;
this.motorRight_ = pads[0].buttons[7].value * 0xFF;
if (pads[0].buttons[0].pressed) {
this.playerLeds_ = 0x04;
this.lightbarRed_ = 124;
this.lightbarGreen_ = 178;
this.lightbarBlue_ = 232;
} else if (pads[0].buttons[1].pressed) {
this.playerLeds_ = 0x0a;
this.lightbarRed_ = 255;
this.lightbarGreen_ = 102;
this.lightbarBlue_ = 102;
} else if (pads[0].buttons[2].pressed) {
this.playerLeds_ = 0x15;
this.lightbarRed_ = 255;
this.lightbarGreen_ = 105;
this.lightbarBlue_ = 248;
} else if (pads[0].buttons[3].pressed) {
this.playerLeds_ = 0x1b;
this.lightbarRed_ = 64;
this.lightbarGreen_ = 226;
this.lightbarBlue_ = 160;
} else {
this.playerLeds_ = this.checkboxPlayerLeds_;
}
}
let reportId;
let reportData;
let common;
let r2Effect;
let l2Effect;
if (this.connectionType_ == 'bluetooth') {
reportId = 0x31;
reportData = new Uint8Array(77);
// seq_tag
reportData[0] = (this.outputSeq_ << 4);
if (++this.outputSeq_ == 16)
this.outputSeq_ = 0;
// tag
reportData[1] = 0x10; // DS_OUTPUT_TAG
common = new DataView(reportData.buffer, 2, 47);
r2Effect = new DataView(common.buffer, 12, 8);
l2Effect = new DataView(common.buffer, 23, 8);
} else if (this.connectionType_ == 'usb') {
reportId = 0x02;
reportData = new Uint8Array(47);
common = new DataView(reportData.buffer, 0, 47);
r2Effect = new DataView(common.buffer, 10, 8);
l2Effect = new DataView(common.buffer, 21, 8);
}
// valid_flag0
// bit 0: COMPATIBLE_VIBRATION
// bit 1: HAPTICS_SELECT
common.setUint8(0, 0xff);
// valid_flag1
// bit 0: MIC_MUTE_LED_CONTROL_ENABLE
// bit 1: POWER_SAVE_CONTROL_ENABLE
// bit 2: LIGHTBAR_CONTROL_ENABLE
// bit 3: RELEASE_LEDS
// bit 4: PLAYER_INDICATOR_CONTROL_ENABLE
common.setUint8(1, 0xf7);
// DualShock 4 compatibility mode.
common.setUint8(2, this.motorRight_);
common.setUint8(3, this.motorLeft_);
// mute_button_led
// 0: mute LED off
// 1: mute LED on
common.setUint8(8, this.muteLed_);
// power_save_control
// bit 4: POWER_SAVE_CONTROL_MIC_MUTE
common.setUint8(9, this.muteLed_ ? 0x00 : 0x10);
// Right trigger effect
// Mode
// 0x00: off
// 0x01: mode1
// 0x02: mode2
// 0x05: mode1 + mode4
// 0x06: mode2 + mode4
// 0x21: mode1 + mode20
// 0x25: mode1 + mode4 + mode20
// 0x26: mode2 + mode4 + mode20
// 0xFC: calibration
r2Effect.setUint8(0, this.r2EffectMode_);
// Effect parameter 1
// start of resistance section
r2Effect.setUint8(1, this.r2EffectParam1_);
// Effect parameter 2
// mode1: amount of force exerted
// mode2: end of resistance section
// mode4 + mode20: flags
// bit 2: do not pause effect when fully pressed
r2Effect.setUint8(2, this.r2EffectParam2_);
// Effect parameter 3
// mode2: force exerted
r2Effect.setUint8(3, this.r2EffectParam3_);
// Effect effect parameter 4
// mode4 + mode20: strength near release state
r2Effect.setUint8(4, this.r2EffectParam4_);
// Effect parameter 5
// mode4 + mode20: strength near middle
r2Effect.setUint8(5, this.r2EffectParam5_);
// Effect parameter 6
// mode4 + mode20: at pressed state
r2Effect.setUint8(6, this.r2EffectParam6_);
// Effect parameter 7
// mode4 + mode20: effect actuation frequency in Hz
r2Effect.setUint8(7, this.r2EffectParam7_);
// Left trigger effect
// Mode
// 0x00: off
// 0x01: mode1
// 0x02: mode2
// 0x05: mode1 + mode4
// 0x06: mode2 + mode4
// 0x21: mode1 + mode20
// 0x25: mode1 + mode4 + mode20
// 0x26: mode2 + mode4 + mode20
// 0xFC: calibration
l2Effect.setUint8(0, this.l2EffectMode_);
// Effect parameter 1