From 781129b4670f254c1769bcd94be7377fffdd539e Mon Sep 17 00:00:00 2001 From: cathery Date: Fri, 15 Nov 2019 14:03:06 +0300 Subject: [PATCH] Finalize 0.5.0 --- ControllerUSB/include/ControllerConfig.h | 1 + .../Controllers/Dualshock4Controller.cpp | 11 +- SwitchUSB/source/SwitchHDLHandler.cpp | 1 + config/sys-con/config_dualshock3.ini | 7 + config/sys-con/config_dualshock4.ini | 10 +- config/sys-con/config_global.ini | 13 +- config/sys-con/config_xbox360.ini | 7 + config/sys-con/config_xboxone.ini | 7 + config/sys-con/config_xboxoneadapter.ini | 1 + config/sys-con/config_xboxorig.ini | 7 + config/sys-con/example.ini | 9 ++ source/configFile.cpp | 125 ++++++++++-------- source/configFile.h | 1 - source/mainLoop.cpp | 41 ++++-- source/mainLoop.h | 9 +- 15 files changed, 171 insertions(+), 79 deletions(-) diff --git a/ControllerUSB/include/ControllerConfig.h b/ControllerUSB/include/ControllerConfig.h index 24ced39..e2faec2 100644 --- a/ControllerUSB/include/ControllerConfig.h +++ b/ControllerUSB/include/ControllerConfig.h @@ -21,6 +21,7 @@ enum ControllerButton DPAD_LEFT, SYNC, GUIDE, + TOUCHPAD, NUM_CONTROLLERBUTTONS, }; diff --git a/ControllerUSB/source/Controllers/Dualshock4Controller.cpp b/ControllerUSB/source/Controllers/Dualshock4Controller.cpp index f9f8c7e..75592e1 100644 --- a/ControllerUSB/source/Controllers/Dualshock4Controller.cpp +++ b/ControllerUSB/source/Controllers/Dualshock4Controller.cpp @@ -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)); @@ -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; @@ -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) diff --git a/SwitchUSB/source/SwitchHDLHandler.cpp b/SwitchUSB/source/SwitchHDLHandler.cpp index 6449e66..6449a13 100644 --- a/SwitchUSB/source/SwitchHDLHandler.cpp +++ b/SwitchUSB/source/SwitchHDLHandler.cpp @@ -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() diff --git a/config/sys-con/config_dualshock3.ini b/config/sys-con/config_dualshock3.ini index c3d9baf..6afb431 100644 --- a/config/sys-con/config_dualshock3.ini +++ b/config/sys-con/config_dualshock3.ini @@ -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" diff --git a/config/sys-con/config_dualshock4.ini b/config/sys-con/config_dualshock4.ini index 12bd0b5..aa7d521 100644 --- a/config/sys-con/config_dualshock4.ini +++ b/config/sys-con/config_dualshock4.ini @@ -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 \ No newline at end of file +;key_SYNC = LSTICK_CLICK ; Remove the semicolon at the start to take effect + diff --git a/config/sys-con/config_global.ini b/config/sys-con/config_global.ini index 187ba35..f94dcc7 100644 --- a/config/sys-con/config_global.ini +++ b/config/sys-con/config_global.ini @@ -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 \ No newline at end of file +[global] +use_dualshock_2nd_generation = false \ No newline at end of file diff --git a/config/sys-con/config_xbox360.ini b/config/sys-con/config_xbox360.ini index 8dfd6b4..25e8cd0 100644 --- a/config/sys-con/config_xbox360.ini +++ b/config/sys-con/config_xbox360.ini @@ -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" diff --git a/config/sys-con/config_xboxone.ini b/config/sys-con/config_xboxone.ini index 714ba06..3d20016 100644 --- a/config/sys-con/config_xboxone.ini +++ b/config/sys-con/config_xboxone.ini @@ -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" diff --git a/config/sys-con/config_xboxoneadapter.ini b/config/sys-con/config_xboxoneadapter.ini index c019b3e..ffe2b4b 100644 --- a/config/sys-con/config_xboxoneadapter.ini +++ b/config/sys-con/config_xboxoneadapter.ini @@ -1 +1,2 @@ +; Doesn't work properly yet, disabled firmware_path = /config/sys-con/firmware/XboxOneAdapter.bin \ No newline at end of file diff --git a/config/sys-con/config_xboxorig.ini b/config/sys-con/config_xboxorig.ini index db4f777..55ae912 100644 --- a/config/sys-con/config_xboxorig.ini +++ b/config/sys-con/config_xboxorig.ini @@ -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" diff --git a/config/sys-con/example.ini b/config/sys-con/example.ini index d47c94c..238170b 100644 --- a/config/sys-con/example.ini +++ b/config/sys-con/example.ini @@ -30,6 +30,7 @@ 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 @@ -37,3 +38,11 @@ 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 diff --git a/source/configFile.cpp b/source/configFile.cpp index 4e48c40..35ea5df 100644 --- a/source/configFile.cpp +++ b/source/configFile.cpp @@ -1,3 +1,4 @@ +#include "mainLoop.h" #include "configFile.h" #include "Controllers.h" #include "ControllerConfig.h" @@ -36,6 +37,7 @@ std::array keyNames{ "DPAD_LEFT", "SYNC", "GUIDE", + "TOUCHPAD", }; static ControllerButton _StringToKey(const char *text) @@ -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; - } - else if (strncmp(name, "color_", 6) == 0) - { - if (strcmp(name + 6, "body") == 0) + if (strcmp(name, "use_dualshock_2nd_generation") == 0) { - temp_config.bodyColor = _DecodeColorValue(value); + global_config.dualshock4_productID = (strcmp(value, "true") ? PRODUCT_DUALSHOCK4_1X : PRODUCT_DUALSHOCK4_2X); return 1; } - else if (strcmp(name + 6, "buttons") == 0) + } + else + { + if (strncmp(name, "key_", 4) == 0) { - temp_config.buttonsColor = _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, "leftGrip") == 0) + else if (strcmp(name, "left_stick_deadzone") == 0) { - temp_config.leftGripColor = _DecodeColorValue(value); + temp_config.leftStickDeadzonePercent = atoi(value); return 1; } - else if (strcmp(name + 6, "rightGrip") == 0) + else if (strcmp(name, "right_stick_deadzone") == 0) { - temp_config.rightGripColor = _DecodeColorValue(value); + 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; + } + 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; @@ -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); diff --git a/source/configFile.h b/source/configFile.h index 8cfe029..c84bfee 100644 --- a/source/configFile.h +++ b/source/configFile.h @@ -1,5 +1,4 @@ #pragma once - #define CONFIG_PATH "/config/sys-con/" void LoadAllConfigs(); diff --git a/source/mainLoop.cpp b/source/mainLoop.cpp index 0ba4402..67160b2 100644 --- a/source/mainLoop.cpp +++ b/source/mainLoop.cpp @@ -1,4 +1,5 @@ #include +#include "mainLoop.h" #include #include "log.h" @@ -8,7 +9,7 @@ #include "SwitchAbstractedPadHandler.h" #include "configFile.h" -#define APP_VERSION "0.4.3" +#define APP_VERSION "0.5.0" struct VendorEvent { @@ -48,6 +49,27 @@ std::unique_ptr controllerPtr; bool useAbstractedPad = hosversionBetween(5, 7); std::vector> controllerInterfaces; +static GlobalConfig _globalConfig{}; + +void LoadGlobalConfig(const GlobalConfig *config) +{ + _globalConfig = *config; +} + +Result CreateDualshock4AvailableEvent(Event &event) +{ + UsbHsInterfaceFilter filter; + filter.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct; + filter.idVendor = VENDOR_SONY; + filter.idProduct = _globalConfig.dualshock4_productID; + Result rc = usbHsCreateInterfaceAvailableEvent(&event, true, 2, &filter); + if (R_FAILED(rc)) + WriteToLog("Failed to open event for Dualshock 4 0x", std::hex, _globalConfig.dualshock4_productID); + else + WriteToLog("Successfully created event for Dualshock 4 0x", std::hex, _globalConfig.dualshock4_productID); + return rc; +} + Result CallInitHandler() { if (controllerPtr) @@ -112,7 +134,7 @@ Result mainLoop() WriteToLog("Failed to open catch-all event"); else WriteToLog("Successfully created catch-all event"); - + /* filter.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct; filter.idVendor = VENDOR_SONY; filter.idProduct = PRODUCT_DUALSHOCK4_2X; @@ -121,16 +143,9 @@ Result mainLoop() WriteToLog("Failed to open event for Dualshock 4 2x"); else WriteToLog("Successfully created event for Dualshock 4 2x"); - /* - filter.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct; - filter.idVendor = VENDOR_SONY; - filter.idProduct = PRODUCT_DUALSHOCK4_1X; - rc = usbHsCreateInterfaceAvailableEvent(&ds4Event, true, 2, &filter); - if (R_FAILED(rc)) - WriteToLog("Failed to open event for Dualshock 4 1x"); - else - WriteToLog("Successfully created event for Dualshock 4 1x"); */ + + CreateDualshock4AvailableEvent(ds4Event); } controllerInterfaces.reserve(10); @@ -203,12 +218,14 @@ Result mainLoop() devicePtr = std::make_unique(interfaces, total_entries); controllerPtr = std::make_unique(std::move(devicePtr)); } + /* else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 255, 255))) { WriteToLog("Registering Xbox One adapter"); devicePtr = std::make_unique(interfaces, total_entries); controllerPtr = std::make_unique(std::move(devicePtr)); } + */ } } rc = eventWait(&ds3Event, 0); @@ -289,6 +306,8 @@ Result mainLoop() { WriteToLog("File check succeeded! Loading configs..."); LoadAllConfigs(); + usbHsDestroyInterfaceAvailableEvent(&ds4Event, 2); + CreateDualshock4AvailableEvent(ds4Event); } } diff --git a/source/mainLoop.h b/source/mainLoop.h index 0f265a1..3be95d3 100644 --- a/source/mainLoop.h +++ b/source/mainLoop.h @@ -1,4 +1,11 @@ #pragma once #include "switch/result.h" -Result mainLoop(); \ No newline at end of file +struct GlobalConfig +{ + uint16_t dualshock4_productID; +}; + +Result mainLoop(); + +void LoadGlobalConfig(const GlobalConfig *config); \ No newline at end of file