Skip to content

Commit 1f2d0dc

Browse files
committed
bluetooth-mitm: add struct definitions and methods to begin implementing rumble support
1 parent 0ad7fd4 commit 1f2d0dc

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

mc_mitm/source/controllers/emulated_switch_controller.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ namespace ams::controller {
6464
R_TRY(this->HandleSubCmdReport(report));
6565
break;
6666
case 0x10: // Rumble
67-
// Todo: add rumble support
67+
R_TRY(this->HandleRumbleReport(report));
68+
break;
6869
default:
6970
break;
7071
}
@@ -122,6 +123,11 @@ namespace ams::controller {
122123
return ams::ResultSuccess();
123124
}
124125

126+
Result EmulatedSwitchController::HandleRumbleReport(const bluetooth::HidReport *report) {
127+
auto report_data = reinterpret_cast<const SwitchReportData *>(report->data);
128+
return this->SetVibration(&report_data->output0x10.left_motor, &report_data->output0x10.right_motor);
129+
}
130+
125131
Result EmulatedSwitchController::SubCmdRequestDeviceInfo(const bluetooth::HidReport *report) {
126132
const SwitchSubcommandResponse response = {
127133
.ack = 0x82,

mc_mitm/source/controllers/emulated_switch_controller.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ams::controller {
3232
void ClearControllerState(void);
3333
virtual void UpdateControllerState(const bluetooth::HidReport *report) {};
3434

35-
virtual Result SetVibration(void) { return ams::ResultSuccess(); };
35+
virtual Result SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) { return ams::ResultSuccess(); };
3636
virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); };
3737

3838
constexpr SwitchStickData PackStickData(uint16_t x, uint16_t y) {
@@ -44,6 +44,8 @@ namespace ams::controller {
4444
}
4545

4646
Result HandleSubCmdReport(const bluetooth::HidReport *report);
47+
Result HandleRumbleReport(const bluetooth::HidReport *report);
48+
4749
Result SubCmdRequestDeviceInfo(const bluetooth::HidReport *report);
4850
Result SubCmdSpiFlashRead(const bluetooth::HidReport *report);
4951
Result SubCmdSpiFlashWrite(const bluetooth::HidReport *report);

mc_mitm/source/controllers/switch_controller.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ namespace ams::controller {
9292
uint16_t gyro_3;
9393
} __attribute__ ((__packed__));
9494

95+
struct SwitchRumbleData {
96+
uint8_t high_band_freq;
97+
uint8_t high_band_amp;
98+
uint8_t low_band_freq;
99+
uint8_t low_band_amp;
100+
} __attribute__ ((__packed__));
101+
95102
enum SubCmdType : uint8_t {
96103
SubCmd_GetControllerState = 0x00,
97104
SubCmd_ManualPair = 0x01,
@@ -178,7 +185,13 @@ namespace ams::controller {
178185
} __attribute__ ((__packed__));
179186

180187
struct SwitchOutputReport0x03;
181-
struct SwitchOutputReport0x10;
188+
189+
struct SwitchOutputReport0x10 {
190+
uint8_t timer;
191+
SwitchRumbleData left_motor;
192+
SwitchRumbleData right_motor;
193+
}__attribute__ ((__packed__));
194+
182195
struct SwitchOutputReport0x11;
183196
struct SwitchOutputReport0x12;
184197

@@ -218,7 +231,7 @@ namespace ams::controller {
218231
union {
219232
SwitchOutputReport0x01 output0x01;
220233
//SwitchOutputReport0x03 output0x03;
221-
//SwitchOutputReport0x10 output0x10;
234+
SwitchOutputReport0x10 output0x10;
222235
//SwitchOutputReport0x11 output0x11;
223236
//SwitchOutputReport0x12 output0x12;
224237
SwitchInputReport0x21 input0x21;

0 commit comments

Comments
 (0)