mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-22 20:33:07 +00:00
bluetooth-mitm: make vibration reports work for xbox one controller
This commit is contained in:
parent
42f82561ab
commit
1aeddc5574
2 changed files with 25 additions and 25 deletions
|
@ -28,17 +28,16 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result XboxOneController::SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) {
|
||||
m_rumble_state.amp_motor_left = left->low_band_amp;
|
||||
m_rumble_state.amp_motor_right = right->high_band_amp;
|
||||
auto report = reinterpret_cast<XboxOneReportData *>(s_output_report.data);
|
||||
s_output_report.size = sizeof(XboxOneOutputReport0x03) + 1;
|
||||
report->id = 0x03;
|
||||
report->output0x03.enable = 0x3;
|
||||
report->output0x03.magnitude_strong = static_cast<uint8_t>(100 * (float(left->low_band_amp) / UINT8_MAX));
|
||||
report->output0x03.magnitude_weak = static_cast<uint8_t>(100 * (float(right->high_band_amp) / UINT8_MAX));
|
||||
report->output0x03.pulse_sustain_10ms = 1;
|
||||
report->output0x03.pulse_release_10ms = 0;
|
||||
report->output0x03.loop_count = 0;
|
||||
|
||||
uint8_t rumble_packet[] = {0x09, 0x00, m_output_packet_counter++, 0x09, 0x00, 0x0f, 0x00, 0x00, m_rumble_state.amp_motor_left, m_rumble_state.amp_motor_right, 0xff, 0x00, 0xff};
|
||||
s_output_report.size = sizeof(rumble_packet);
|
||||
std::memcpy(s_output_report.data, rumble_packet, sizeof(rumble_packet));
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
||||
Result XboxOneController::CancelVibration(void) {
|
||||
uint8_t rumble_packet[] = {0x09, 0x00, m_output_packet_counter++, 0x09, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff};
|
||||
s_output_report.size = sizeof(rumble_packet);
|
||||
std::memcpy(s_output_report.data, rumble_packet, sizeof(rumble_packet));
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,10 +78,16 @@ namespace ams::controller {
|
|||
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct XboxOneRumbleData {
|
||||
uint8_t amp_motor_left;
|
||||
uint8_t amp_motor_right;
|
||||
} __attribute__((packed));
|
||||
struct XboxOneOutputReport0x03 {
|
||||
uint8_t enable;
|
||||
uint8_t magnitude_left;
|
||||
uint8_t magnitude_right;
|
||||
uint8_t magnitude_strong;
|
||||
uint8_t magnitude_weak;
|
||||
uint8_t pulse_sustain_10ms;
|
||||
uint8_t pulse_release_10ms;
|
||||
uint8_t loop_count;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct XboxOneInputReport0x01 {
|
||||
XboxOneStickData left_stick;
|
||||
|
@ -94,7 +100,7 @@ namespace ams::controller {
|
|||
struct XboxOneInputReport0x02{
|
||||
uint8_t guide : 1;
|
||||
uint8_t : 0;
|
||||
} __attribute__ ((__packed__));
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct XboxOneInputReport0x04 {
|
||||
uint8_t capacity : 2;
|
||||
|
@ -107,9 +113,10 @@ namespace ams::controller {
|
|||
struct XboxOneReportData {
|
||||
uint8_t id;
|
||||
union {
|
||||
XboxOneInputReport0x01 input0x01;
|
||||
XboxOneInputReport0x02 input0x02;
|
||||
XboxOneInputReport0x04 input0x04;
|
||||
XboxOneOutputReport0x03 output0x03;
|
||||
XboxOneInputReport0x01 input0x01;
|
||||
XboxOneInputReport0x02 input0x02;
|
||||
XboxOneInputReport0x04 input0x04;
|
||||
};
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
|
@ -125,21 +132,15 @@ namespace ams::controller {
|
|||
};
|
||||
|
||||
XboxOneController(const bluetooth::Address *address)
|
||||
: EmulatedSwitchController(address)
|
||||
, m_output_packet_counter(0)
|
||||
, m_rumble_state({0, 0}) { };
|
||||
: EmulatedSwitchController(address) { };
|
||||
|
||||
Result SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right);
|
||||
Result CancelVibration(void);
|
||||
void UpdateControllerState(const bluetooth::HidReport *report);
|
||||
|
||||
private:
|
||||
void HandleInputReport0x01(const XboxOneReportData *src);
|
||||
void HandleInputReport0x04(const XboxOneReportData *src);
|
||||
|
||||
uint8_t m_output_packet_counter;
|
||||
XboxOneRumbleData m_rumble_state;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue