rumble_data_table.md

September 27, 2020 ยท View on GitHub

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)
0140.87588541
0241.7709542
0342.68561643
0443.62030844
0544.5754745
0645.55154446
0746.54899647
0847.56828348
0948.60989449
0A49.67431350
0B50.76203951
0C51.87358152
0D53.00946453
0E54.17022354
0F55.35639655
1056.56854257
1157.80723258
1259.07304859
1360.36657760
1461.68843562
1563.03923463
1664.41961764
1765.83021566
1867.27171367
1968.74477469
1A70.25008470
1B71.78836172
1C73.36032173
1D74.96670575
1e76.60826177
1f78.28576778
208080
04 002181.7517782
08 002283.54190184
0c 002385.37123185
10 002487.24061687
14 002589.1509489
18 002691.10308891
1c 002793.09799293
20 002895.13656695
24 002997.21978897
28 002a99.34862599
2c 002b101.524078102
30 002c103.747162104
34 002d106.018929106
38 002e108.340446108
3c 002f110.712791111
40 0030113.137085113
44 0031115.614464116
48 0032118.146095118
4c 0033120.733154121
50 0034123.376869123
54 0035126.078468126
58 0036128.839233129
5c 0037131.660431132
60 0038134.543427135
64 0039137.489548137
68 003a140.500168141
6c 003b143.576721144
70 003c146.720642147
74 003d149.933411150
78 003e153.216522153
7c 003f156.571533157
80 0040160160
84 0041163.50354164
88 0042167.083801167
8c 0043170.742462171
90 0044174.481232174
94 0045178.30188178
98 0046182.206177182
9c 0047186.195984186
a0 0048190.273132190
a4 0049194.439575194
a8 004a198.69725199
ac 004b203.048157203
b0 004c207.494324207
b4 004d212.037857212
b8 004e216.680893217
bc 004f221.425583221
c0 0050226.27417226
c4 0051231.228928231
c8 0052236.292191236
cc 0053241.466309241
d0 0054246.753738247
d4 0055252.156937252
d8 0056257.678467258
dc 0057263.320862263
e0 0058269.086853269
e4 0059274.979095275
e8 005a281.000336281
ec 005b287.153442287
f0 005c293.441284293
f4 005d299.866821300
f8 005e306.433044306
fc 005f313.143066313
00 0160320320
04 0161327.00708327
08 0162334.167603334
0c 0163341.484924341
10 0164348.962463349
14 0165356.60376357
18 0166364.412354364
1c 0167372.391968372
20 0168380.546265381
24 0169388.87915389
28 016a397.394501397
2c 016b406.096313406
30 016c414.988647415
34 016d424.075714424
38 016e433.361786433
3c 016f442.851166443
40 0170452.54834453
44 0171462.457855462
48 0172472.584381473
4c 0173482.932617483
50 0174493.507477494
54 0175504.313873504
58 0176515.356934515
5c 0177526.641724527
60 0178538.173706538
64 0179549.958191550
68 017a562.000671562
6c 017b574.306885574
70 017c586.882568587
74 017d599.733643600
78 017e612.866089613
7c 017f626.286133626
80 01640640
84 01654.01416654
88 01668.335205668
8c 01682.969849683
90 01697.924927698
94 01713.20752713
98 01728.824707729
9c 01744.783936745
a0 01761.092529761
a4 01777.758301778
a8 01794.789001795
ac 01812.192627812
b0 01829.977295830
b4 01848.151428848
b8 01866.723572867
bc 01885.702332886
c0 01905.09668905
c4 01924.91571925
c8 01945.168762945
cc 01965.865234966
d0 01987.014954987
d4 011008.6277471009
d8 011030.7138671031
dc 011053.2834471053
e0 011076.3474121076
e4 011099.9163821100
e8 011124.0013431124
ec 011148.613771149
f0 011173.7651371174
f4 011199.4672851199
f8 011225.7321781226
fc 011252.5722661253

Amplitude Table

HA Byte 1 #LA Byte 2-3 #AmplitudeAmplitude Rounded
000 400.0000000.000
280 400.0078430.010
400 410.0118230.012
680 410.0140610.014
800 420.0167200.017
0a80 420.0198850.020
0c00 430.0236480.024
0e80 430.0281230.028
1000 440.0334420.033
1280 440.0397710.040
1400 450.0472960.047
1680 450.0562460.056
1800 460.0668860.067
1a80 460.0795420.080
1c00 470.0945920.095
1e80 470.1124910.112
2000 480.1174710.117
2280 480.1226710.123
2400 490.1281020.128
2680 490.1337740.134
2800 4a0.1396970.140
2a80 4a0.1458820.146
2c00 4b0.1523410.152
2e80 4b0.1590850.159
3000 4c0.1661290.166
3280 4c0.1734840.173
3400 4d0.1811660.181
3680 4d0.1891850.189
3800 4e0.1975610.198
3a80 4e0.2063080.206
3c00 4f0.2154420.215
3e80 4f0.2249820.225
4000 500.2299080.230
4280 500.2349430.235
4400 510.2400870.240
4680 510.2453450.245
4800 520.2507150.251
4a80 520.2562060.256
4c00 530.2618160.262
4e80 530.2675490.268
5000 540.2734070.273
5280 540.2793940.279
5400 550.2855140.286
5680 550.2917650.292
5800 560.2981540.298
5a80 560.3046810.305
5c00 570.3113530.311
5e80 570.3181710.318
6000 580.3251380.325
6280 580.3322580.332
6400 590.3395340.340
6680 590.3469690.347
6800 5a0.3545660.355
6a80 5a0.3623310.362
6c00 5b0.3702650.370
6e80 5b0.3783720.378
7000 5c0.3866570.387
7280 5c0.3951240.395
7400 5d0.4037770.404
7680 5d0.4126190.413
7800 5e0.4216520.422
7a80 5e0.4308850.431
7c00 5f0.4403210.440
7e80 5f0.4499640.450
8000 600.4598170.460
8280 600.4698850.470
8400 610.4801740.480
8680 610.4906890.491
8800 620.5014330.501
8a80 620.5124130.512
8c00 630.5236330.524
8e80 630.5351000.535
9000 640.5468160.547
9280 640.5587900.559
9400 650.5710270.571
9680 650.5835300.584
9800 660.5963070.596
9a80 660.6093650.609
9c00 670.6227080.623
9e80 670.6363440.636
a000 680.6502790.650
a280 680.6645180.665
a400 690.6790690.679
a680 690.6939390.694
a800 6a0.7091330.709
aa80 6a0.7246620.725
ac00 6b0.7405290.741
ae80 6b0.7567450.757
b000 6c0.7733160.773
b280 6c0.7902490.790
b400 6d0.8075540.808
b680 6d0.8252370.825
b800 6e0.8433070.843
ba80 6e0.8617720.862
bc00 6f0.8806430.881
be80 6f0.8999280.900
c000 700.9196330.920
c280 700.9397710.940
c400 710.9603480.960
c680 710.9813780.981
c800 721.0028671.003

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

HA Byte 1 #LA Byte 2-3 #AmplitudeAmplitude Rounded
ca80 721.0248261.025
cc00 731.0472661.047
ce80 731.0701971.070
d000 741.0936301.094
d280 741.1175761.118
d400 751.1420451.142
d680 751.1670511.167
d800 761.1926031.193
da80 761.2187151.219
dc00 771.2453981.245
de80 771.2726651.273
e000 781.3005291.301
e280 781.3290031.329
e400 791.3581001.358
e680 791.3878341.388
e800 7a1.4182181.418
ea80 7a1.4492681.449
ec00 7b1.4809971.481
ee80 7b1.5134201.513
f000 7c1.5465531.547
f280 7c1.5804111.580
f400 7d1.6150101.615
f680 7d1.6503661.650
f800 7e1.6864971.686
fa80 7e1.7234171.723
fc00 7f1.7611461.761
fe80 7f1.7997011.800