mirror of
https://github.com/cathery/sys-con.git
synced 2024-11-05 08:26:32 +00:00
Add customizable controller colors #63
This commit is contained in:
parent
9807350530
commit
a1363d5774
@ -30,15 +30,31 @@ struct NormalizedStick
|
||||
float axis_y;
|
||||
};
|
||||
|
||||
union RGBAColor {
|
||||
struct
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
};
|
||||
uint8_t values[4];
|
||||
uint32_t rgbaValue;
|
||||
};
|
||||
|
||||
struct ControllerConfig
|
||||
{
|
||||
uint8_t leftStickDeadzonePercent;
|
||||
uint8_t rightStickDeadzonePercent;
|
||||
uint16_t leftStickRotationDegrees;
|
||||
uint16_t rightStickRotationDegrees;
|
||||
uint8_t triggerDeadzonePercent;
|
||||
uint8_t leftStickDeadzonePercent{10};
|
||||
uint8_t rightStickDeadzonePercent{10};
|
||||
uint16_t leftStickRotationDegrees{0};
|
||||
uint16_t rightStickRotationDegrees{0};
|
||||
uint8_t triggerDeadzonePercent{0};
|
||||
ControllerButton buttons[NUM_CONTROLLERBUTTONS];
|
||||
float triggers[2];
|
||||
NormalizedStick sticks[2];
|
||||
bool swapDPADandLSTICK;
|
||||
float triggers[2]{0};
|
||||
NormalizedStick sticks[2]{0};
|
||||
bool swapDPADandLSTICK{false};
|
||||
RGBAColor bodyColor{107, 107, 107, 255};
|
||||
RGBAColor buttonsColor{0, 0, 0, 255};
|
||||
RGBAColor leftGripColor{70, 70, 70, 255};
|
||||
RGBAColor rightGripColor{70, 70, 70, 255};
|
||||
};
|
@ -82,8 +82,9 @@ Result SwitchAbstractedPadHandler::InitAbstractedPadState()
|
||||
m_state.npadInterfaceType = NpadInterfaceType_USB;
|
||||
m_state.flags = 0xff;
|
||||
m_state.state.batteryCharge = 4;
|
||||
m_state.singleColorBody = RGBA8_MAXALPHA(107, 107, 107);
|
||||
m_state.singleColorButtons = RGBA8_MAXALPHA(0, 0, 0);
|
||||
ControllerConfig *config = GetController()->GetConfig();
|
||||
m_state.singleColorBody = config->bodyColor.rgbaValue;
|
||||
m_state.singleColorButtons = config->buttonsColor.rgbaValue;
|
||||
|
||||
rc = hiddbgSetAutoPilotVirtualPadState(m_abstractedPadID, &m_state);
|
||||
if (R_FAILED(rc))
|
||||
|
@ -61,10 +61,11 @@ Result SwitchHDLHandler::InitHdlState()
|
||||
m_deviceInfo.deviceType = HidDeviceType_FullKey15;
|
||||
m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB;
|
||||
// Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+].
|
||||
m_deviceInfo.singleColorBody = RGBA8_MAXALPHA(107, 107, 107);
|
||||
m_deviceInfo.singleColorButtons = RGBA8_MAXALPHA(0, 0, 0);
|
||||
m_deviceInfo.colorLeftGrip = RGBA8_MAXALPHA(70, 70, 70);
|
||||
m_deviceInfo.colorRightGrip = RGBA8_MAXALPHA(70, 70, 70);
|
||||
ControllerConfig *config = GetController()->GetConfig();
|
||||
m_deviceInfo.singleColorBody = config->bodyColor.rgbaValue;
|
||||
m_deviceInfo.singleColorButtons = config->buttonsColor.rgbaValue;
|
||||
m_deviceInfo.colorLeftGrip = config->leftGripColor.rgbaValue;
|
||||
m_deviceInfo.colorRightGrip = config->rightGripColor.rgbaValue;
|
||||
|
||||
m_hdlState.batteryCharge = 4; // Set battery charge to full.
|
||||
m_hdlState.joysticks[JOYSTICK_LEFT].dx = 0x1234;
|
||||
|
@ -50,6 +50,25 @@ static ControllerButton _StringToKey(const char *text)
|
||||
return NOT_SET;
|
||||
}
|
||||
|
||||
static RGBAColor _DecodeColorValue(const char *value)
|
||||
{
|
||||
RGBAColor color{255};
|
||||
uint8_t counter = 0;
|
||||
int charIndex = 0;
|
||||
while (value[charIndex] != '\0')
|
||||
{
|
||||
if (charIndex == 0)
|
||||
color.values[counter++] = atoi(value + charIndex++);
|
||||
if (value[charIndex++] == ',')
|
||||
{
|
||||
color.values[counter++] = atoi(value + charIndex);
|
||||
if (counter == 4)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
static ControllerConfig temp_config;
|
||||
static char firmwarePath[100];
|
||||
|
||||
@ -93,11 +112,34 @@ static int _ParseConfigLine(void *dummy, const char *section, const char *name,
|
||||
temp_config.swapDPADandLSTICK = (strcmp(value, "true") ? false : true);
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(name, "firmware_path") == 0)
|
||||
else if (strcmp(name, "swap_dpad_and_lstick") == 0)
|
||||
{
|
||||
strcpy(firmwarePath, value);
|
||||
temp_config.swapDPADandLSTICK = (strcmp(value, "true") ? false : true);
|
||||
return 1;
|
||||
}
|
||||
else if (strncmp(name, "color_", 6) == 0)
|
||||
{
|
||||
if (strcmp(name + 6, "body") == 0)
|
||||
{
|
||||
temp_config.bodyColor = _DecodeColorValue(value);
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(name + 6, "buttons") == 0)
|
||||
{
|
||||
temp_config.buttonsColor = _DecodeColorValue(value);
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(name + 6, "leftGrip") == 0)
|
||||
{
|
||||
temp_config.leftGripColor = _DecodeColorValue(value);
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(name + 6, "rightGrip") == 0)
|
||||
{
|
||||
temp_config.rightGripColor = _DecodeColorValue(value);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user