bluetooth-mitm: playing around with rumble values

This commit is contained in:
ndeadly 2020-12-20 17:27:58 +01:00
parent 1160f7d0e0
commit 210dc5079f
6 changed files with 68 additions and 13 deletions

View file

@ -24,6 +24,11 @@ namespace ams::controller {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr uint8_t min_rumble_lf = 0x01;
constexpr uint8_t max_rumble_lf = 0x5f;
constexpr uint8_t min_rumble_hf = 0x30;
constexpr uint8_t max_rumble_hf = 0xbf;
const RGBColour player_led_colours[] = {
// Same colours used by PS4
{0x00, 0x00, 0x40}, // blue
@ -47,8 +52,8 @@ namespace ams::controller {
}
Result Dualshock4Controller::SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) {
m_rumble_state.amp_motor_left = left->low_band_amp; //(left->low_band_amp + left->high_band_amp) >> 1;
m_rumble_state.amp_motor_right = left->high_band_amp; //(right->low_band_amp + right->high_band_amp) >> 1;
m_rumble_state.amp_motor_left = ScaleRumbleAmplitude(left->low_band_amp, min_rumble_lf, max_rumble_lf); //left->low_band_amp; //(left->low_band_amp + left->high_band_amp) >> 1;
m_rumble_state.amp_motor_right = ScaleRumbleAmplitude(left->high_band_amp, min_rumble_hf, max_rumble_hf); //(right->low_band_amp + right->high_band_amp) >> 1;
return this->PushRumbleLedState();
}

View file

@ -71,16 +71,56 @@ namespace ams::controller {
0xf2, 0xf5, 0xf8, 0xfb, 0xff,
};
// Raw floats from dekunukem github
/*
const float rumble_amp_lut_f[] = {
0.000000, 0.007843, 0.011823, 0.014061, 0.016720, 0.019885, 0.023648,
0.028123, 0.033442, 0.039771, 0.047296, 0.056246, 0.066886, 0.079542,
0.094592, 0.112491, 0.117471, 0.122671, 0.128102, 0.133774, 0.139697,
0.145882, 0.152341, 0.159085, 0.166129, 0.173484, 0.181166, 0.189185,
0.197561, 0.206308, 0.215442, 0.224982, 0.229908, 0.234943, 0.240087,
0.245345, 0.250715, 0.256206, 0.261816, 0.267549, 0.273407, 0.279394,
0.285514, 0.291765, 0.298154, 0.304681, 0.311353, 0.318171, 0.325138,
0.332258, 0.339534, 0.346969, 0.354566, 0.362331, 0.370265, 0.378372,
0.386657, 0.395124, 0.403777, 0.412619, 0.421652, 0.430885, 0.440321,
0.449964, 0.459817, 0.469885, 0.480174, 0.490689, 0.501433, 0.512413,
0.523633, 0.535100, 0.546816, 0.558790, 0.571027, 0.583530, 0.596307,
0.609365, 0.622708, 0.636344, 0.650279, 0.664518, 0.679069, 0.693939,
0.709133, 0.724662, 0.740529, 0.756745, 0.773316, 0.790249, 0.807554,
0.825237, 0.843307, 0.861772, 0.880643, 0.899928, 0.919633, 0.939771,
0.960348, 0.981378, 1.002867
};
*/
// Above floats scaled by yuzu function
const float rumble_amp_lut_f[] = {
0.000000, 0.193414, 0.211610, 0.219983, 0.228816, 0.238172, 0.248099,
0.258665, 0.269941, 0.282030, 0.295028, 0.309064, 0.324277, 0.340847,
0.358972, 0.378893, 0.384185, 0.389610, 0.395176, 0.400887, 0.406749,
0.412766, 0.418945, 0.425292, 0.431815, 0.438519, 0.445413, 0.452500,
0.459793, 0.467298, 0.475023, 0.482979, 0.487045, 0.491172, 0.495360,
0.499613, 0.503928, 0.508311, 0.512760, 0.517278, 0.521865, 0.526524,
0.531257, 0.536062, 0.540943, 0.545900, 0.550937, 0.556054, 0.561253,
0.566536, 0.571904, 0.577359, 0.582902, 0.588537, 0.594264, 0.600084,
0.606001, 0.612016, 0.618132, 0.624351, 0.630671, 0.637100, 0.643638,
0.650287, 0.657049, 0.663926, 0.670921, 0.678037, 0.685275, 0.692639,
0.700131, 0.707754, 0.715510, 0.723403, 0.731435, 0.739608, 0.747926,
0.756393, 0.765010, 0.773782, 0.782712, 0.791802, 0.801056, 0.810477,
0.820069, 0.829837, 0.839782, 0.849910, 0.860224, 0.870727, 0.881424,
0.892319, 0.903416, 0.914719, 0.926234, 0.937964, 0.949912, 0.962086,
0.974488, 0.987125, 1.000000
};
inline void DecodeRumbleValues(const uint8_t enc[], SwitchRumbleData *dec) {
uint8_t hi_freq_ind = 0x20 + (enc[0] >> 2) + ((enc[1] & 0x01) * 0x40) - 1;
uint8_t hi_amp_ind = (enc[1] & 0xfe) >> 1;
uint8_t lo_freq_ind = (enc[2] & 0x7f) - 1;;
uint8_t lo_amp_ind = ((enc[3] - 0x40) << 1) + ((enc[2] & 0x80) >> 7);
dec->high_band_freq = rumble_freq_lut[hi_freq_ind];
dec->high_band_amp = rumble_amp_lut[hi_amp_ind];
dec->low_band_freq = rumble_freq_lut[lo_freq_ind];
dec->low_band_amp = rumble_amp_lut[lo_amp_ind];
dec->high_band_freq = float(rumble_freq_lut[hi_freq_ind]);
dec->high_band_amp = rumble_amp_lut_f[hi_amp_ind];
dec->low_band_freq = float(rumble_freq_lut[lo_freq_ind]);
dec->low_band_amp = rumble_amp_lut_f[lo_amp_ind];
}
}

View file

@ -18,6 +18,10 @@
namespace ams::controller {
inline uint8_t ScaleRumbleAmplitude(float amp, uint8_t lower, uint8_t upper) {
return amp > 0.0 ? static_cast<uint8_t>(amp * (upper - lower) + lower) : 0;
}
class EmulatedSwitchController : public SwitchController {
public:

View file

@ -93,10 +93,10 @@ namespace ams::controller {
} __attribute__ ((__packed__));
struct SwitchRumbleData {
uint16_t high_band_freq;
uint8_t high_band_amp;
uint16_t low_band_freq;
uint8_t low_band_amp;
float high_band_freq;
float high_band_amp;
float low_band_freq;
float low_band_amp;
} __attribute__ ((__packed__));
enum SubCmdType : uint8_t {

View file

@ -348,7 +348,7 @@ namespace ams::controller {
}
Result WiiController::SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) {
m_rumble_state = left->low_band_amp || left->high_band_amp;
m_rumble_state = left->low_band_amp > 0 || left->high_band_amp > 0;
s_output_report.size = sizeof(WiiOutputReport0x10) + 1;
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);

View file

@ -21,8 +21,14 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT16_MAX;
constexpr uint8_t min_rumble_lf = 0x03;
constexpr uint8_t max_rumble_lf = 0x5f;
constexpr uint8_t min_rumble_hf = 0x10; //0x03;
constexpr uint8_t max_rumble_hf = 0xbf; //0x7f;
}
}
@ -32,8 +38,8 @@ namespace ams::controller {
s_output_report.size = sizeof(XboxOneOutputReport0x03) + 1;
report->id = 0x03;
report->output0x03.enable = 0x3;
report->output0x03.magnitude_strong = left->low_band_amp; //static_cast<uint8_t>(100 * 0.5 * (left->low_band_amp + left->high_band_amp) / UINT8_MAX);
report->output0x03.magnitude_weak = left->high_band_amp; //static_cast<uint8_t>(100 * 0.5 * (left->high_band_amp + right->high_band_amp) / UINT8_MAX);
report->output0x03.magnitude_strong = ScaleRumbleAmplitude(left->low_band_amp, min_rumble_lf, max_rumble_lf); //left->low_band_amp; //static_cast<uint8_t>(100 * 0.5 * (left->low_band_amp + left->high_band_amp) / UINT8_MAX);
report->output0x03.magnitude_weak = ScaleRumbleAmplitude(left->high_band_amp, min_rumble_hf, max_rumble_hf); //left->high_band_amp; //static_cast<uint8_t>(100 * 0.5 * (left->high_band_amp + right->high_band_amp) / UINT8_MAX);
report->output0x03.pulse_sustain_10ms = 1;
report->output0x03.pulse_release_10ms = 0;
report->output0x03.loop_count = 0;