bluetooth-mitm: add DualSense rumble

This commit is contained in:
Sean Maas 2021-01-28 16:10:05 -05:00 committed by ndeadly
parent 6fc0036129
commit c227688485
2 changed files with 30 additions and 2 deletions

View file

@ -22,6 +22,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 uint8_t player_led_flags[] = {
// Mimic the Switch's player LEDs
0x01,
@ -56,6 +61,18 @@ namespace ams::controller {
return ams::ResultSuccess();
}
Result DualsenseController::SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) {
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();
}
Result DualsenseController::CancelVibration(void) {
m_rumble_state.amp_motor_left = 0;
m_rumble_state.amp_motor_right = 0;
return this->PushRumbleLedState();
}
Result DualsenseController::SetPlayerLed(uint8_t led_mask) {
uint8_t player_number;
R_TRY(LedsMaskToPlayerNumber(led_mask, &player_number));
@ -158,7 +175,7 @@ namespace ams::controller {
}
Result DualsenseController::PushRumbleLedState(void) {
DualsenseOutputReport0x31 report = {0xa2, 0x31, 0x02, 0x00, 0x14};
DualsenseOutputReport0x31 report = {0xa2, 0x31, 0x02, 0x03, 0x14, m_rumble_state.amp_motor_right, m_rumble_state.amp_motor_left};
report.data[41] = 0x02;
report.data[44] = 0x02;
report.data[46] = m_led_flags;

View file

@ -56,6 +56,11 @@ namespace ams::controller {
uint8_t counter : 6;
} __attribute__((packed));
struct DualsenseRumbleData {
uint8_t amp_motor_left;
uint8_t amp_motor_right;
} __attribute__((packed));
struct DualsenseOutputReport0x31 {
struct {
uint8_t data[75];
@ -110,9 +115,14 @@ namespace ams::controller {
};
DualsenseController(const bluetooth::Address *address)
: EmulatedSwitchController(address), m_led_flags(0), m_led_colour({0, 0, 0}) { };
: EmulatedSwitchController(address)
, m_led_flags(0)
, m_led_colour({0, 0, 0})
, m_rumble_state({0, 0}) { };
Result Initialize(void);
Result SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right);
Result CancelVibration(void);
Result SetPlayerLed(uint8_t led_mask);
Result SetLightbarColour(RGBColour colour);
@ -128,5 +138,6 @@ namespace ams::controller {
uint8_t m_led_flags;
RGBColour m_led_colour;
DualsenseRumbleData m_rumble_state;
};
}