Skip to content

Latest commit

 

History

History
361 lines (343 loc) · 12.3 KB

rumble_data_table.md

File metadata and controls

361 lines (343 loc) · 12.3 KB

The encoding algorithm for frequency is log2((double)freq/10.0)*32.0. The algorithm for amplitude is split in 3 range indexes (idx < 16, 16 <= idx < 32, idx < 128), it is:

// 32<= idx < 128
log2f(8.7f*amp)*32.0f

// 16 <= idx < 32
log2f(17.0f*amp)*16.0f

An example of code using it is:

//Float frequency to hex conversion
if (freq < 0.0f)
  freq = 0.0f;
else if (freq > 1252.0f)
  freq = 1252.0f;
uint8_t encoded_hex_freq = (uint8_t)round(log2((double)freq/10.0)*32.0);

//Convert to Joy-Con HF range. Range in big-endian: 0x0004-0x01FC with +0x0004 steps.
uint16_t hf = (encoded_hex_freq-0x60)*4;
//Convert to Joy-Con LF range. Range: 0x01-0x7F.
uint8_t lf = encoded_hex_freq-0x40;

// Float amplitude to hex conversion
uint8_t encoded_hex_amp = 0;
if(amp > 0.23f)
  encoded_hex_amp = (uint8_t)round(log2f(amp*8.7f)*32.f);
else if(amp > 0.12f)
  encoded_hex_amp = (uint8_t)round(log2f(amp*17.f)*16.f);
else{
  // TBD
}
uint16_t hf_amp = encoded_hex_amp * 2;    // encoded_hex_amp<<1;
uint8_t lf_amp = encoded_hex_amp / 2 + 64;// (encoded_hex_amp>>1)+0x40;

The high frequency and low amplitude are encoded and must always add the "control" byte to the HA/LF byte. An example is the following:

//Left linear actuator
uint16_t hf = 0x01a8; //Set H.Frequency
uint8_t hf_amp = 0x88; //Set H.Frequency amplitude
//Byte swapping
byte[0] = hf & 0xFF;
byte[1] = hf_amp + ((hf >> 8) & 0xFF); //Add amp + 1st byte of frequency to amplitude byte

uint8_t lf = 0x63; //Set L.Frequency
uint16_t lf_amp = 0x804d; //Set L.Frequency amplitude
//Byte swapping
byte[2] = lf + ((lf_amp >> 8) & 0xFF); //Add freq + 1st byte of LF amplitude to the frequency byte
byte[3] = lf_amp & 0xFF;

Frequency Table

Values # are in HEX.

HF Byte 0-1 # LF Byte 2 # Frequency (Hz) Frequency Rounded (Hz)
01 40.875885 41
02 41.77095 42
03 42.685616 43
04 43.620308 44
05 44.57547 45
06 45.551544 46
07 46.548996 47
08 47.568283 48
09 48.609894 49
0A 49.674313 50
0B 50.762039 51
0C 51.873581 52
0D 53.009464 53
0E 54.170223 54
0F 55.356396 55
10 56.568542 57
11 57.807232 58
12 59.073048 59
13 60.366577 60
14 61.688435 62
15 63.039234 63
16 64.419617 64
17 65.830215 66
18 67.271713 67
19 68.744774 69
1A 70.250084 70
1B 71.788361 72
1C 73.360321 73
1D 74.966705 75
1e 76.608261 77
1f 78.285767 78
20 80 80
04 00 21 81.75177 82
08 00 22 83.541901 84
0c 00 23 85.371231 85
10 00 24 87.240616 87
14 00 25 89.15094 89
18 00 26 91.103088 91
1c 00 27 93.097992 93
20 00 28 95.136566 95
24 00 29 97.219788 97
28 00 2a 99.348625 99
2c 00 2b 101.524078 102
30 00 2c 103.747162 104
34 00 2d 106.018929 106
38 00 2e 108.340446 108
3c 00 2f 110.712791 111
40 00 30 113.137085 113
44 00 31 115.614464 116
48 00 32 118.146095 118
4c 00 33 120.733154 121
50 00 34 123.376869 123
54 00 35 126.078468 126
58 00 36 128.839233 129
5c 00 37 131.660431 132
60 00 38 134.543427 135
64 00 39 137.489548 137
68 00 3a 140.500168 141
6c 00 3b 143.576721 144
70 00 3c 146.720642 147
74 00 3d 149.933411 150
78 00 3e 153.216522 153
7c 00 3f 156.571533 157
80 00 40 160 160
84 00 41 163.50354 164
88 00 42 167.083801 167
8c 00 43 170.742462 171
90 00 44 174.481232 174
94 00 45 178.30188 178
98 00 46 182.206177 182
9c 00 47 186.195984 186
a0 00 48 190.273132 190
a4 00 49 194.439575 194
a8 00 4a 198.69725 199
ac 00 4b 203.048157 203
b0 00 4c 207.494324 207
b4 00 4d 212.037857 212
b8 00 4e 216.680893 217
bc 00 4f 221.425583 221
c0 00 50 226.27417 226
c4 00 51 231.228928 231
c8 00 52 236.292191 236
cc 00 53 241.466309 241
d0 00 54 246.753738 247
d4 00 55 252.156937 252
d8 00 56 257.678467 258
dc 00 57 263.320862 263
e0 00 58 269.086853 269
e4 00 59 274.979095 275
e8 00 5a 281.000336 281
ec 00 5b 287.153442 287
f0 00 5c 293.441284 293
f4 00 5d 299.866821 300
f8 00 5e 306.433044 306
fc 00 5f 313.143066 313
00 01 60 320 320
04 01 61 327.00708 327
08 01 62 334.167603 334
0c 01 63 341.484924 341
10 01 64 348.962463 349
14 01 65 356.60376 357
18 01 66 364.412354 364
1c 01 67 372.391968 372
20 01 68 380.546265 381
24 01 69 388.87915 389
28 01 6a 397.394501 397
2c 01 6b 406.096313 406
30 01 6c 414.988647 415
34 01 6d 424.075714 424
38 01 6e 433.361786 433
3c 01 6f 442.851166 443
40 01 70 452.54834 453
44 01 71 462.457855 462
48 01 72 472.584381 473
4c 01 73 482.932617 483
50 01 74 493.507477 494
54 01 75 504.313873 504
58 01 76 515.356934 515
5c 01 77 526.641724 527
60 01 78 538.173706 538
64 01 79 549.958191 550
68 01 7a 562.000671 562
6c 01 7b 574.306885 574
70 01 7c 586.882568 587
74 01 7d 599.733643 600
78 01 7e 612.866089 613
7c 01 7f 626.286133 626
80 01 640 640
84 01 654.01416 654
88 01 668.335205 668
8c 01 682.969849 683
90 01 697.924927 698
94 01 713.20752 713
98 01 728.824707 729
9c 01 744.783936 745
a0 01 761.092529 761
a4 01 777.758301 778
a8 01 794.789001 795
ac 01 812.192627 812
b0 01 829.977295 830
b4 01 848.151428 848
b8 01 866.723572 867
bc 01 885.702332 886
c0 01 905.09668 905
c4 01 924.91571 925
c8 01 945.168762 945
cc 01 965.865234 966
d0 01 987.014954 987
d4 01 1008.627747 1009
d8 01 1030.713867 1031
dc 01 1053.283447 1053
e0 01 1076.347412 1076
e4 01 1099.916382 1100
e8 01 1124.001343 1124
ec 01 1148.61377 1149
f0 01 1173.765137 1174
f4 01 1199.467285 1199
f8 01 1225.732178 1226
fc 01 1252.572266 1253

Amplitude Table

HA Byte 1 # LA Byte 2-3 # Amplitude Amplitude Rounded
0 00 40 0.000000 0.000
2 80 40 0.007843 0.010
4 00 41 0.011823 0.012
6 80 41 0.014061 0.014
8 00 42 0.016720 0.017
0a 80 42 0.019885 0.020
0c 00 43 0.023648 0.024
0e 80 43 0.028123 0.028
10 00 44 0.033442 0.033
12 80 44 0.039771 0.040
14 00 45 0.047296 0.047
16 80 45 0.056246 0.056
18 00 46 0.066886 0.067
1a 80 46 0.079542 0.080
1c 00 47 0.094592 0.095
1e 80 47 0.112491 0.112
20 00 48 0.117471 0.117
22 80 48 0.122671 0.123
24 00 49 0.128102 0.128
26 80 49 0.133774 0.134
28 00 4a 0.139697 0.140
2a 80 4a 0.145882 0.146
2c 00 4b 0.152341 0.152
2e 80 4b 0.159085 0.159
30 00 4c 0.166129 0.166
32 80 4c 0.173484 0.173
34 00 4d 0.181166 0.181
36 80 4d 0.189185 0.189
38 00 4e 0.197561 0.198
3a 80 4e 0.206308 0.206
3c 00 4f 0.215442 0.215
3e 80 4f 0.224982 0.225
40 00 50 0.229908 0.230
42 80 50 0.234943 0.235
44 00 51 0.240087 0.240
46 80 51 0.245345 0.245
48 00 52 0.250715 0.251
4a 80 52 0.256206 0.256
4c 00 53 0.261816 0.262
4e 80 53 0.267549 0.268
50 00 54 0.273407 0.273
52 80 54 0.279394 0.279
54 00 55 0.285514 0.286
56 80 55 0.291765 0.292
58 00 56 0.298154 0.298
5a 80 56 0.304681 0.305
5c 00 57 0.311353 0.311
5e 80 57 0.318171 0.318
60 00 58 0.325138 0.325
62 80 58 0.332258 0.332
64 00 59 0.339534 0.340
66 80 59 0.346969 0.347
68 00 5a 0.354566 0.355
6a 80 5a 0.362331 0.362
6c 00 5b 0.370265 0.370
6e 80 5b 0.378372 0.378
70 00 5c 0.386657 0.387
72 80 5c 0.395124 0.395
74 00 5d 0.403777 0.404
76 80 5d 0.412619 0.413
78 00 5e 0.421652 0.422
7a 80 5e 0.430885 0.431
7c 00 5f 0.440321 0.440
7e 80 5f 0.449964 0.450
80 00 60 0.459817 0.460
82 80 60 0.469885 0.470
84 00 61 0.480174 0.480
86 80 61 0.490689 0.491
88 00 62 0.501433 0.501
8a 80 62 0.512413 0.512
8c 00 63 0.523633 0.524
8e 80 63 0.535100 0.535
90 00 64 0.546816 0.547
92 80 64 0.558790 0.559
94 00 65 0.571027 0.571
96 80 65 0.583530 0.584
98 00 66 0.596307 0.596
9a 80 66 0.609365 0.609
9c 00 67 0.622708 0.623
9e 80 67 0.636344 0.636
a0 00 68 0.650279 0.650
a2 80 68 0.664518 0.665
a4 00 69 0.679069 0.679
a6 80 69 0.693939 0.694
a8 00 6a 0.709133 0.709
aa 80 6a 0.724662 0.725
ac 00 6b 0.740529 0.741
ae 80 6b 0.756745 0.757
b0 00 6c 0.773316 0.773
b2 80 6c 0.790249 0.790
b4 00 6d 0.807554 0.808
b6 80 6d 0.825237 0.825
b8 00 6e 0.843307 0.843
ba 80 6e 0.861772 0.862
bc 00 6f 0.880643 0.881
be 80 6f 0.899928 0.900
c0 00 70 0.919633 0.920
c2 80 70 0.939771 0.940
c4 00 71 0.960348 0.960
c6 80 71 0.981378 0.981
c8 00 72 1.002867 1.003

The amplitudes below are not safe for the integrity of the linear resonant actuators.

HA Byte 1 # LA Byte 2-3 # Amplitude Amplitude Rounded
ca 80 72 1.024826 1.025
cc 00 73 1.047266 1.047
ce 80 73 1.070197 1.070
d0 00 74 1.093630 1.094
d2 80 74 1.117576 1.118
d4 00 75 1.142045 1.142
d6 80 75 1.167051 1.167
d8 00 76 1.192603 1.193
da 80 76 1.218715 1.219
dc 00 77 1.245398 1.245
de 80 77 1.272665 1.273
e0 00 78 1.300529 1.301
e2 80 78 1.329003 1.329
e4 00 79 1.358100 1.358
e6 80 79 1.387834 1.388
e8 00 7a 1.418218 1.418
ea 80 7a 1.449268 1.449
ec 00 7b 1.480997 1.481
ee 80 7b 1.513420 1.513
f0 00 7c 1.546553 1.547
f2 80 7c 1.580411 1.580
f4 00 7d 1.615010 1.615
f6 80 7d 1.650366 1.650
f8 00 7e 1.686497 1.686
fa 80 7e 1.723417 1.723
fc 00 7f 1.761146 1.761
fe 80 7f 1.799701 1.800