diff --git a/ControllerPatcher.cpp b/ControllerPatcher.cpp index efe6290..4011763 100644 --- a/ControllerPatcher.cpp +++ b/ControllerPatcher.cpp @@ -136,12 +136,18 @@ void ControllerPatcher::ResetConfig(){ u32 xinput_hid = slotdata.hidmask; if(HID_DEBUG) log_printf("ControllerPatcher::ResetConfig(line %d): Register XInput-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(xinput_hid),xinput_slot); + ControllerPatcherUtils::getNextSlotData(&slotdata); + u32 switch_pro_slot = slotdata.deviceslot; + gHID_LIST_SWITCH_PRO = slotdata.hidmask; + log_printf("ControllerPatcher::ResetConfig(line %d): Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot); + config_controller_hidmask[gc_slot] = gHID_LIST_GC; config_controller_hidmask[ds3_slot] = gHID_LIST_DS3; config_controller_hidmask[keyboard_slot] = gHID_LIST_KEYBOARD; config_controller_hidmask[gMouseSlot] = gHID_LIST_MOUSE; config_controller_hidmask[ds4_slot] = ds4_hid; config_controller_hidmask[xinput_slot] = xinput_hid; + config_controller_hidmask[switch_pro_slot] = gHID_LIST_SWITCH_PRO; /* We need to give the GamePad, Mouse and Keyboard a unique VID/PID to find the right slots.*/ //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -150,6 +156,57 @@ void ControllerPatcher::ResetConfig(){ ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_VID], 0xAF,0xFE); ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_PID], 0xAA,0xAA); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //! Switch Pro Controller + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VID], (HID_SWITCH_PRO_VID>>8)&0xFF, HID_SWITCH_PRO_VID&0xFF); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_PID], (HID_SWITCH_PRO_PID>>8)&0xFF, HID_SWITCH_PRO_PID&0xFF); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_A], HID_SWITCH_PRO_BT_BUTTON_A[0], HID_SWITCH_PRO_BT_BUTTON_A[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_B], HID_SWITCH_PRO_BT_BUTTON_B[0], HID_SWITCH_PRO_BT_BUTTON_B[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_X], HID_SWITCH_PRO_BT_BUTTON_X[0], HID_SWITCH_PRO_BT_BUTTON_X[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_Y], HID_SWITCH_PRO_BT_BUTTON_Y[0], HID_SWITCH_PRO_BT_BUTTON_Y[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_N], HID_SWITCH_PRO_BT_BUTTON_DPAD_N[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_N[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NE], HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_E], HID_SWITCH_PRO_BT_BUTTON_DPAD_E[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_E[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_SE], HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_S], HID_SWITCH_PRO_BT_BUTTON_DPAD_S[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_S[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_SW], HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_W], HID_SWITCH_PRO_BT_BUTTON_DPAD_W[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_W[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NW], HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_SWITCH_PRO_BT_BUTTON_PLUS[0], HID_SWITCH_PRO_BT_BUTTON_PLUS[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_SWITCH_PRO_BT_BUTTON_MINUS[0], HID_SWITCH_PRO_BT_BUTTON_MINUS[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L], HID_SWITCH_PRO_BT_BUTTON_L[0], HID_SWITCH_PRO_BT_BUTTON_L[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R], HID_SWITCH_PRO_BT_BUTTON_R[0], HID_SWITCH_PRO_BT_BUTTON_R[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_ZL], HID_SWITCH_PRO_BT_BUTTON_ZL[0], HID_SWITCH_PRO_BT_BUTTON_ZL[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_ZR], HID_SWITCH_PRO_BT_BUTTON_ZR[0], HID_SWITCH_PRO_BT_BUTTON_ZR[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_SWITCH_PRO_BT_BUTTON_STICK_L[0], HID_SWITCH_PRO_BT_BUTTON_STICK_L[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_SWITCH_PRO_BT_BUTTON_STICK_R[0], HID_SWITCH_PRO_BT_BUTTON_STICK_R[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_HOME], HID_SWITCH_PRO_BT_BUTTON_HOME[0], HID_SWITCH_PRO_BT_BUTTON_HOME[1]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_PAD_COUNT); + + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_DEFAULT]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_DEADZONE]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_MAX]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_INVERT]); + + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_DEFAULT]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_DEADZONE]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_MAX]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_INVERT]); + + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_DEFAULT]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_DEADZONE]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_MAX]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_INVERT]); + + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_DEFAULT]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_DEADZONE]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_MAX]); + ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_INVERT]); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Mouse //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -495,6 +552,7 @@ void ControllerPatcher::DeInit(){ gHID_LIST_DS3 = 0; gHID_LIST_KEYBOARD = 0; gHID_LIST_MOUSE = 0; + gHID_LIST_SWITCH_PRO = 0; gGamePadSlot = 0; gHID_SLOT_GC = 0; diff --git a/config/ConfigValues.cpp b/config/ConfigValues.cpp index 11badd9..5d5183f 100644 --- a/config/ConfigValues.cpp +++ b/config/ConfigValues.cpp @@ -45,6 +45,7 @@ bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,s32 slot,s3 if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetXInputValues,value,slot,keyslot)) return true; + if(setIfValueIsPreset(presetSwitchProValues,value,slot,keyslot)) return true; return false; } diff --git a/config/ConfigValues.hpp b/config/ConfigValues.hpp index 9dc36ed..70e32bd 100644 --- a/config/ConfigValues.hpp +++ b/config/ConfigValues.hpp @@ -163,6 +163,7 @@ private: std::map presetDS3Values; std::map presetDS4Values; std::map presetXInputValues; + std::map presetSwitchProValues; std::map presetSticks; s32 getValueFromMap(std::map values,std::string nameOfString); @@ -272,12 +273,10 @@ private: CONTPRStringToValueSingle["DOUBLE_USE"] = CONTRPS_DOUBLE_USE; CONTPRStringToValueSingle["PAD_COUNT"] = CONTRPS_PAD_COUNT; - mouseLeftValues["LEFT_CLICK"] = CONTRPS_VPAD_BUTTON_LEFT; mouseLeftValues["RIGHT_CLICK"] = CONTRPS_VPAD_BUTTON_RIGHT; mouseLeftValues["EMULATED_STICK"] = CONTRPS_MOUSE_STICK; - presetGCValues["GC_BUTTON_A"] = HID_GC_BUTTON_A; presetGCValues["GC_BUTTON_B"] = HID_GC_BUTTON_B; presetGCValues["GC_BUTTON_X"] = HID_GC_BUTTON_X; @@ -363,6 +362,34 @@ private: presetXInputValues["XINPUT_BUTTON_GUIDE"] = HID_XINPUT_BUTTON_GUIDE; + presetSwitchProValues["SWITCH_PRO_BUTTON_A"] = HID_SWITCH_PRO_BT_BUTTON_A; + presetSwitchProValues["SWITCH_PRO_BUTTON_B"] = HID_SWITCH_PRO_BT_BUTTON_B; + presetSwitchProValues["SWITCH_PRO_BUTTON_X"] = HID_SWITCH_PRO_BT_BUTTON_X; + presetSwitchProValues["SWITCH_PRO_BUTTON_Y"] = HID_SWITCH_PRO_BT_BUTTON_Y; + + presetSwitchProValues["SWITCH_PRO_BUTTON_PLUS"] = HID_SWITCH_PRO_BT_BUTTON_PLUS; + presetSwitchProValues["SWITCH_PRO_BUTTON_MINUS"] = HID_SWITCH_PRO_BT_BUTTON_MINUS; + presetSwitchProValues["SWITCH_PRO_BUTTON_HOME"] = HID_SWITCH_PRO_BT_BUTTON_HOME; + + presetSwitchProValues["SWITCH_PRO_BUTTON_L"] = HID_SWITCH_PRO_BT_BUTTON_L; + presetSwitchProValues["SWITCH_PRO_BUTTON_R"] = HID_SWITCH_PRO_BT_BUTTON_R; + + presetSwitchProValues["SWITCH_PRO_BUTTON_ZL"] = HID_SWITCH_PRO_BT_BUTTON_ZL; + presetSwitchProValues["SWITCH_PRO_BUTTON_ZR"] = HID_SWITCH_PRO_BT_BUTTON_ZR; + + presetSwitchProValues["SWITCH_PRO_BUTTON_STICK_L"] = HID_SWITCH_PRO_BT_BUTTON_STICK_L; + presetSwitchProValues["SWITCH_PRO_BUTTON_STICK_R"] = HID_SWITCH_PRO_BT_BUTTON_STICK_R; + + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_N"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_N; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NE; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_E"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_E; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_SE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_SE; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_S"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_S; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_SW"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_SW; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_W"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_W; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NW"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NW; + presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NEUTRAL"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL; + presetKeyboardValues["KEYBOARD_SHIFT"] = HID_KEYBOARD_BUTTON_SHIFT; presetKeyboardValues["KEYBOARD_A"] = HID_KEYBOARD_BUTTON_A; presetKeyboardValues["KEYBOARD_B"] = HID_KEYBOARD_BUTTON_B; @@ -486,10 +513,16 @@ private: presetSticks["XINPUT_STICK_R_X"] = HID_XINPUT_STICK_R_X; presetSticks["XINPUT_STICK_R_Y"] = HID_XINPUT_STICK_R_Y; + presetSticks["SWITCH_PRO_STICK_L_X"] = HID_SWITCH_PRO_BT_STICK_L_X; + presetSticks["SWITCH_PRO_STICK_L_Y"] = HID_SWITCH_PRO_BT_STICK_L_Y; + presetSticks["SWITCH_PRO_STICK_R_X"] = HID_SWITCH_PRO_BT_STICK_R_X; + presetSticks["SWITCH_PRO_STICK_R_Y"] = HID_SWITCH_PRO_BT_STICK_R_Y; + presetSticks["GC_DPAD_MODE"] = HID_GC_BUTTON_DPAD_TYPE; presetSticks["DS3_DPAD_MODE"] = HID_DS3_BUTTON_DPAD_TYPE; presetSticks["DS4_DPAD_MODE"] = HID_DS4_BUTTON_DPAD_TYPE; presetSticks["XINPUT_DPAD_MODE"] = HID_XINPUT_BUTTON_DPAD_TYPE; + presetSticks["SWITCH_PRO_DPAD_MODE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE; gGamePadValuesToCONTRPSString["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A; gGamePadValuesToCONTRPSString["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B; @@ -520,14 +553,14 @@ private: gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP; gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_KEYBOARD_VID, HID_KEYBOARD_PID).c_str()] = HID_KEYBOARD_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS3_VID, HID_DS3_PID).c_str()] = HID_DS3_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_NEW_DS4_VID, HID_NEW_DS4_PID).c_str()] = HID_NEW_DS4_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_DS4_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_XINPUT_VID, HID_XINPUT_PID).c_str()] = HID_XINPUT_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID, HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_KEYBOARD_VID, HID_KEYBOARD_PID).c_str()] = HID_KEYBOARD_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS3_VID, HID_DS3_PID).c_str()] = HID_DS3_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_NEW_DS4_VID, HID_NEW_DS4_PID).c_str()] = HID_NEW_DS4_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_DS4_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_XINPUT_VID, HID_XINPUT_PID).c_str()] = HID_XINPUT_STRING; + deviceNames[CPStringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID,HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING; } const u8 * getValuesForPreset(std::map values,std::string possibleValue); diff --git a/patcher/ControllerPatcherDefs.h b/patcher/ControllerPatcherDefs.h index 5a81cdc..44b0dd7 100644 --- a/patcher/ControllerPatcherDefs.h +++ b/patcher/ControllerPatcherDefs.h @@ -523,6 +523,62 @@ enum UController_Type{ #define HID_XINPUT_PAD_COUNT 1 +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * Switch Pro Controller + *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ + +#define HID_SWITCH_PRO_USB_BUTTON_A_VALUE 0x08000000 +#define HID_SWITCH_PRO_USB_BUTTON_B_VALUE 0x04000000 +#define HID_SWITCH_PRO_USB_BUTTON_X_VALUE 0x02000000 +#define HID_SWITCH_PRO_USB_BUTTON_Y_VALUE 0x01000000 +#define HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE 0x00020000 +#define HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE 0x00010000 +#define HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE 0x00100000 +#define HID_SWITCH_PRO_USB_BUTTON_SCREENSHOT_VALUE 0x00200000 +#define HID_SWITCH_PRO_USB_BUTTON_R_VALUE 0x40000000 +#define HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE 0x80000000 +#define HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE 0x00040000 +#define HID_SWITCH_PRO_USB_BUTTON_L_VALUE 0x00004000 +#define HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE 0x00008000 +#define HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE 0x00080000 + +#define HID_SWITCH_PRO_USB_BUTTON_DPAD_MASK_VALUE 0x0F +#define HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE 0x08 // 2 +#define HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE 0x04 // 2 +#define HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE 0x01 // 2 +#define HID_SWITCH_PRO_USB_BUTTON_UP_VALUE 0x02 // 2 + +#define HID_SWITCH_PRO_BT_BUTTON_A_VALUE 0x02000000 +#define HID_SWITCH_PRO_BT_BUTTON_B_VALUE 0x01000000 +#define HID_SWITCH_PRO_BT_BUTTON_X_VALUE 0x08000000 +#define HID_SWITCH_PRO_BT_BUTTON_Y_VALUE 0x04000000 +#define HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE 0x00020000 +#define HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE 0x00010000 +#define HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE 0x00100000 + +#define HID_SWITCH_PRO_BT_BUTTON_R_VALUE 0x20000000 +#define HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE 0x80000000 +#define HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE 0x00080000 + +#define HID_SWITCH_PRO_BT_BUTTON_L_VALUE 0x10000000 +#define HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE 0x40000000 +#define HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE 0x00040000 + + +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_MASK_VALUE 0x0F +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE 0x00 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE 0x01 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE 0x02 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE 0x03 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE 0x04 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE 0x05 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE 0x06 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE 0x07 // 2 +#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE 0x08 // 2 + + +#define HID_SWITCH_PRO_BT_PAD_COUNT 1 + /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Keyboard (Full list is on: http://www.freebsddiary.org/APC/usb_hid_usages.php) *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ diff --git a/patcher/ControllerPatcherHID.cpp b/patcher/ControllerPatcherHID.cpp index fe3e4b8..264c634 100644 --- a/patcher/ControllerPatcherHID.cpp +++ b/patcher/ControllerPatcherHID.cpp @@ -242,6 +242,34 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p HIDSetIdle(p_device->handle,p_device->interface_index,1,NULL,NULL); gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; HIDRead(p_device->handle, buf, p_device->max_packet_size_rx, myHIDMouseReadCallback, usr); + }else if (slotdata->hidmask == gHID_LIST_SWITCH_PRO){ + s32 read_result = HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); + if(read_result == 64){ + if(usr->buf[01] == 0x01){ //We need to do the handshake + log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake needed\n",__LINE__); + /** + Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering) + **/ + //Get MAC + buf[0] = 0x80; + buf[1] = 0x01; + HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); + HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); + //Do handshake + buf[0] = 0x80; + buf[1] = 0x02; + HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); + HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); + //Talk over HID only. + buf[0] = 0x80; + buf[1] = 0x04; + HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); + HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); + }else{ + log_printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake already done\n",__LINE__); + } + HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr); + } }else if (slotdata->hidmask == gHID_LIST_KEYBOARD){ HIDSetProtocol(p_device->handle, p_device->interface_index, 1, 0, 0); HIDSetIdle(p_device->handle, p_device->interface_index, 0, 0, 0); @@ -312,56 +340,141 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p } void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){ - //log_printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot); - if(usr->slotdata.hidmask == gHID_LIST_GC){ + //log_printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot); + if(usr->slotdata.hidmask == gHID_LIST_GC){ - HID_Data * data_ptr = NULL; - //Copy the data for all 4 pads - for(s32 i = 0;i<4;i++){ - data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]); - memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data. - memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data. + HID_Data * data_ptr = NULL; + //Copy the data for all 4 pads + for(s32 i = 0;i<4;i++){ + data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]); + memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data. + memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data. - } + } - /* - s32 i = 0; - log_printf("GC1 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - log_printf("GC2 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - log_printf("GC3 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - log_printf("GC4 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);*/ - HIDGCRumble(handle,usr); - }else if(usr->slotdata.hidmask != 0){ + /* + s32 i = 0; + log_printf("GC1 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; + log_printf("GC2 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; + log_printf("GC3 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; + log_printf("GC4 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);*/ + HIDGCRumble(handle,usr); + }else if(usr->slotdata.hidmask != 0){ + //Depending on how the switch pro controller is connected, it has a different data format. At first we had the Bluetooth version, so we need to convert + //the USB one into it now. (When it's connected via USB). The network client always sends the BT version, even if connected via USB to the PC. + if(usr->slotdata.hidmask == gHID_LIST_SWITCH_PRO && buf != NULL && bytes_transfered >= 0x20){ + u8 buffer[0x13]; + memcpy(buffer,buf+0x0D,0x013); - s32 dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD; - s32 skip = 0; + /** + Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering) + **/ + buf[0] = 0x80; + buf[1] = 0x92; + buf[2] = 0x00; + buf[3] = 0x01; + buf[4] = 0x00; + buf[5] = 0x00; + buf[6] = 0x00; + buf[7] = 0x00; + buf[8] = 0x1F; + //We want to get the next input! + s32 res = HIDWrite(handle, buf, 9, NULL,NULL); - //Input filter - if( config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(buf[config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0]] != config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][1]){ - skip = 1; + if(res == 9){ //Check if it's the USB data format. + if(buffer[1] == 0) return; + //Converting the buttons + u32 buttons = (((u32*)(buffer))[0]) & 0xFFFFFF00; + u32 newButtons = 0; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_A_VALUE) == HID_SWITCH_PRO_USB_BUTTON_A_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_A_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_B_VALUE) == HID_SWITCH_PRO_USB_BUTTON_B_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_B_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_X_VALUE) == HID_SWITCH_PRO_USB_BUTTON_X_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_X_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_Y_VALUE) == HID_SWITCH_PRO_USB_BUTTON_Y_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_Y_VALUE; + + if((buttons & HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE) == HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE) == HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE) == HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE; + //if((buttons & SWITCH_PRO_USB_BUTTON_SCREENSHOT) == HID_SWITCH_PRO_USB_BUTTON_SCREENSHOT) newButtons |= HID_SWITCH_PRO_BT_BUTTON_SCREENSHOT; + + if((buttons & HID_SWITCH_PRO_USB_BUTTON_R_VALUE) == HID_SWITCH_PRO_USB_BUTTON_R_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_R_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE) == HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE) == HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE; + + if((buttons & HID_SWITCH_PRO_USB_BUTTON_L_VALUE) == HID_SWITCH_PRO_USB_BUTTON_L_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_L_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE) == HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE; + if((buttons & HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE) == HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE; + + u8 dpad = buffer[2]; + u8 dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE; + + //Converting the DPAD + if(((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) && + ((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE)){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE; + }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) && + ((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE)){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE; + }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) && + ((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE)){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE; + }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) && + ((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE)){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE; + }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE; + }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE; + }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE; + }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE){ + dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE; } + + //Converting the stick data + u8 LX = (u8) ((u16) ((buffer[0x04] << 8 &0xFF00) | (((u16)buffer[0x03])&0xFF)) >> 0x04); + u8 LY = (u8)((buffer[0x05] *-1)); + u8 RX = (u8) ((u16) ((buffer[0x07] << 8 &0xFF00) | (((u16)buffer[0x06])&0xFF)) >> 0x04); + u8 RY = (u8)((buffer[0x08] *-1)); + + buf[0] = (newButtons >> 24) & 0xFF; + buf[1] = (newButtons >> 16) & 0xFF; + buf[2] |= dpadResult; + buf[4] = LX; + buf[6] = LY; + buf[8] = RX; + buf[10] = RY; } + } - if(!skip){ - u32 slot = 0; - if(usr->pad_slot < HID_MAX_PADS_COUNT){ - slot = usr->pad_slot; - } - slot += ControllerPatcherUtils::getPadSlotInAdapter(usr->slotdata.deviceslot,buf); // If the controller has multiple slots, we need to use the right one. + s32 dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD; + s32 skip = 0; - HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); - - memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),dsize); // save the last data. - memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[0],dsize); // save the new data. - - DCFlushRange(&gHID_Devices[usr->slotdata.deviceslot].pad_data[slot],sizeof(HID_Data)); - - data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); - - HIDRumble(handle,usr,slot); + //Input filter + if( config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(buf[config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0]] != config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][1]){ + skip = 1; } - } + } + + if(!skip){ + u32 slot = 0; + if(usr->pad_slot < HID_MAX_PADS_COUNT){ + slot = usr->pad_slot; + } + slot += ControllerPatcherUtils::getPadSlotInAdapter(usr->slotdata.deviceslot,buf); // If the controller has multiple slots, we need to use the right one. + + HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); + + memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),dsize); // save the last data. + memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[0],dsize); // save the new data. + + DCFlushRange(&gHID_Devices[usr->slotdata.deviceslot].pad_data[slot],sizeof(HID_Data)); + + data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); + + HIDRumble(handle,usr,slot); + } + } } /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/utils/CPRetainVars.cpp b/utils/CPRetainVars.cpp index ad4ace0..9cec19b 100644 --- a/utils/CPRetainVars.cpp +++ b/utils/CPRetainVars.cpp @@ -43,6 +43,7 @@ u32 config_controller_hidmask[gHIDMaxDevices] __attribute__((section(".data"))); u32 gHID_LIST_GC __attribute__((section(".data"))) = 0; u32 gHID_LIST_DS3 __attribute__((section(".data"))) = 0; u32 gHID_LIST_KEYBOARD __attribute__((section(".data"))) = 0; +u32 gHID_LIST_SWITCH_PRO __attribute__((section(".data"))) = 0; u32 gHID_LIST_MOUSE __attribute__((section(".data"))) = 0; u16 gGamePadSlot __attribute__((section(".data"))) = 0; diff --git a/utils/CPRetainVars.hpp b/utils/CPRetainVars.hpp index 2a40924..2a6475d 100644 --- a/utils/CPRetainVars.hpp +++ b/utils/CPRetainVars.hpp @@ -44,6 +44,7 @@ extern u32 config_controller_hidmask[gHIDMaxDevices]; extern u32 gHID_LIST_GC; extern u32 gHID_LIST_DS3; extern u32 gHID_LIST_KEYBOARD; +extern u32 gHID_LIST_SWITCH_PRO; extern u32 gHID_LIST_MOUSE; extern u16 gGamePadSlot; diff --git a/utils/PadConst.cpp b/utils/PadConst.cpp index 898754e..c3e2002 100644 --- a/utils/PadConst.cpp +++ b/utils/PadConst.cpp @@ -273,3 +273,70 @@ const u8 HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_ 0x00, //STICK_CONF_INVERT, 0x00, //STICK_CONF_MIN, 0xFF};//STICK_CONF_MAX, + + + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! Switch Pro Controller +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +const u8 HID_SWITCH_PRO_BT_BUTTON_A[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_A_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_B[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_B_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_X[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_X_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_Y[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_Y_VALUE >> 24) & 0xFF)}; + +const u8 HID_SWITCH_PRO_BT_BUTTON_L[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_L_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_ZL[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_L[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE >> 16) & 0xFF)}; + +const u8 HID_SWITCH_PRO_BT_BUTTON_R[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_R_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_ZR[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE >> 24) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_R[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE >> 16) & 0xFF)}; + +const u8 HID_SWITCH_PRO_BT_BUTTON_PLUS[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE >> 16) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_MINUS[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE >> 16) & 0xFF)}; +const u8 HID_SWITCH_PRO_BT_BUTTON_HOME[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE >> 16) & 0xFF)}; + +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[] = { CONTRPDM_Hat,HID_SWITCH_PRO_BT_BUTTON_DPAD_MASK_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_N[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_E[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_S[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_W[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE}; +const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE}; + + +const u8 HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x04, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x01, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x28, //STICK_CONF_MIN, + 0xDF};//STICK_CONF_MAX, + +const u8 HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x06, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x16, //STICK_CONF_MIN, + 0xD7};//STICK_CONF_MAX, + +const u8 HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x08, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x04, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x29, //STICK_CONF_MIN, + 0xE2};//STICK_CONF_MAX, + +const u8 HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x0A, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x08, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x22, //STICK_CONF_MIN, + 0xE4};//STICK_CONF_MAX, diff --git a/utils/PadConst.hpp b/utils/PadConst.hpp index 28a6aaa..02426b3 100644 --- a/utils/PadConst.hpp +++ b/utils/PadConst.hpp @@ -171,4 +171,42 @@ extern const u8 HID_XINPUT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; extern const u8 HID_XINPUT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; extern const u8 HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! Switch Pro Controller +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +extern const u8 HID_SWITCH_PRO_BT_BUTTON_A[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_B[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_X[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_Y[]; + +extern const u8 HID_SWITCH_PRO_BT_BUTTON_L[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_ZL[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_L[]; + +extern const u8 HID_SWITCH_PRO_BT_BUTTON_R[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_ZR[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_R[]; + +extern const u8 HID_SWITCH_PRO_BT_BUTTON_PLUS[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_MINUS[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_HOME[]; + +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_N[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_E[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_S[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_W[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[]; +extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[]; + + +extern const u8 HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; + #endif /* _PAD_CONST_H_ */