mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-26 06:10:20 +00:00
mc.mitm: replace lightbar enable config option with brightness setting for sony controllers
This commit is contained in:
parent
55c35d2c9a
commit
193df29205
7 changed files with 71 additions and 60 deletions
|
@ -11,10 +11,10 @@
|
|||
;host_address=04:20:69:04:20:69
|
||||
|
||||
[misc]
|
||||
; Enable the LED lightbar on Sony Dualshock 4 controllers [default true]
|
||||
;enable_dualshock4_lightbar=false
|
||||
; Enable the LED lightbar on Sony Dualsense controllers [default true]
|
||||
;enable_dualsense_lightbar=false
|
||||
; Set LED lightbar brightness for Sony Dualshock 4 controllers. Valid range [0-9] where 0=0% (off), 9=100% [default 5(50%)]
|
||||
;dualshock4_lightbar_brightness=4
|
||||
; Set LED lightbar brightness for Sony Dualsense controllers. Valid range [0-9] where 0=0% (off), 9=100% [default 5(50%)]
|
||||
;dualsense_lightbar_brightness=4
|
||||
; Enable the white player indicator LEDs below the Dualsense touchpad [default true]
|
||||
;enable_dualsense_player_leds=false
|
||||
; Set Dualsense vibration intensity, 12.5% per increment. Valid range [1-8] where 1=12.5%, 8=100% [default 4(50%)]
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::controller {
|
|||
|
||||
namespace {
|
||||
|
||||
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
|
||||
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
|
||||
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
|
||||
|
@ -49,21 +49,22 @@ namespace ams::controller {
|
|||
0x07
|
||||
};
|
||||
|
||||
const constexpr RGBColour led_disable = {0x00, 0x00, 0x00};
|
||||
|
||||
const RGBColour player_led_colours[] = {
|
||||
const RGBColour player_led_base_colours[] = {
|
||||
// Same colours used by PS4
|
||||
{0x00, 0x00, 0x40}, // blue
|
||||
{0x40, 0x00, 0x00}, // red
|
||||
{0x00, 0x40, 0x00}, // green
|
||||
{0x20, 0x00, 0x20}, // pink
|
||||
{0x00, 0x00, 0x04}, // blue
|
||||
{0x04, 0x00, 0x00}, // red
|
||||
{0x00, 0x04, 0x00}, // green
|
||||
{0x02, 0x00, 0x02}, // pink
|
||||
// New colours for controllers 5-8
|
||||
{0x00, 0x20, 0x20}, // cyan
|
||||
{0x30, 0x10, 0x00}, // orange
|
||||
{0x20, 0x20, 0x00}, // yellow
|
||||
{0x10, 0x00, 0x30} // purple
|
||||
{0x00, 0x02, 0x02}, // cyan
|
||||
{0x03, 0x01, 0x00}, // orange
|
||||
{0x02, 0x02, 0x00}, // yellow
|
||||
{0x01, 0x00, 0x03} // purple
|
||||
};
|
||||
|
||||
constexpr u8 step = 4;
|
||||
const u8 led_brightness_multipliers[] = { 0, 1, 1 * step, 2 * step, 3 * step, 4 * step, 5 * step, 6 * step, 7 * step, 8 * step };
|
||||
|
||||
constexpr u32 crc_seed = 0x8C36CCAE; // CRC32 of {0xa2, 0x31} bytes at beginning of output report
|
||||
|
||||
}
|
||||
|
@ -78,6 +79,9 @@ namespace ams::controller {
|
|||
// Request motion calibration data from DualSense
|
||||
R_TRY(this->GetCalibrationData(&m_motion_calibration));
|
||||
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
m_lightbar_brightness = config->misc.dualsense_lightbar_brightness;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
@ -94,13 +98,12 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result DualsenseController::SetPlayerLed(u8 led_mask) {
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
|
||||
u8 player_number;
|
||||
R_TRY(LedsMaskToPlayerNumber(led_mask, &player_number));
|
||||
|
||||
u16 fw_version = *reinterpret_cast<u16 *>(&m_version_info.data[43]);
|
||||
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
if (!config->misc.enable_dualsense_player_leds) {
|
||||
m_led_flags = 0x00;
|
||||
} else if (fw_version < 0x0282) {
|
||||
|
@ -112,13 +115,16 @@ namespace ams::controller {
|
|||
// Disable LED fade-in
|
||||
m_led_flags |= 0x20;
|
||||
|
||||
RGBColour colour = player_led_colours[player_number];
|
||||
RGBColour colour = player_led_base_colours[player_number];
|
||||
u8 multiplier = led_brightness_multipliers[m_lightbar_brightness];
|
||||
colour.r *= multiplier;
|
||||
colour.g *= multiplier;
|
||||
colour.b *= multiplier;
|
||||
R_RETURN(this->SetLightbarColour(colour));
|
||||
}
|
||||
|
||||
Result DualsenseController::SetLightbarColour(RGBColour colour) {
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
m_led_colour = config->misc.enable_dualsense_lightbar ? colour : led_disable;
|
||||
m_lightbar_colour = colour;
|
||||
R_RETURN(this->PushRumbleLedState());
|
||||
}
|
||||
|
||||
|
@ -283,9 +289,9 @@ namespace ams::controller {
|
|||
report.output0x31.data[42] = 0x02;
|
||||
report.output0x31.data[43] = 0x02;
|
||||
report.output0x31.data[44] = m_led_flags;
|
||||
report.output0x31.data[45] = m_led_colour.r;
|
||||
report.output0x31.data[46] = m_led_colour.g;
|
||||
report.output0x31.data[47] = m_led_colour.b;
|
||||
report.output0x31.data[45] = m_lightbar_colour.r;
|
||||
report.output0x31.data[46] = m_lightbar_colour.g;
|
||||
report.output0x31.data[47] = m_lightbar_colour.b;
|
||||
report.output0x31.crc = crc32CalculateWithSeed(crc_seed, report.output0x31.data, sizeof(report.output0x31.data));
|
||||
|
||||
m_output_report.size = sizeof(report.output0x31) + sizeof(report.id);
|
||||
|
|
|
@ -159,7 +159,8 @@ namespace ams::controller {
|
|||
DualsenseController(const bluetooth::Address *address, HardwareID id)
|
||||
: EmulatedSwitchController(address, id)
|
||||
, m_led_flags(0)
|
||||
, m_led_colour({0, 0, 0})
|
||||
, m_lightbar_colour({0, 0, 0})
|
||||
, m_lightbar_brightness(0)
|
||||
, m_rumble_state({0, 0}) { }
|
||||
|
||||
Result Initialize();
|
||||
|
@ -181,7 +182,8 @@ namespace ams::controller {
|
|||
Result PushRumbleLedState();
|
||||
|
||||
u8 m_led_flags;
|
||||
RGBColour m_led_colour;
|
||||
RGBColour m_lightbar_colour;
|
||||
u8 m_lightbar_brightness;
|
||||
DualsenseRumbleData m_rumble_state;
|
||||
|
||||
DualsenseVersionInfo m_version_info;
|
||||
|
|
|
@ -22,26 +22,27 @@ namespace ams::controller {
|
|||
|
||||
namespace {
|
||||
|
||||
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
|
||||
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
|
||||
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
|
||||
|
||||
const constexpr RGBColour led_disable = {0x00, 0x00, 0x00};
|
||||
|
||||
const RGBColour player_led_colours[] = {
|
||||
const RGBColour player_led_base_colours[] = {
|
||||
// Same colours used by PS4
|
||||
{0x00, 0x00, 0x40}, // blue
|
||||
{0x40, 0x00, 0x00}, // red
|
||||
{0x00, 0x40, 0x00}, // green
|
||||
{0x20, 0x00, 0x20}, // pink
|
||||
{0x00, 0x00, 0x04}, // blue
|
||||
{0x04, 0x00, 0x00}, // red
|
||||
{0x00, 0x04, 0x00}, // green
|
||||
{0x02, 0x00, 0x02}, // pink
|
||||
// New colours for controllers 5-8
|
||||
{0x00, 0x20, 0x20}, // cyan
|
||||
{0x30, 0x10, 0x00}, // orange
|
||||
{0x20, 0x20, 0x00}, // yellow
|
||||
{0x10, 0x00, 0x30} // purple
|
||||
{0x00, 0x02, 0x02}, // cyan
|
||||
{0x03, 0x01, 0x00}, // orange
|
||||
{0x02, 0x02, 0x00}, // yellow
|
||||
{0x01, 0x00, 0x03} // purple
|
||||
};
|
||||
|
||||
constexpr u8 step = 4;
|
||||
const u8 led_brightness_multipliers[] = { 0, 1, 1 * step, 2 * step, 3 * step, 4 * step, 5 * step, 6 * step, 7 * step, 8 * step };
|
||||
|
||||
constexpr u32 crc_seed = 0xB758EC66; // CRC32 of {0xa2, 0x11} bytes at beginning of output report
|
||||
|
||||
}
|
||||
|
@ -55,6 +56,9 @@ namespace ams::controller {
|
|||
m_enable_motion = false;
|
||||
}
|
||||
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
m_lightbar_brightness = config->misc.dualshock4_lightbar_brightness;
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
@ -73,13 +77,16 @@ namespace ams::controller {
|
|||
Result Dualshock4Controller::SetPlayerLed(u8 led_mask) {
|
||||
u8 player_number;
|
||||
R_TRY(LedsMaskToPlayerNumber(led_mask, &player_number));
|
||||
RGBColour colour = player_led_colours[player_number];
|
||||
RGBColour colour = player_led_base_colours[player_number];
|
||||
u8 multiplier = led_brightness_multipliers[m_lightbar_brightness];
|
||||
colour.r *= multiplier;
|
||||
colour.g *= multiplier;
|
||||
colour.b *= multiplier;
|
||||
R_RETURN(this->SetLightbarColour(colour));
|
||||
}
|
||||
|
||||
Result Dualshock4Controller::SetLightbarColour(RGBColour colour) {
|
||||
auto config = mitm::GetGlobalConfig();
|
||||
m_led_colour = config->misc.enable_dualshock4_lightbar ? colour : led_disable;
|
||||
m_lightbar_colour = colour;
|
||||
R_RETURN(this->PushRumbleLedState());
|
||||
}
|
||||
|
||||
|
@ -238,9 +245,9 @@ namespace ams::controller {
|
|||
report.output0x11.data[3] = 0x04;
|
||||
report.output0x11.data[5] = m_rumble_state.amp_motor_right;
|
||||
report.output0x11.data[6] = m_rumble_state.amp_motor_left;
|
||||
report.output0x11.data[7] = m_led_colour.r;
|
||||
report.output0x11.data[8] = m_led_colour.g;
|
||||
report.output0x11.data[9] = m_led_colour.b;
|
||||
report.output0x11.data[7] = m_lightbar_colour.r;
|
||||
report.output0x11.data[8] = m_lightbar_colour.g;
|
||||
report.output0x11.data[9] = m_lightbar_colour.b;
|
||||
report.output0x11.crc = crc32CalculateWithSeed(crc_seed, report.output0x11.data, sizeof(report.output0x11.data));
|
||||
|
||||
m_output_report.size = sizeof(report.output0x11) + sizeof(report.id);
|
||||
|
|
|
@ -38,12 +38,6 @@ namespace ams::controller {
|
|||
Dualshock4ReportRate_62Hz = 16
|
||||
};
|
||||
|
||||
enum Dualshock4ControllerVariant {
|
||||
Dualshock4ControllerVariant_V1,
|
||||
Dualshock4ControllerVariant_V2,
|
||||
Dualshock4ControllerVariant_Unknown
|
||||
};
|
||||
|
||||
enum Dualshock4DPadDirection {
|
||||
Dualshock4DPad_N,
|
||||
Dualshock4DPad_NE,
|
||||
|
@ -199,7 +193,8 @@ namespace ams::controller {
|
|||
Dualshock4Controller(const bluetooth::Address *address, HardwareID id)
|
||||
: EmulatedSwitchController(address, id)
|
||||
, m_report_rate(Dualshock4ReportRate_125Hz)
|
||||
, m_led_colour({0, 0, 0})
|
||||
, m_lightbar_colour({0, 0, 0})
|
||||
, m_lightbar_brightness(0)
|
||||
, m_rumble_state({0, 0}) { }
|
||||
|
||||
Result Initialize();
|
||||
|
@ -221,7 +216,8 @@ namespace ams::controller {
|
|||
Result PushRumbleLedState();
|
||||
|
||||
Dualshock4ReportRate m_report_rate;
|
||||
RGBColour m_led_colour;
|
||||
RGBColour m_lightbar_colour;
|
||||
u8 m_lightbar_brightness;
|
||||
Dualshock4RumbleData m_rumble_state;
|
||||
|
||||
Dualshock4ImuCalibrationData m_motion_calibration;
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace ams::mitm {
|
|||
.enable_motion = true
|
||||
},
|
||||
.misc = {
|
||||
.enable_dualshock4_lightbar = true,
|
||||
.enable_dualsense_lightbar = true,
|
||||
.dualshock4_lightbar_brightness = 5,
|
||||
.dualsense_lightbar_brightness = 5,
|
||||
.enable_dualsense_player_leds = true,
|
||||
.dualsense_vibration_intensity = 4
|
||||
}
|
||||
|
@ -90,10 +90,10 @@ namespace ams::mitm {
|
|||
ParseBluetoothAddress(value, &config->bluetooth.host_address);
|
||||
}
|
||||
} else if (strcasecmp(section, "misc") == 0) {
|
||||
if (strcasecmp(name, "enable_dualshock4_lightbar") == 0) {
|
||||
ParseBoolean(value, &config->misc.enable_dualshock4_lightbar);
|
||||
} else if (strcasecmp(name, "enable_dualsense_lightbar") == 0) {
|
||||
ParseBoolean(value, &config->misc.enable_dualsense_lightbar);
|
||||
if (strcasecmp(name, "dualshock4_lightbar_brightness") == 0) {
|
||||
ParseInt(value, &config->misc.dualshock4_lightbar_brightness, 0, 9);
|
||||
} else if (strcasecmp(name, "dualsense_lightbar_brightness") == 0) {
|
||||
ParseInt(value, &config->misc.dualsense_lightbar_brightness, 0, 9);
|
||||
} else if (strcasecmp(name, "enable_dualsense_player_leds") == 0) {
|
||||
ParseBoolean(value, &config->misc.enable_dualsense_player_leds);
|
||||
} else if (strcasecmp(name, "dualsense_vibration_intensity") == 0) {
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace ams::mitm {
|
|||
} bluetooth;
|
||||
|
||||
struct {
|
||||
bool enable_dualshock4_lightbar;
|
||||
bool enable_dualsense_lightbar;
|
||||
int dualshock4_lightbar_brightness;
|
||||
int dualsense_lightbar_brightness;
|
||||
bool enable_dualsense_player_leds;
|
||||
int dualsense_vibration_intensity;
|
||||
} misc;
|
||||
|
|
Loading…
Reference in a new issue