1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-07-08 03:58:43 +00:00

Finalize 0.5.0

This commit is contained in:
cathery 2019-11-15 14:03:06 +03:00
parent 9be2b8cf40
commit 781129b467
15 changed files with 171 additions and 79 deletions

View File

@ -21,6 +21,7 @@ enum ControllerButton
DPAD_LEFT, DPAD_LEFT,
SYNC, SYNC,
GUIDE, GUIDE,
TOUCHPAD,
NUM_CONTROLLERBUTTONS, NUM_CONTROLLERBUTTONS,
}; };

View File

@ -17,8 +17,8 @@ Result Dualshock4Controller::SendInitBytes()
{ {
constexpr uint8_t init_bytes[32] = { constexpr uint8_t init_bytes[32] = {
0x05, 0x07, 0x00, 0x00, 0x05, 0x07, 0x00, 0x00,
0x7f, 0x7f, 0x00, 0x00, //initial strong and weak rumble
0x00, 0x00, 0x40, 0x00, 0x00, 0x40, //LED color
0x00, 0x00}; 0x00, 0x00};
return m_outPipe->Write(init_bytes, sizeof(init_bytes)); return m_outPipe->Write(init_bytes, sizeof(init_bytes));
@ -57,6 +57,12 @@ Result Dualshock4Controller::OpenInterfaces()
if (R_FAILED(rc)) if (R_FAILED(rc))
return rc; return rc;
if (interface->GetDescriptor()->bInterfaceClass != 3)
continue;
if (interface->GetDescriptor()->bInterfaceProtocol != 0)
continue;
if (interface->GetDescriptor()->bNumEndpoints < 2) if (interface->GetDescriptor()->bNumEndpoints < 2)
continue; 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.dpad == DS4_LEFT) || (m_buttonData.dpad == DS4_UPLEFT) || (m_buttonData.dpad == DS4_DOWNLEFT),
m_buttonData.touchpad_press, m_buttonData.touchpad_press,
m_buttonData.psbutton, m_buttonData.psbutton,
m_buttonData.touchpad_finger1_unpressed == false,
}; };
for (int i = 0; i != NUM_CONTROLLERBUTTONS; ++i) for (int i = 0; i != NUM_CONTROLLERBUTTONS; ++i)

View File

@ -151,6 +151,7 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)
m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0); m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0);
m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0); m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0);
m_hdlState.buttons |= (data.buttons[18] ? KEY_TOUCH : 0);
} }
void SwitchHDLHandler::UpdateInput() void SwitchHDLHandler::UpdateInput()

View File

@ -3,6 +3,13 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 10 ; from 0 to 100 right_stick_deadzone = 10 ; from 0 to 100
trigger_deadzone = 0 ; 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 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" ; For information on input mapping, see "example.ini"

View File

@ -3,7 +3,15 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 10 ; from 0 to 100 right_stick_deadzone = 10 ; from 0 to 100
trigger_deadzone = 0 ; 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 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" ; 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

View File

@ -1,11 +1,2 @@
; Global overwrite config. Controller configs take priority. Doesn't work also [global]
;left_stick_deadzone = 0 ; from 0 to 100 use_dualshock_2nd_generation = false
;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

View File

@ -3,6 +3,13 @@ left_stick_deadzone = 21 ; from 0 to 100
right_stick_deadzone = 25 ; from 0 to 100 right_stick_deadzone = 25 ; from 0 to 100
trigger_deadzone = 0 ; 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 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" ; For information on input mapping, see "example.ini"

View File

@ -3,6 +3,13 @@ left_stick_deadzone = 10 ; from 0 to 100
right_stick_deadzone = 17 ; from 0 to 100 right_stick_deadzone = 17 ; from 0 to 100
trigger_deadzone = 0 ; 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 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" ; For information on input mapping, see "example.ini"

View File

@ -1 +1,2 @@
; Doesn't work properly yet, disabled
firmware_path = /config/sys-con/firmware/XboxOneAdapter.bin firmware_path = /config/sys-con/firmware/XboxOneAdapter.bin

View File

@ -3,6 +3,13 @@ left_stick_deadzone = 21 ; from 0 to 100
right_stick_deadzone = 25 ; from 0 to 100 right_stick_deadzone = 25 ; from 0 to 100
trigger_deadzone = 0 ; 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 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" ; For information on input mapping, see "example.ini"

View File

@ -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 ; DPAD_LEFT D-pad LEFT
; SYNC Capture on joycons ; SYNC Capture on joycons
; GUIDE Home 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 ; 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_DOWN = FACE_RIGHT
@ -37,3 +38,11 @@ key_FACE_LEFT = FACE_UP
; example: this will press the Capture button on Left stick press ; example: this will press the Capture button on Left stick press
key_LSTICK_CLICK = SYNC 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

View File

@ -1,3 +1,4 @@
#include "mainLoop.h"
#include "configFile.h" #include "configFile.h"
#include "Controllers.h" #include "Controllers.h"
#include "ControllerConfig.h" #include "ControllerConfig.h"
@ -36,6 +37,7 @@ std::array<const char *, NUM_CONTROLLERBUTTONS> keyNames{
"DPAD_LEFT", "DPAD_LEFT",
"SYNC", "SYNC",
"GUIDE", "GUIDE",
"TOUCHPAD",
}; };
static ControllerButton _StringToKey(const char *text) static ControllerButton _StringToKey(const char *text)
@ -70,75 +72,87 @@ static RGBAColor _DecodeColorValue(const char *value)
} }
static ControllerConfig temp_config; static ControllerConfig temp_config;
static GlobalConfig global_config;
static char firmwarePath[100]; static char firmwarePath[100];
static int _ParseConfigLine(void *dummy, const char *section, const char *name, const char *value) 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); if (strcmp(name, "use_dualshock_2nd_generation") == 0)
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)
{ {
temp_config.bodyColor = _DecodeColorValue(value); global_config.dualshock4_productID = (strcmp(value, "true") ? PRODUCT_DUALSHOCK4_1X : PRODUCT_DUALSHOCK4_2X);
return 1; 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; 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; 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; 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; return 0;
@ -156,6 +170,13 @@ static Result _ReadFromConfig(const char *path)
void LoadAllConfigs() 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))) if (R_SUCCEEDED(_ReadFromConfig(CONFIG_PATH XBOXCONFIG)))
{ {
XboxController::LoadConfig(&temp_config); XboxController::LoadConfig(&temp_config);

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#define CONFIG_PATH "/config/sys-con/" #define CONFIG_PATH "/config/sys-con/"
void LoadAllConfigs(); void LoadAllConfigs();

View File

@ -1,4 +1,5 @@
#include <switch.h> #include <switch.h>
#include "mainLoop.h"
#include <variant> #include <variant>
#include "log.h" #include "log.h"
@ -8,7 +9,7 @@
#include "SwitchAbstractedPadHandler.h" #include "SwitchAbstractedPadHandler.h"
#include "configFile.h" #include "configFile.h"
#define APP_VERSION "0.4.3" #define APP_VERSION "0.5.0"
struct VendorEvent struct VendorEvent
{ {
@ -48,6 +49,27 @@ std::unique_ptr<IController> controllerPtr;
bool useAbstractedPad = hosversionBetween(5, 7); bool useAbstractedPad = hosversionBetween(5, 7);
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerInterfaces; std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> 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() Result CallInitHandler()
{ {
if (controllerPtr) if (controllerPtr)
@ -112,7 +134,7 @@ Result mainLoop()
WriteToLog("Failed to open catch-all event"); WriteToLog("Failed to open catch-all event");
else else
WriteToLog("Successfully created catch-all event"); WriteToLog("Successfully created catch-all event");
/*
filter.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct; filter.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct;
filter.idVendor = VENDOR_SONY; filter.idVendor = VENDOR_SONY;
filter.idProduct = PRODUCT_DUALSHOCK4_2X; filter.idProduct = PRODUCT_DUALSHOCK4_2X;
@ -121,16 +143,9 @@ Result mainLoop()
WriteToLog("Failed to open event for Dualshock 4 2x"); WriteToLog("Failed to open event for Dualshock 4 2x");
else else
WriteToLog("Successfully created event for Dualshock 4 2x"); 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); controllerInterfaces.reserve(10);
@ -203,12 +218,14 @@ Result mainLoop()
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries); devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
controllerPtr = std::make_unique<XboxOneController>(std::move(devicePtr)); controllerPtr = std::make_unique<XboxOneController>(std::move(devicePtr));
} }
/*
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 255, 255))) else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 255, 255)))
{ {
WriteToLog("Registering Xbox One adapter"); WriteToLog("Registering Xbox One adapter");
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries); devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
controllerPtr = std::make_unique<XboxOneAdapter>(std::move(devicePtr)); controllerPtr = std::make_unique<XboxOneAdapter>(std::move(devicePtr));
} }
*/
} }
} }
rc = eventWait(&ds3Event, 0); rc = eventWait(&ds3Event, 0);
@ -289,6 +306,8 @@ Result mainLoop()
{ {
WriteToLog("File check succeeded! Loading configs..."); WriteToLog("File check succeeded! Loading configs...");
LoadAllConfigs(); LoadAllConfigs();
usbHsDestroyInterfaceAvailableEvent(&ds4Event, 2);
CreateDualshock4AvailableEvent(ds4Event);
} }
} }

View File

@ -1,4 +1,11 @@
#pragma once #pragma once
#include "switch/result.h" #include "switch/result.h"
Result mainLoop(); struct GlobalConfig
{
uint16_t dualshock4_productID;
};
Result mainLoop();
void LoadGlobalConfig(const GlobalConfig *config);