Skip to content

Commit ba2659a

Browse files
dualshock3: Make rumble configurable
1 parent 333fb53 commit ba2659a

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

ios/ios_pad/source/controllers/dualshock3_controller.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,29 @@ static const MappingConfiguration default_dualshock3_mapping = {
5555
},
5656
};
5757

58+
static const Dualshock3Configuration default_dualshock3_configuration = {
59+
.motorForce = 64,
60+
.motorDuration = 1,
61+
};
62+
5863
static const Dualshock3LedConfig led_config = { 0xff, 0x27, 0x10, 0x00, 0x32 };
5964

6065
static const uint8_t enable_payload[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
6166

6267
static void sendRumbleLedState(Controller* controller)
6368
{
6469
Dualshock3Data* ds_data = (Dualshock3Data*) controller->additionalData;
70+
Dualshock3Configuration* config = (Dualshock3Configuration*) controller->customConfig;
6571

6672
Dualshock3OutputReport rep;
6773
memset(&rep, 0, sizeof(rep));
6874

6975
rep.report_id = DUALSHOCK3_OUTPUT_REPORT_ID;
7076

71-
rep.right_motor_duration = 1;
77+
rep.right_motor_duration = config->motorDuration;
7278
rep.right_motor_force = ds_data->rumble;
73-
rep.left_motor_duration = 1;
74-
rep.left_motor_force = ds_data->rumble * 64;
79+
rep.left_motor_duration = config->motorDuration;
80+
rep.left_motor_force = ds_data->rumble * config->motorForce;
7581

7682
rep.led_mask = ds_data->led_mask << 1;
7783
memcpy(&rep.leds[0], &led_config, sizeof(Dualshock3LedConfig));
@@ -195,5 +201,5 @@ void controllerInit_dualshock3(Controller* controller)
195201

196202
void controllerModuleInit_dualshock3(void)
197203
{
198-
Configuration_SetFallback(BLOOPAIR_CONTROLLER_DUALSHOCK3, NULL, &default_dualshock3_mapping, NULL, 0);
204+
Configuration_SetFallback(BLOOPAIR_CONTROLLER_DUALSHOCK3, NULL, &default_dualshock3_mapping, &default_dualshock3_configuration, sizeof(default_dualshock3_configuration));
199205
}

koopair/source/Configuration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ void Configuration::SetCustomConfiguraion(const Dualshock3Configuration& config)
247247
return;
248248
}
249249

250-
// mJson["custom"]["someCustomField"] = config.SomeCustomField;
250+
mJson["custom"]["motorForce"] = config.motorForce;
251+
mJson["custom"]["motorDuration"] = config.motorDuration;
251252
}
252253

253254
void Configuration::SetCustomConfiguraion(const Dualshock4Configuration& config)

koopair/source/screens/ControllerOptionsScreen.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ ControllerOptionsScreen::ControllerOptionsScreen(const KPADController* controlle
5151
case BLOOPAIR_CONTROLLER_DUALSENSE:
5252
break;
5353
case BLOOPAIR_CONTROLLER_DUALSHOCK3:
54+
mCustomOptions.insert(mCustomOptions.begin(), 1, Option{ .name = "Dualshock 3 Specific Options", .type = OPTION_TYPE_TITLE_BAR });
55+
mCustomOptions.push_back(Option{ .name = "Motor force", .type = OPTION_TYPE_INT,
56+
.d = { custom.dualshock3.motorForce, 0, 255 },
57+
.callback = [this](const Option& opt) {
58+
mCustomConfiguration.dualshock3.motorForce = opt.d.value;
59+
}
60+
});
61+
mCustomOptions.push_back(Option{ .name = "Motor duration", .type = OPTION_TYPE_INT,
62+
.d = { custom.dualshock3.motorDuration, 0, 255 },
63+
.callback = [this](const Option& opt) {
64+
mCustomConfiguration.dualshock3.motorDuration = opt.d.value;
65+
}
66+
});
5467
break;
5568
case BLOOPAIR_CONTROLLER_DUALSHOCK4:
5669
break;

libbloopair/include/bloopair/controllers/dualshock3_controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ enum {
4343
};
4444

4545
typedef struct {
46-
46+
uint8_t motorForce;
47+
uint8_t motorDuration;
4748
} Dualshock3Configuration;

loader/config.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,34 @@ static bool LoadDualSenseCustomConfiguration(const nlohmann::json& custom, IOSHa
146146

147147
static bool LoadDualShock3CustomConfiguration(const nlohmann::json& custom, IOSHandle handle, BloopairControllerType type, const uint8_t* bda)
148148
{
149+
// Start by getting the default configuration
150+
Dualshock3Configuration config;
151+
uint32_t configSize = sizeof(config);
152+
if (Bloopair_GetDefaultCustomConfiguration(handle, type, &config, &configSize) < 0) {
153+
return false;
154+
}
155+
156+
// Overwrite fields from the config
157+
if (custom.contains("motorForce")) {
158+
config.motorForce = custom["motorForce"];
159+
}
160+
if (custom.contains("motorDuration")) {
161+
config.motorDuration = custom["motorDuration"];
162+
}
163+
164+
// Apply configuration
165+
IOSError error;
166+
if (bda) {
167+
error = Bloopair_ApplyCustomConfigurationForBDA(handle, bda, &config, sizeof(config));
168+
} else {
169+
error = Bloopair_ApplyCustomConfigurationForControllerType(handle, type, &config, sizeof(config));
170+
}
171+
172+
if (error < 0) {
173+
OSReport("Bloopair Loader: ApplyCustomConfiguration failed %x\n", error);
174+
return false;
175+
}
176+
149177
return true;
150178
}
151179

0 commit comments

Comments
 (0)