Skip to content

Commit

Permalink
Finalize 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cathery committed Nov 15, 2019
1 parent 9be2b8c commit 781129b
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 77 deletions.
1 change: 1 addition & 0 deletions ControllerUSB/include/ControllerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum ControllerButton
DPAD_LEFT,
SYNC,
GUIDE,
TOUCHPAD,
NUM_CONTROLLERBUTTONS,
};

Expand Down
11 changes: 9 additions & 2 deletions ControllerUSB/source/Controllers/Dualshock4Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Result Dualshock4Controller::SendInitBytes()
{
constexpr uint8_t init_bytes[32] = {
0x05, 0x07, 0x00, 0x00,
0x7f, 0x7f,
0x00, 0x00, 0x40,
0x00, 0x00, //initial strong and weak rumble
0x00, 0x00, 0x40, //LED color
0x00, 0x00};

return m_outPipe->Write(init_bytes, sizeof(init_bytes));
Expand Down Expand Up @@ -57,6 +57,12 @@ Result Dualshock4Controller::OpenInterfaces()
if (R_FAILED(rc))
return rc;

if (interface->GetDescriptor()->bInterfaceClass != 3)
continue;

if (interface->GetDescriptor()->bInterfaceProtocol != 0)
continue;

if (interface->GetDescriptor()->bNumEndpoints < 2)
continue;

Expand Down Expand Up @@ -203,6 +209,7 @@ NormalizedButtonData Dualshock4Controller::GetNormalizedButtonData()
(m_buttonData.dpad == DS4_LEFT) || (m_buttonData.dpad == DS4_UPLEFT) || (m_buttonData.dpad == DS4_DOWNLEFT),
m_buttonData.touchpad_press,
m_buttonData.psbutton,
m_buttonData.touchpad_finger1_unpressed == false,
};

for (int i = 0; i != NUM_CONTROLLERBUTTONS; ++i)
Expand Down
1 change: 1 addition & 0 deletions SwitchUSB/source/SwitchHDLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)

m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0);
m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0);
m_hdlState.buttons |= (data.buttons[18] ? KEY_TOUCH : 0);
}

void SwitchHDLHandler::UpdateInput()
Expand Down
7 changes: 7 additions & 0 deletions config/sys-con/config_dualshock3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 10 ; from 0 to 100
trigger_deadzone = 0 ; from 0 to 100

color_body = 48,71,105
color_buttons = 22,22,22

; [9.0.0+]
color_leftGrip = 22,33,49
color_rightGrip = 22,33,49

swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
Expand Down
10 changes: 9 additions & 1 deletion config/sys-con/config_dualshock4.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 10 ; from 0 to 100
trigger_deadzone = 0 ; from 0 to 100

color_body = 77,77,77
color_buttons = 0,0,0

; [9.0.0+]
color_leftGrip = 33,33,33
color_rightGrip = 33,33,33

swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
;key_SYNC = LSTICK_CLICK ; Remove the semicolon at the start to take effect
;key_SYNC = LSTICK_CLICK ; Remove the semicolon at the start to take effect

13 changes: 2 additions & 11 deletions config/sys-con/config_global.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
; Global overwrite config. Controller configs take priority. Doesn't work also
;left_stick_deadzone = 0 ; from 0 to 100
;right_stick_deadzone = 0 ; from 0 to 100
;trigger_deadzone = 0 ; from 0 to 100

;swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
; Remove the semicolons below to take effect
;key_FACE_DOWN = FACE_RIGHT
;key_FACE_LEFT = FACE_UP
[global]
use_dualshock_2nd_generation = false
7 changes: 7 additions & 0 deletions config/sys-con/config_xbox360.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ left_stick_deadzone = 21 ; from 0 to 100
right_stick_deadzone = 25 ; from 0 to 100
trigger_deadzone = 0 ; from 0 to 100

color_body = 77,77,77
color_buttons = 69,121,22

; [9.0.0+]
color_leftGrip = 100,100,100
color_rightGrip = 100,100,100

swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
Expand Down
7 changes: 7 additions & 0 deletions config/sys-con/config_xboxone.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 17 ; from 0 to 100
trigger_deadzone = 0 ; from 0 to 100

color_body = 107,107,107
color_buttons = 0,0,0

; [9.0.0+]
color_leftGrip = 77,77,77
color_rightGrip = 77,77,77

swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
Expand Down
1 change: 1 addition & 0 deletions config/sys-con/config_xboxoneadapter.ini
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
; Doesn't work properly yet, disabled
firmware_path = /config/sys-con/firmware/XboxOneAdapter.bin
7 changes: 7 additions & 0 deletions config/sys-con/config_xboxorig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ left_stick_deadzone = 21 ; from 0 to 100
right_stick_deadzone = 25 ; from 0 to 100
trigger_deadzone = 0 ; from 0 to 100

color_body = 77,77,77
color_buttons = 69,121,22

; [9.0.0+]
color_leftGrip = 100,100,100
color_rightGrip = 100,100,100

swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick

; For information on input mapping, see "example.ini"
Expand Down
9 changes: 9 additions & 0 deletions config/sys-con/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ swap_dpad_and_lstick = false ; set this to true to swap the d-pad and left stick
; DPAD_LEFT D-pad LEFT
; SYNC Capture on joycons
; GUIDE Home on joycons
; TOUCHPAD Simulate at least one finger on the touch screen (doesn't work?)

; example: this will swap the X and Y, A and B buttons to match the names on Xbox controllers
key_FACE_DOWN = FACE_RIGHT
key_FACE_LEFT = FACE_UP

; example: this will press the Capture button on Left stick press
key_LSTICK_CLICK = SYNC

; these are RGB color values for the controller icon represented in the controller screens
color_body = 107,107,107
color_buttons = 0,0,0

; these two will only work on firmware [9.0.0+]. They are supposed to change the color of your controller grips
color_leftGrip = 77,77,77
color_rightGrip = 77,77,77
121 changes: 71 additions & 50 deletions source/configFile.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "mainLoop.h"
#include "configFile.h"
#include "Controllers.h"
#include "ControllerConfig.h"
Expand Down Expand Up @@ -36,6 +37,7 @@ std::array<const char *, NUM_CONTROLLERBUTTONS> keyNames{
"DPAD_LEFT",
"SYNC",
"GUIDE",
"TOUCHPAD",
};

static ControllerButton _StringToKey(const char *text)
Expand Down Expand Up @@ -70,75 +72,87 @@ static RGBAColor _DecodeColorValue(const char *value)
}

static ControllerConfig temp_config;
static GlobalConfig global_config;
static char firmwarePath[100];

static int _ParseConfigLine(void *dummy, const char *section, const char *name, const char *value)
{
if (strncmp(name, "key_", 4) == 0)
if (strcmp(section, "global") == 0)
{
ControllerButton button = _StringToKey(name + 4);
ControllerButton buttonValue = _StringToKey(value);
temp_config.buttons[button] = buttonValue;
temp_config.buttons[buttonValue] = button;
return 1;
}
else if (strcmp(name, "left_stick_deadzone") == 0)
{
temp_config.leftStickDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name, "right_stick_deadzone") == 0)
{
temp_config.rightStickDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name, "left_stick_rotation") == 0)
{
temp_config.leftStickRotationDegrees = atoi(value);
return 1;
}
else if (strcmp(name, "right_stick_rotation") == 0)
{
temp_config.rightStickRotationDegrees = atoi(value);
return 1;
}
else if (strcmp(name, "trigger_deadzone") == 0)
{
temp_config.triggerDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name, "swap_dpad_and_lstick") == 0)
{
temp_config.swapDPADandLSTICK = (strcmp(value, "true") ? false : true);
return 1;
}
else if (strcmp(name, "firmware_path") == 0)
{
strcpy(firmwarePath, value);
return 1;
if (strcmp(name, "use_dualshock_2nd_generation") == 0)
{
global_config.dualshock4_productID = (strcmp(value, "true") ? PRODUCT_DUALSHOCK4_1X : PRODUCT_DUALSHOCK4_2X);
return 1;
}
}
else if (strncmp(name, "color_", 6) == 0)
else
{
if (strcmp(name + 6, "body") == 0)
if (strncmp(name, "key_", 4) == 0)
{
temp_config.bodyColor = _DecodeColorValue(value);
ControllerButton button = _StringToKey(name + 4);
ControllerButton buttonValue = _StringToKey(value);
temp_config.buttons[button] = buttonValue;
temp_config.buttons[buttonValue] = button;
return 1;
}
else if (strcmp(name + 6, "buttons") == 0)
else if (strcmp(name, "left_stick_deadzone") == 0)
{
temp_config.buttonsColor = _DecodeColorValue(value);
temp_config.leftStickDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name + 6, "leftGrip") == 0)
else if (strcmp(name, "right_stick_deadzone") == 0)
{
temp_config.leftGripColor = _DecodeColorValue(value);
temp_config.rightStickDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name + 6, "rightGrip") == 0)
else if (strcmp(name, "left_stick_rotation") == 0)
{
temp_config.rightGripColor = _DecodeColorValue(value);
temp_config.leftStickRotationDegrees = atoi(value);
return 1;
}
else if (strcmp(name, "right_stick_rotation") == 0)
{
temp_config.rightStickRotationDegrees = atoi(value);
return 1;
}
else if (strcmp(name, "trigger_deadzone") == 0)
{
temp_config.triggerDeadzonePercent = atoi(value);
return 1;
}
else if (strcmp(name, "swap_dpad_and_lstick") == 0)
{
temp_config.swapDPADandLSTICK = (strcmp(value, "true") ? false : true);
return 1;
}
else if (strcmp(name, "firmware_path") == 0)
{
strcpy(firmwarePath, value);
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;
Expand All @@ -156,6 +170,13 @@ static Result _ReadFromConfig(const char *path)

void LoadAllConfigs()
{
if (R_SUCCEEDED(_ReadFromConfig(CONFIG_PATH GLOBALCONFIG)))
{
LoadGlobalConfig(&global_config);
}
else
WriteToLog("Failed to read from global config!");

if (R_SUCCEEDED(_ReadFromConfig(CONFIG_PATH XBOXCONFIG)))
{
XboxController::LoadConfig(&temp_config);
Expand Down
1 change: 0 additions & 1 deletion source/configFile.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#define CONFIG_PATH "/config/sys-con/"

void LoadAllConfigs();
Expand Down
Loading

0 comments on commit 781129b

Please sign in to comment.