Skip to content

Commit 012d811

Browse files
authored
Merge pull request #91 from mumumusuc/mumumusuc-patch-1
Update rumble_data_table.md
2 parents c2f5e95 + d42fec8 commit 012d811

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

rumble_data_table.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
The encoding algorithm for frequency is log2((double)freq/10.0)*32.0.
2-
The algorithm for amplitude is split in 3 range indexes (idx < 16, 16 <= idx < 32, idx < 128) and it's currently undecoded.
2+
The algorithm for amplitude is split in 3 range indexes (idx < 16, 16 <= idx < 32, idx < 128), it is:
3+
```
4+
// 32<= idx < 128
5+
log2f(8.7f*amp)*32.0f
6+
7+
// 16 <= idx < 32
8+
log2f(17.0f*amp)*16.0f
9+
```
310

411
An example of code using it is:
512

@@ -15,6 +22,18 @@ uint8_t encoded_hex_freq = (uint8_t)round(log2((double)freq/10.0)*32.0);
1522
uint16_t hf = (encoded_hex_freq-0x60)*4;
1623
//Convert to Joy-Con LF range. Range: 0x01-0x7F.
1724
uint8_t lf = encoded_hex_freq-0x40;
25+
26+
// Float amplitude to hex conversion
27+
uint8_t encoded_hex_amp = 0;
28+
if(amp > 0.23f)
29+
encoded_hex_amp = (uint8_t)round(log2f(amp*8.7f)*32.f);
30+
else if(amp > 0.12f)
31+
encoded_hex_amp = (uint8_t)round(log2f(amp*17.f)*16.f);
32+
else{
33+
// TBD
34+
}
35+
uint16_t hf_amp = encoded_hex_amp * 2; // encoded_hex_amp<<1;
36+
uint8_t lf_amp = encoded_hex_amp / 2 + 64;// (encoded_hex_amp>>1)+0x40;
1837
```
1938

2039
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:

0 commit comments

Comments
 (0)