Skip to content

Commit

Permalink
dualshock3: Make rumble configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Jan 17, 2025
1 parent 333fb53 commit ba2659a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ios/ios_pad/source/controllers/dualshock3_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,29 @@ static const MappingConfiguration default_dualshock3_mapping = {
},
};

static const Dualshock3Configuration default_dualshock3_configuration = {
.motorForce = 64,
.motorDuration = 1,
};

static const Dualshock3LedConfig led_config = { 0xff, 0x27, 0x10, 0x00, 0x32 };

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

static void sendRumbleLedState(Controller* controller)
{
Dualshock3Data* ds_data = (Dualshock3Data*) controller->additionalData;
Dualshock3Configuration* config = (Dualshock3Configuration*) controller->customConfig;

Dualshock3OutputReport rep;
memset(&rep, 0, sizeof(rep));

rep.report_id = DUALSHOCK3_OUTPUT_REPORT_ID;

rep.right_motor_duration = 1;
rep.right_motor_duration = config->motorDuration;
rep.right_motor_force = ds_data->rumble;
rep.left_motor_duration = 1;
rep.left_motor_force = ds_data->rumble * 64;
rep.left_motor_duration = config->motorDuration;
rep.left_motor_force = ds_data->rumble * config->motorForce;

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

void controllerModuleInit_dualshock3(void)
{
Configuration_SetFallback(BLOOPAIR_CONTROLLER_DUALSHOCK3, NULL, &default_dualshock3_mapping, NULL, 0);
Configuration_SetFallback(BLOOPAIR_CONTROLLER_DUALSHOCK3, NULL, &default_dualshock3_mapping, &default_dualshock3_configuration, sizeof(default_dualshock3_configuration));
}
3 changes: 2 additions & 1 deletion koopair/source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ void Configuration::SetCustomConfiguraion(const Dualshock3Configuration& config)
return;
}

// mJson["custom"]["someCustomField"] = config.SomeCustomField;
mJson["custom"]["motorForce"] = config.motorForce;
mJson["custom"]["motorDuration"] = config.motorDuration;
}

void Configuration::SetCustomConfiguraion(const Dualshock4Configuration& config)
Expand Down
13 changes: 13 additions & 0 deletions koopair/source/screens/ControllerOptionsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ ControllerOptionsScreen::ControllerOptionsScreen(const KPADController* controlle
case BLOOPAIR_CONTROLLER_DUALSENSE:
break;
case BLOOPAIR_CONTROLLER_DUALSHOCK3:
mCustomOptions.insert(mCustomOptions.begin(), 1, Option{ .name = "Dualshock 3 Specific Options", .type = OPTION_TYPE_TITLE_BAR });
mCustomOptions.push_back(Option{ .name = "Motor force", .type = OPTION_TYPE_INT,
.d = { custom.dualshock3.motorForce, 0, 255 },
.callback = [this](const Option& opt) {
mCustomConfiguration.dualshock3.motorForce = opt.d.value;
}
});
mCustomOptions.push_back(Option{ .name = "Motor duration", .type = OPTION_TYPE_INT,
.d = { custom.dualshock3.motorDuration, 0, 255 },
.callback = [this](const Option& opt) {
mCustomConfiguration.dualshock3.motorDuration = opt.d.value;
}
});
break;
case BLOOPAIR_CONTROLLER_DUALSHOCK4:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ enum {
};

typedef struct {

uint8_t motorForce;
uint8_t motorDuration;
} Dualshock3Configuration;
28 changes: 28 additions & 0 deletions loader/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ static bool LoadDualSenseCustomConfiguration(const nlohmann::json& custom, IOSHa

static bool LoadDualShock3CustomConfiguration(const nlohmann::json& custom, IOSHandle handle, BloopairControllerType type, const uint8_t* bda)
{
// Start by getting the default configuration
Dualshock3Configuration config;
uint32_t configSize = sizeof(config);
if (Bloopair_GetDefaultCustomConfiguration(handle, type, &config, &configSize) < 0) {
return false;
}

// Overwrite fields from the config
if (custom.contains("motorForce")) {
config.motorForce = custom["motorForce"];
}
if (custom.contains("motorDuration")) {
config.motorDuration = custom["motorDuration"];
}

// Apply configuration
IOSError error;
if (bda) {
error = Bloopair_ApplyCustomConfigurationForBDA(handle, bda, &config, sizeof(config));
} else {
error = Bloopair_ApplyCustomConfigurationForControllerType(handle, type, &config, sizeof(config));
}

if (error < 0) {
OSReport("Bloopair Loader: ApplyCustomConfiguration failed %x\n", error);
return false;
}

return true;
}

Expand Down

0 comments on commit ba2659a

Please sign in to comment.