From c2e273f46f7f33056df759d49a7124d25e0b89f5 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 19 Jun 2018 17:46:37 +0200 Subject: [PATCH] Format the files --- .../controller_patcher/ControllerPatcher.hpp | 318 ++++----- .../ControllerPatcherDefs.h | 91 ++- source/ConfigReader.cpp | 52 +- source/ControllerPatcher.cpp | 323 +++++---- source/config/ConfigParser.cpp | 254 +++++--- source/config/ConfigValues.cpp | 66 +- source/network/CPTCPServer.hpp | 18 +- source/network/UDPClient.cpp | 37 +- source/network/UDPClient.hpp | 8 +- source/network/UDPServer.cpp | 130 ++-- source/network/UDPServer.hpp | 4 +- source/patcher/ControllerPatcherHID.cpp | 242 +++---- source/patcher/ControllerPatcherHID.hpp | 48 +- source/patcher/ControllerPatcherUtils.cpp | 612 ++++++++++-------- source/patcher/ControllerPatcherUtils.hpp | 396 ++++++------ source/utils/CPRetainVars.cpp | 7 +- source/utils/PadConst.cpp | 260 ++++---- 17 files changed, 1551 insertions(+), 1315 deletions(-) diff --git a/include/controller_patcher/ControllerPatcher.hpp b/include/controller_patcher/ControllerPatcher.hpp index 7ba0b03..fd46671 100644 --- a/include/controller_patcher/ControllerPatcher.hpp +++ b/include/controller_patcher/ControllerPatcher.hpp @@ -15,14 +15,14 @@ * along with this program. If not, see . ****************************************************************************/ - /** - * @file ControllerPatcher.hpp - * @author Maschell - * @date 30 Mar 2017 - * \brief This files contain all public accessible functions of the controller patcher engine - * - * @see https://github.com/Maschell/controller_patcher - */ +/** +* @file ControllerPatcher.hpp +* @author Maschell +* @date 30 Mar 2017 +* \brief This files contain all public accessible functions of the controller patcher engine +* +* @see https://github.com/Maschell/controller_patcher +*/ #ifndef _CONTROLLER_PATCHER_H_ #define _CONTROLLER_PATCHER_H_ @@ -33,219 +33,219 @@ #include #include "ControllerPatcherDefs.h" -class ControllerPatcher{ - public: - /*----------------------------------------------------------------------------------------------------------------------------------- - * Initialization - *----------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Resets the data thats used by the controller configuration - **/ - static void ResetConfig(); - /** - \brief Initializes the libraries, functions, values and arrays. Need to be called on each start of an Application. Returns false on errors. - @param pathToConfig: The path of the directory containing the configuration files. The path needs already to be mounted and accessible via the - devoptabs! If no configuration should be loaded from the SD Card, set this parameter to NULL. - **/ +class ControllerPatcher { +public: + /*----------------------------------------------------------------------------------------------------------------------------------- + * Initialization + *----------------------------------------------------------------------------------------------------------------------------------*/ + /** + \brief Resets the data thats used by the controller configuration + **/ + static void ResetConfig(); + /** + \brief Initializes the libraries, functions, values and arrays. Need to be called on each start of an Application. Returns false on errors. + @param pathToConfig: The path of the directory containing the configuration files. The path needs already to be mounted and accessible via the + devoptabs! If no configuration should be loaded from the SD Card, set this parameter to NULL. + **/ - static bool Init(const char * pathToConfig); + static bool Init(const char * pathToConfig); - /** - \brief De-Initialises the controller_patcher - **/ - static void DeInit(); - /** - Initialises the button remapping - **/ - static void InitButtonMapping(); + /** + \brief De-Initialises the controller_patcher + **/ + static void DeInit(); + /** + Initialises the button remapping + **/ + static void InitButtonMapping(); - /** - Starts the network server - **/ - static void startNetworkServer(); + /** + Starts the network server + **/ + static void startNetworkServer(); - /** - Stops the network server - **/ - static void stopNetworkServer(); + /** + Stops the network server + **/ + static void stopNetworkServer(); - /*----------------------------------------------------------------------------------------------------------------------------------- - * Initialization - *----------------------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------------------- + * Initialization + *----------------------------------------------------------------------------------------------------------------------------------*/ - /** - Sets the data in a given data from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array int slot 1-4 (counting starts at 0, which is the gamepad). The \p - chan provides the information of the channel from which the data will be used. The mode sets the type of the buffer. + /** + Sets the data in a given data from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array int slot 1-4 (counting starts at 0, which is the gamepad). The \p + chan provides the information of the channel from which the data will be used. The mode sets the type of the buffer. - @param buffer: A pointer to the struct where the result will be stored. - @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. - @param mode: Sets the type of the buffer. PRO_CONTROLLER_MODE_KPADDATA or PRO_CONTROLLER_MODE_WPADReadData + @param buffer: A pointer to the struct where the result will be stored. + @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. + @param mode: Sets the type of the buffer. PRO_CONTROLLER_MODE_KPADDATA or PRO_CONTROLLER_MODE_WPADReadData - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,s32 chan,s32 mode = PRO_CONTROLLER_MODE_KPADDATA); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,s32 chan,s32 mode = PRO_CONTROLLER_MODE_KPADDATA); - /** - Sets the data in a given VPADStatus from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array in slot 0. + /** + Sets the data in a given VPADStatus from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array in slot 0. - @param buffer: A pointer to an KPADData struct where the result will be stored. - @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. + @param buffer: A pointer to an KPADData struct where the result will be stored. + @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * buffer); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * buffer); - /*----------------------------------------------------------------------------------------------------------------------------------- - * Useful functions - *----------------------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------------------- + * Useful functions + *----------------------------------------------------------------------------------------------------------------------------------*/ - /** - Enable the Controller mapping. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR enableControllerMapping(); + /** + Enable the Controller mapping. + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR enableControllerMapping(); - /** - Disbale the Controller mapping. Afterwards all connected controllers will be used for the gamepad. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR disableControllerMapping(); + /** + Disbale the Controller mapping. Afterwards all connected controllers will be used for the gamepad. + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR disableControllerMapping(); - /** - Disables the energy settings for the WiiU. Settings can be restored via restoreWiiUEnergySetting. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR disableWiiUEnergySetting(); + /** + Disables the energy settings for the WiiU. Settings can be restored via restoreWiiUEnergySetting. + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR disableWiiUEnergySetting(); - /** - Restores the WiiU Energy Settings. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR restoreWiiUEnergySetting(); + /** + Restores the WiiU Energy Settings. + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR restoreWiiUEnergySetting(); - /** - Resets the controller mapping for a given controller type. + /** + Resets the controller mapping for a given controller type. - @param type: The type of the controller. + @param type: The type of the controller. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR resetControllerMapping(UController_Type type); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR resetControllerMapping(UController_Type type); - /** - Adds a controller mapping + /** + Adds a controller mapping - @param type: The type of the controller. - @param config: information about the added controller. + @param type: The type of the controller. + @param config: information about the added controller. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR addControllerMapping(UController_Type type,ControllerMappingPADInfo config); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR addControllerMapping(UController_Type type,ControllerMappingPADInfo config); - /** + /** - @return The first active mapping slot for the given controller type will be returned. If the controller type is not set active, -1 will be returned. - **/ - static s32 getActiveMappingSlot(UController_Type type); + @return The first active mapping slot for the given controller type will be returned. If the controller type is not set active, -1 will be returned. + **/ + static s32 getActiveMappingSlot(UController_Type type); - /** - @param type: The type of the controller. - @param mapping_slot: information about the added controller. - @return When the functions failed result < 0 is returned. Otherwise a pointer to a ControllerMappingPADInfo is returned. - **/ - static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,s32 mapping_slot); + /** + @param type: The type of the controller. + @param mapping_slot: information about the added controller. + @return When the functions failed result < 0 is returned. Otherwise a pointer to a ControllerMappingPADInfo is returned. + **/ + static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,s32 mapping_slot); - /** - Checks if a emulated controller is connected for the given controller type / mapping slot. + /** + Checks if a emulated controller is connected for the given controller type / mapping slot. - @param type: The type of the controller. - @param mapping_slot: Slot of the controller mapped to this controller type (usually 0) + @param type: The type of the controller. + @param mapping_slot: Slot of the controller mapped to this controller type (usually 0) - @return - **/ - static bool isControllerConnectedAndActive(UController_Type type,s32 mapping_slot = 0); + @return + **/ + static bool isControllerConnectedAndActive(UController_Type type,s32 mapping_slot = 0); - /** - Search for a connected mouse and returns a pointer to it's data. - @return A pointer to the first connected mouse that is found. NULL if no mouse is connected. - **/ - static HID_Mouse_Data * getMouseData(); + /** + Search for a connected mouse and returns a pointer to it's data. + @return A pointer to the first connected mouse that is found. NULL if no mouse is connected. + **/ + static HID_Mouse_Data * getMouseData(); - /** - Sets a rumble status for a controller. + /** + Sets a rumble status for a controller. - @param type: The type of the controller. - @param status: status of the rumble. 0 for off, 1 for on. + @param type: The type of the controller. + @param status: status of the rumble. 0 for off, 1 for on. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumble(UController_Type type,u32 status); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumble(UController_Type type,u32 status); - /** - Reads the input of all connected HID devices. Each attached controller will write his date into given array until it's full. + /** + Reads the input of all connected HID devices. Each attached controller will write his date into given array until it's full. - @param output: A pointer to an InputData array where the result will be stored. (Make sure to reset the array before using this function). - @param array_size: Size of the given InputData array. + @param output: A pointer to an InputData array where the result will be stored. (Make sure to reset the array before using this function). + @param array_size: Size of the given InputData array. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. If the result is > 0 the number of stored sets in the array is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. If the result is > 0 the number of stored sets in the array is returned. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size); - /** - Remaps the buttons in the given \p VPADStatus pointer. InitButtonMapping() needs to be called before calling this. The information about the remapping is stored in the config_controller array. - One easy way to set it is using the a config file on the SD Card. + /** + Remaps the buttons in the given \p VPADStatus pointer. InitButtonMapping() needs to be called before calling this. The information about the remapping is stored in the config_controller array. + One easy way to set it is using the a config file on the SD Card. - @param buffer: A pointer to the buffer where the input will be read from and the result will be stored. + @param buffer: A pointer to the buffer where the input will be read from and the result will be stored. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADStatus * buffer, s32 buffer_count); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADStatus * buffer, s32 buffer_count); - /** - Prints the current pressed down buttons of the given \p VPADStatus pointer. Uses the utils/logger.c UDP logger.. + /** + Prints the current pressed down buttons of the given \p VPADStatus pointer. Uses the utils/logger.c UDP logger.. - @param buffer: A pointer to the buffer where the input will be read from. + @param buffer: A pointer to the buffer where the input will be read from. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR printVPADButtons(VPADStatus * buffer); + @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR printVPADButtons(VPADStatus * buffer); - static std::string getIdentifierByVIDPID(u16 vid,u16 pid); + static std::string getIdentifierByVIDPID(u16 vid,u16 pid); - static void destroyConfigHelper(); + static void destroyConfigHelper(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingForDeviceSlot(u16 device_slot); + static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingForDeviceSlot(u16 device_slot); - static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumbleActivated(bool value); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumbleActivated(bool value); - static CONTROLLER_PATCHER_RESULT_OR_ERROR setNetworkControllerActivated(bool value); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setNetworkControllerActivated(bool value); - static bool isRumbleActivated(); + static bool isRumbleActivated(); - static bool isButtonRemappingDone(); + static bool isButtonRemappingDone(); - static bool isKeyboardConnected(); + static bool isKeyboardConnected(); - static bool areControllersConnected(); + static bool areControllersConnected(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR sampleKeyboardData(); + static CONTROLLER_PATCHER_RESULT_OR_ERROR sampleKeyboardData(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR resetCallbackData(); + static CONTROLLER_PATCHER_RESULT_OR_ERROR resetCallbackData(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADConnectedCallback(s32 chan, WPADConnectCallback callback); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADConnectedCallback(s32 chan, WPADConnectCallback callback); - static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADExtensionCallback(s32 chan, WPADConnectCallback callback); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setKPADExtensionCallback(s32 chan, WPADConnectCallback callback); - static CONTROLLER_PATCHER_RESULT_OR_ERROR setWPADConnectCallback(s32 chan, WPADConnectCallback callback); + static CONTROLLER_PATCHER_RESULT_OR_ERROR setWPADConnectCallback(s32 chan, WPADConnectCallback callback); - static CONTROLLER_PATCHER_RESULT_OR_ERROR handleCallbackData(bool button_pressed); + static CONTROLLER_PATCHER_RESULT_OR_ERROR handleCallbackData(bool button_pressed); - static CONTROLLER_PATCHER_RESULT_OR_ERROR handleCallbackDataInternal(WPADChan chan); + static CONTROLLER_PATCHER_RESULT_OR_ERROR handleCallbackDataInternal(WPADChan chan); }; #endif /* _CONTROLLER_PATCHER_H_ */ diff --git a/include/controller_patcher/ControllerPatcherDefs.h b/include/controller_patcher/ControllerPatcherDefs.h index 5603ee8..bc86b08 100644 --- a/include/controller_patcher/ControllerPatcherDefs.h +++ b/include/controller_patcher/ControllerPatcherDefs.h @@ -80,8 +80,7 @@ typedef int CONTROLLER_PATCHER_RESULT_OR_ERROR; /** * @brief The enumeration of Controller sticks defines */ -enum Controller_Stick_Defines -{ +enum Controller_Stick_Defines { STICK_CONF_MAGIC_VERSION, /**< Version of the stick configuration. Changes with every format*/ STICK_CONF_BYTE, /**< Byte where the stick-axis data is stored*/ STICK_CONF_DEFAULT, /**< Default value*/ @@ -95,8 +94,7 @@ enum Controller_Stick_Defines #define STICK_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!! //! most data has the format: byte,value (byte starting at 0) -enum Controller_Patcher_Settings -{ +enum Controller_Patcher_Settings { CONTRPS_VID, //! pid: 0x451d would be 0x45,0x1d CONTRPS_PID, //! vid: 0x488d would be 0x48,0x8d CONTRPS_BUF_SIZE, //! To set: CONTROLLER_PATCHER_VALUE_SET, BUF_SIZE (default is 64) @@ -203,8 +201,7 @@ enum Controller_Patcher_Settings /** * @brief The enumeration of different DPAD-Modes */ -enum Controller_Patcher_DPAD_MODE -{ +enum Controller_Patcher_DPAD_MODE { CONTRPDM_Normal, /**< Normal mode */ CONTRPDM_Hat, /**< Hat mode */ CONTRPDM_Absolute_2Values, /**< DPAD Value stored in 2 values (one for each axis), acting like a stick */ @@ -212,8 +209,7 @@ enum Controller_Patcher_DPAD_MODE /** * @brief The enumeration of DPAD Settings. Needed for saving both in the PADConst. */ -enum Controller_Patcher_DPAD_Settings -{ +enum Controller_Patcher_DPAD_Settings { CONTRDPAD_MODE = 0, /**< Byte where the DPAD Mode is stored */ CONTRDPAD_MASK = 1, /**< Byte where the DPAD Mask is stored */ }; @@ -221,24 +217,24 @@ enum Controller_Patcher_DPAD_Settings /** * @brief Stores data if the Slot the device is using in gHID_Devices */ -typedef struct _HIDSlotData{ - u16 deviceslot; /**< deviceslot number */ - u32 hidmask; /**< Used HID-Mask */ -}HIDSlotData; +typedef struct _HIDSlotData { + u16 deviceslot; /**< deviceslot number */ + u32 hidmask; /**< Used HID-Mask */ +} HIDSlotData; /** * @brief Struct where the data for the callback funtion is stored */ -typedef struct _my_cb_user{ - u8 *buf; /**< pointer the buffer that is used */ - u32 transfersize; /**< number of transfered data */ - u32 handle; /**< HID handle */ +typedef struct _my_cb_user { + u8 *buf; /**< pointer the buffer that is used */ + u32 transfersize; /**< number of transfered data */ + u32 handle; /**< HID handle */ HIDSlotData slotdata; /**< Information about the deviceslot and hidmask */ - u32 pads_per_device; /**< Number of maximum pads of this device */ - u8 pad_slot; /**< number of the pad that will be used */ - u8 rumblestatus[HID_MAX_PADS_COUNT]; /**< Current status of the device rumble */ - u8 forceRumbleInTicks[HID_MAX_PADS_COUNT]; -}my_cb_user; + u32 pads_per_device; /**< Number of maximum pads of this device */ + u8 pad_slot; /**< number of the pad that will be used */ + u8 rumblestatus[HID_MAX_PADS_COUNT]; /**< Current status of the device rumble */ + u8 forceRumbleInTicks[HID_MAX_PADS_COUNT]; +} my_cb_user; /** * @brief Stores data for the mouse @@ -256,8 +252,7 @@ typedef struct _HID_Mouse_Data { /** * @brief The enumeration of device types */ -enum DEVICE_TYPE -{ +enum DEVICE_TYPE { DEVICE_TYPE_CONTROLLER = 0, /**< Normal Controller */ DEVICE_TYPE_MOUSE = 1, /**< Mouse */ }; @@ -269,16 +264,16 @@ typedef struct _HID_Data { u32 handle; /**< The HID-handle this device is using */ u8 rumbleActive; /**< 1 when rumble is active */ u32 last_buttons; /**< The last pressed buttons, based on VPAD_BUTTON_XXX data */ - union{ - struct{ + union { + struct { u8 cur_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the current controller data is stored */ u8 last_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the last controller data is stored */ } controller; /**< Used when the device in a controller. Using u8 array where the raw data of the controller is placed. */ - struct{ + struct { HID_Mouse_Data cur_mouse_data; /**< Struct where the current mouse data is stored */ HID_Mouse_Data last_mouse_data; /**< Struct where the last mouse data is stored */ } mouse; /**< Used when the device in a mouse. Using a new struct to store the data. */ - }data_union; /**< The data union where the current and last data is stored.*/ + } data_union; /**< The data union where the current and last data is stored.*/ DEVICE_TYPE type; /**< The device type*/ HIDSlotData slotdata; /**< Information about the deviceslot and his mask*/ my_cb_user * user_data; /**< Pointer to the user data the read callback is using*/ @@ -296,24 +291,24 @@ typedef struct _HID_DEVICE_DATA { /** * @brief Stores a VID and PID */ -typedef struct _DeviceVIDPIDInfo{ - u16 vid; /**< Vendor ID of this device */ - u16 pid; /**< Product ID of this device */ -}DeviceVIDPIDInfo; +typedef struct _DeviceVIDPIDInfo { + u16 vid; /**< Vendor ID of this device */ + u16 pid; /**< Product ID of this device */ +} DeviceVIDPIDInfo; /** * @brief Infos of the device */ -typedef struct _DeviceInfo{ - HIDSlotData slotdata; /**< The slot used by this device */ - DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ - u8 pad_count; /**< Number of maximum pads this device can have*/ -}DeviceInfo; +typedef struct _DeviceInfo { + HIDSlotData slotdata; /**< The slot used by this device */ + DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ + u8 pad_count; /**< Number of maximum pads this device can have*/ +} DeviceInfo; /** * @brief The enumeration of Controller-Mapping types */ -enum ControllerMapping_Type_Defines{ +enum ControllerMapping_Type_Defines { CM_Type_Controller = 0, /**< Device with single input */ CM_Type_RealController = 1, /**< Real Pro Controller */ CM_Type_Mouse = 2, /**< Mouse */ @@ -323,52 +318,52 @@ enum ControllerMapping_Type_Defines{ /** * @brief Infos of a mapped controller */ -typedef struct _ControllerMappingPADInfo{ +typedef struct _ControllerMappingPADInfo { u8 active; /**< Set to one if mapped */ ControllerMapping_Type_Defines type; /**< Type of the controller mapping */ DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ u8 pad; /**< Stores which pad it mapped */ -}ControllerMappingPADInfo; +} ControllerMappingPADInfo; /** * @brief Infos of a mapped controller */ -typedef struct _ControllerMappingPAD{ +typedef struct _ControllerMappingPAD { ControllerMappingPADInfo pad_infos[HID_MAX_DEVICES_PER_SLOT]; //lets limit this to HID_MAX_DEVICES_PER_SLOT. u8 useAll; u8 rumble; /**< Set when the controller should rumble */ -}ControllerMappingPAD; +} ControllerMappingPAD; /** * @brief Stores informations about all mapped controller */ -typedef struct _ControllerMapping{ +typedef struct _ControllerMapping { ControllerMappingPAD gamepad; /**< Information about the gamepad mapping */ ControllerMappingPAD proController[4]; /**< Information about the Pro Controller mapping */ -}ControllerMapping; +} ControllerMapping; /** * @brief Pressed/Released/Down Button data. */ -typedef struct _InputButtonData{ +typedef struct _InputButtonData { u32 btn_h; /**< Buttons beeing hold */ u32 btn_d; /**< Buttons that started pressing */ u32 btn_r; /**< Buttons that were button released */ -}InputButtonData; +} InputButtonData; /** * @brief Struct where the inputdata of a device for all HID_MAX_PADS_COUNT pads can be stored */ -typedef struct _InputData{ +typedef struct _InputData { DeviceInfo device_info; /**< Infos about the device where the data is coming from */ ControllerMapping_Type_Defines type; InputButtonData button_data[HID_MAX_PADS_COUNT]; -}InputData; +} InputData; /** * @brief The enumeration of WiiU Controller types */ -enum UController_Type{ +enum UController_Type { UController_Type_Gamepad, UController_Type_Pro1, UController_Type_Pro2, diff --git a/source/ConfigReader.cpp b/source/ConfigReader.cpp index b938601..0eb612b 100644 --- a/source/ConfigReader.cpp +++ b/source/ConfigReader.cpp @@ -34,55 +34,63 @@ s32 ConfigReader::numberValidFiles = 0; ConfigReader *ConfigReader::instance = NULL; -ConfigReader::ConfigReader(){ +ConfigReader::ConfigReader() { } -bool ConfigReader::ReadConfigs(std::string path){ +bool ConfigReader::ReadConfigs(std::string path) { std::vector fileList = ScanFolder(path); - if(fileList.size() == 1 && fileList[0].compare("ERROR") == 0){ + if(fileList.size() == 1 && fileList[0].compare("ERROR") == 0) { return false; } - if(fileList.size() > 0){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found %d config files\n",fileList.size()); } + if(fileList.size() > 0) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Found %d config files\n",fileList.size()); + } processFileList(fileList); } return true; } -ConfigReader::~ConfigReader(){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("~ConfigReader\n"); } +ConfigReader::~ConfigReader() { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("~ConfigReader\n"); + } } -std::vector ConfigReader::ScanFolder(std::string path){ +std::vector ConfigReader::ScanFolder(std::string path) { std::vector config_files; struct dirent *dirent = NULL; - DIR *dirHandle = opendir(path.c_str()); - if (dirHandle == NULL){ + DIR *dirHandle = opendir(path.c_str()); + if (dirHandle == NULL) { DEBUG_FUNCTION_LINE("Failed to open dir %s\n",path.c_str()); config_files.push_back("ERROR"); //TODO: Find a proper solution - return config_files; - } - while ((dirent = readdir(dirHandle)) != 0){ - bool isDir = dirent->d_type & DT_DIR; - const char *filename = dirent->d_name; + return config_files; + } + while ((dirent = readdir(dirHandle)) != 0) { + bool isDir = dirent->d_type & DT_DIR; + const char *filename = dirent->d_name; - if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0){ continue; } + if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) { + continue; + } std::string newPath = path + "/" + std::string(filename); - if(!isDir && StringTools::EndsWith(std::string(filename),".ini")){ + if(!isDir && StringTools::EndsWith(std::string(filename),".ini")) { config_files.push_back(newPath); - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found ini: %s \n",newPath.c_str()); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Found ini: %s \n",newPath.c_str()); + } } - } + } return config_files; } -void ConfigReader::processFileList(std::vector path){ +void ConfigReader::processFileList(std::vector path) { for(std::vector::iterator it = path.begin(); it != path.end(); ++it) { DEBUG_FUNCTION_LINE("Reading %s\n",it->c_str()); std::string result = loadFileToString(*it); @@ -92,10 +100,10 @@ void ConfigReader::processFileList(std::vector path){ } } -std::string ConfigReader::loadFileToString(std::string path){ +std::string ConfigReader::loadFileToString(std::string path) { std::string strBuffer = ""; u8 * buffer = NULL; - if(FSUtils::LoadFileToMem(path.c_str(),&buffer,NULL) > 0){ + if(FSUtils::LoadFileToMem(path.c_str(),&buffer,NULL) > 0) { strBuffer = std::string((char *)buffer); strBuffer = StringTools::removeCharFromString(strBuffer,'\r'); strBuffer = StringTools::removeCharFromString(strBuffer,' '); diff --git a/source/ControllerPatcher.cpp b/source/ControllerPatcher.cpp index 3edfec8..997c53a 100644 --- a/source/ControllerPatcher.cpp +++ b/source/ControllerPatcher.cpp @@ -36,10 +36,14 @@ static u32 last_button_hold[4] = {0,0,0,0}; // This arrays stores the VPADStatus that will be used to get the HID Data for the Pro Controllers. One for each channel. static VPADStatus myVPADBuffer[4]; -void ControllerPatcher::InitButtonMapping(){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Init called \n"); } - if(!gButtonRemappingConfigDone){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Remapping is running! \n"); } +void ControllerPatcher::InitButtonMapping() { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Init called \n"); + } + if(!gButtonRemappingConfigDone) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Remapping is running! \n"); + } gButtonRemappingConfigDone = 1; memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything @@ -74,7 +78,7 @@ void ControllerPatcher::InitButtonMapping(){ } } -void ControllerPatcher::ResetConfig(){ +void ControllerPatcher::ResetConfig() { memset(&gControllerMapping,0,sizeof(gControllerMapping)); disableControllerMapping(); memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // Init / Invalid everything @@ -102,12 +106,16 @@ void ControllerPatcher::ResetConfig(){ gHIDRegisteredDevices = 0; ControllerPatcherUtils::getNextSlotData(&slotdata); gGamePadSlot = slotdata.deviceslot; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); + } ControllerPatcherUtils::getNextSlotData(&slotdata); gMouseSlot = slotdata.deviceslot; gHID_LIST_MOUSE = slotdata.hidmask; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 keyboard_slot = slotdata.deviceslot; @@ -115,31 +123,41 @@ void ControllerPatcher::ResetConfig(){ gHID_LIST_KEYBOARD = keyboard_hid; gHID_SLOT_KEYBOARD = keyboard_slot; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 gc_slot = slotdata.deviceslot; u32 gc_hid = slotdata.hidmask; gHID_LIST_GC = gc_hid; gHID_SLOT_GC = gc_slot; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 ds3_slot = slotdata.deviceslot; u32 ds3_hid = slotdata.hidmask; gHID_LIST_DS3 = ds3_hid; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS3-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register DS3-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 ds4_slot = slotdata.deviceslot; u32 ds4_hid = slotdata.hidmask; gHID_LIST_DS4 = ds4_hid; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register DS4-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(ds4_hid),ds4_slot); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register DS4-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(ds4_hid),ds4_slot); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 xinput_slot = slotdata.deviceslot; u32 xinput_hid = slotdata.hidmask; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Register XInput-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(xinput_hid),xinput_slot); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Register XInput-Config. HID-Mask %s Device-Slot: %d\n",StringTools::byte_to_binary(xinput_hid),xinput_slot); + } ControllerPatcherUtils::getNextSlotData(&slotdata); u32 switch_pro_slot = slotdata.deviceslot; @@ -290,7 +308,7 @@ void ControllerPatcher::ResetConfig(){ ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_L); ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_R); - //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is released + //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is released ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_PLUS); ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZL); ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZR); @@ -484,21 +502,28 @@ bool ControllerPatcher::Init(const char * pathToConfig) { } DEBUG_FUNCTION_LINE("Found the gSamplingCallback at %08X \n",gSamplingCallback); - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Init called! \n"); } - - if(gConfig_done == HID_INIT_NOT_DONE){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("First time calling the Init\n"); } - gConfig_done = HID_INIT_DONE; - ControllerPatcher::ResetConfig(); - }else{ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Config already done!\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Init called! \n"); } - if(pathToConfig != NULL && gConfig_done != HID_SDCARD_READ){ + if(gConfig_done == HID_INIT_NOT_DONE) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("First time calling the Init\n"); + } + gConfig_done = HID_INIT_DONE; + ControllerPatcher::ResetConfig(); + } else { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Config already done!\n"); + } + } + + if(pathToConfig != NULL && gConfig_done != HID_SDCARD_READ) { + DEBUG_FUNCTION_LINE("Reading config files from SD Card\n"); DEBUG_FUNCTION_LINE("Reading config files from SD Card\n"); ConfigReader* reader = ConfigReader::getInstance(); - if(reader->ReadConfigs(pathToConfig)){ + if(reader->ReadConfigs(pathToConfig)) { DEBUG_FUNCTION_LINE("Done with reading config files from SD Card\n"); gConfig_done = HID_SDCARD_READ; } @@ -508,29 +533,31 @@ bool ControllerPatcher::Init(const char * pathToConfig) { DEBUG_FUNCTION_LINE("Initializing the data for button remapping\n"); InitButtonMapping(); - if(!gHIDAttached){ + if(!gHIDAttached) { HIDAddClient(&gHIDClient, ControllerPatcherHID::myAttachDetachCallback); } return true; } -void ControllerPatcher::startNetworkServer(){ +void ControllerPatcher::startNetworkServer() { if(!gNetworkControllerActivated) return; DEBUG_FUNCTION_LINE("statedNetworkServer! \n"); UDPServer::getInstance(); CPTCPServer::getInstance(); } -void ControllerPatcher::stopNetworkServer(){ +void ControllerPatcher::stopNetworkServer() { DEBUG_FUNCTION_LINE("called! \n"); UDPServer::destroyInstance(); UDPClient::destroyInstance(); CPTCPServer::destroyInstance(); } -void ControllerPatcher::DeInit(){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("called! \n"); } +void ControllerPatcher::DeInit() { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("called! \n"); + } if(gHIDAttached) HIDDelClient(&gHIDClient); @@ -577,28 +604,32 @@ void ControllerPatcher::DeInit(){ destroyConfigHelper(); } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::enableControllerMapping(){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::enableControllerMapping() { gControllerMapping.gamepad.useAll = 0; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableControllerMapping(){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableControllerMapping() { gControllerMapping.gamepad.useAll = 1; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting(){ - s32 res; - if(IMIsDimEnabled(&res) == 0){ - if(res == 1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Dim was orignally enabled!\n"); } +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting() { + uint32_t res; + if(IMIsDimEnabled(&res) == 0) { + if(res == 1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Dim was orignally enabled!\n"); + } gOriginalDimState = 1; } } - if(IMIsAPDEnabled(&res) == 0){ - if(res == 1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Auto power down was orignally enabled!\n"); } + if(IMIsAPDEnabled(&res) == 0) { + if(res == 1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Auto power down was orignally enabled!\n"); + } gOriginalAPDState = 1; } } @@ -609,37 +640,39 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting() return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::restoreWiiUEnergySetting(){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::restoreWiiUEnergySetting() { //Check if we need to enable Auto Power down again on exiting - if(gOriginalAPDState == 1){ + if(gOriginalAPDState == 1) { DEBUG_FUNCTION_LINE("Auto shutdown was on before using HID to VPAD. Setting it to on again.\n"); IMEnableAPD(); } - if(gOriginalDimState == 1){ + if(gOriginalDimState == 1) { DEBUG_FUNCTION_LINE("Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n"); IMEnableDim(); } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UController_Type type){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UController_Type type) { ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - if(cm_map_pad == NULL){return CONTROLLER_PATCHER_ERROR_NULL_POINTER;} + if(cm_map_pad == NULL) { + return CONTROLLER_PATCHER_ERROR_NULL_POINTER; + } memset(cm_map_pad,0,sizeof(*cm_map_pad)); return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UController_Type type,ControllerMappingPADInfo config){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UController_Type type,ControllerMappingPADInfo config) { ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); s32 result = 0; - for(s32 i=0;ipad_infos[i]); - if(info != NULL && !info->active){ + if(info != NULL && !info->active) { info->active = 1; info->pad = config.pad; info->type = config.type; @@ -650,7 +683,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UCont break; } } - if(result == 0){ + if(result == 0) { //No free slot. return -1; } @@ -658,14 +691,16 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UCont return CONTROLLER_PATCHER_ERROR_NONE; } -s32 ControllerPatcher::getActiveMappingSlot(UController_Type type){ +s32 ControllerPatcher::getActiveMappingSlot(UController_Type type) { ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - if(cm_map_pad == NULL){return -1;} + if(cm_map_pad == NULL) { + return -1; + } s32 connected = -1; - for(s32 i =0;ipad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController){ + for(s32 i =0; ipad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController) { connected = i; break; } @@ -674,12 +709,12 @@ s32 ControllerPatcher::getActiveMappingSlot(UController_Type type){ return connected; } -bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 mapping_slot){ +bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 mapping_slot) { ControllerMappingPADInfo * padinfo = getControllerMappingInfo(type,mapping_slot); - if(!padinfo){ + if(!padinfo) { return false; } - if(padinfo->active){ + if(padinfo->active) { DeviceInfo device_info; memset(&device_info,0,sizeof(device_info)); @@ -687,7 +722,7 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 device_info.vidpid = padinfo->vidpid; s32 res; - if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ + if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0) { return false; } @@ -697,7 +732,7 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 HID_Data * data_cur; if((res = ControllerPatcherHID::getHIDData(hidmask,pad,&data_cur)) < 0) { - return false; + return false; } return true; @@ -705,32 +740,36 @@ bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 return false; } -ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UController_Type type,s32 mapping_slot){ +ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UController_Type type,s32 mapping_slot) { ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - if(cm_map_pad == NULL){return NULL;} + if(cm_map_pad == NULL) { + return NULL; + } - if(mapping_slot < 0 || mapping_slot > HID_MAX_DEVICES_PER_SLOT-1){ return NULL;} + if(mapping_slot < 0 || mapping_slot > HID_MAX_DEVICES_PER_SLOT-1) { + return NULL; + } return &(cm_map_pad->pad_infos[mapping_slot]); } -HID_Mouse_Data * ControllerPatcher::getMouseData(){ +HID_Mouse_Data * ControllerPatcher::getMouseData() { if(gHID_Mouse_Mode != HID_MOUSE_MODE_TOUCH) return NULL; ControllerMappingPAD * CMPAD = ControllerPatcherUtils::getControllerMappingByType(UController_Type_Gamepad); - if(CMPAD == NULL){ + if(CMPAD == NULL) { return NULL; } HID_Mouse_Data * result = NULL; - for(s32 i = 0;ipad_infos[i]); - if(!padinfo->active){ + if(!padinfo->active) { break; } - if(padinfo->type == CM_Type_Mouse){ + if(padinfo->type == CM_Type_Mouse) { result = &(gHID_Devices[gMouseSlot].pad_data[padinfo->pad].data_union.mouse.cur_mouse_data); DCFlushRange(&result,sizeof(result)); DCInvalidateRange(&result,sizeof(result)); @@ -740,21 +779,23 @@ HID_Mouse_Data * ControllerPatcher::getMouseData(){ return result; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type type,u32 status){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type type,u32 status) { ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - if(cm_map_pad == NULL){return -1;} + if(cm_map_pad == NULL) { + return -1; + } cm_map_pad->rumble = !!status; //to make sure it's only 0 or 1. return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size) { s32 hid = gHIDCurrentDevice; HID_Data * data_cur; VPADStatus pad_buffer; VPADStatus * buffer = &pad_buffer; s32 result = CONTROLLER_PATCHER_ERROR_NONE; - for(s32 i = 0;i< gHIDMaxDevices;i++){ - if((hid & (1 << i)) != 0){ + for(s32 i = 0; i< gHIDMaxDevices; i++) { + if((hid & (1 << i)) != 0) { memset(buffer,0,sizeof(*buffer)); s32 newhid = (1 << i); @@ -769,9 +810,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp deviceinfo->slotdata.deviceslot = deviceslot; deviceinfo->slotdata.hidmask = newhid; - if(newhid == gHID_LIST_MOUSE){ + if(newhid == gHID_LIST_MOUSE) { output[result].type = CM_Type_Mouse; - } else if(newhid == gHID_LIST_KEYBOARD){ + } else if(newhid == gHID_LIST_KEYBOARD) { output[result].type = CM_Type_Keyboard; } @@ -787,15 +828,15 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp s32 buttons_hold = 0; - for(s32 pad = 0;padslotdata.hidmask,pad,&data_cur)) < 0){ - continue; + if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0) { + continue; } res = ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_A); @@ -828,7 +869,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp } result++; - if(result >= array_size){ + if(result >= array_size) { break; } } @@ -837,7 +878,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp return result; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHID(void * data,s32 chan, s32 mode){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHID(void * data,s32 chan, s32 mode) { if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(chan < 0 || chan > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; //if(gControllerMapping.proController[chan].enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED; @@ -847,9 +888,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI std::vector data_list; - for(s32 i = 0;irumbleActive = !!gControllerMapping.gamepad.rumble; } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADStatus * buffer){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADStatus * buffer) { return CONTROLLER_PATCHER_ERROR_NONE; /* BROKEN on transitions.*/ if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(buffer->trigger != 0x00000000){ + if(buffer->trigger != 0x00000000) { char output[250]; output[0] = 0; //null terminate it. just in case. @@ -987,15 +1028,15 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADStatu if((buffer->trigger & VPAD_STICK_L_EMULATION_UP) == VPAD_STICK_L_EMULATION_UP) strcat(output,"LE_Up "); if((buffer->trigger & VPAD_STICK_L_EMULATION_DOWN) == VPAD_STICK_L_EMULATION_DOWN) strcat(output,"LE_Down "); - DEBUG_FUNCTION_LINE("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->lstick.x,buffer->lstick.y,buffer->rstick.x,buffer->rstick.y); + DEBUG_FUNCTION_LINE("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->leftStick.x,buffer->leftStick.y,buffer->rightStick.x,buffer->rightStick.y); } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADStatus * buffer,s32 buffer_count){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADStatus * buffer,s32 buffer_count) { if(!gButtonRemappingConfigDone) return CONTROLLER_PATCHER_ERROR_CONFIG_NOT_DONE; if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - for(s32 i = 0;i < buffer_count;i++){ + for(s32 i = 0; i < buffer_count; i++) { VPADStatus new_data; memset(&new_data,0,sizeof(new_data)); @@ -1047,54 +1088,54 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADStatus return CONTROLLER_PATCHER_ERROR_NONE; } -std::string ControllerPatcher::getIdentifierByVIDPID(u16 vid,u16 pid){ +std::string ControllerPatcher::getIdentifierByVIDPID(u16 vid,u16 pid) { return ConfigValues::getStringByVIDPID(vid,pid); } -void ControllerPatcher::destroyConfigHelper(){ +void ControllerPatcher::destroyConfigHelper() { ConfigReader::destroyInstance(); ConfigValues::destroyInstance(); } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::doSamplingForDeviceSlot(u16 device_slot){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::doSamplingForDeviceSlot(u16 device_slot) { return ControllerPatcherUtils::doSampling(device_slot,0,true); } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumbleActivated(bool value){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumbleActivated(bool value) { gGlobalRumbleActivated = value; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setNetworkControllerActivated(bool value){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setNetworkControllerActivated(bool value) { gNetworkControllerActivated = value; return CONTROLLER_PATCHER_ERROR_NONE; } -bool ControllerPatcher::isRumbleActivated(){ +bool ControllerPatcher::isRumbleActivated() { return gGlobalRumbleActivated; } -bool ControllerPatcher::isButtonRemappingDone(){ +bool ControllerPatcher::isButtonRemappingDone() { return gButtonRemappingConfigDone; } -bool ControllerPatcher::isKeyboardConnected(){ +bool ControllerPatcher::isKeyboardConnected() { return (gHIDCurrentDevice & gHID_LIST_KEYBOARD) == gHID_LIST_KEYBOARD; } -bool ControllerPatcher::areControllersConnected(){ +bool ControllerPatcher::areControllersConnected() { return gHIDAttached > 0; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::sampleKeyboardData(){ - if(ControllerPatcher::isKeyboardConnected()){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::sampleKeyboardData() { + if(ControllerPatcher::isKeyboardConnected()) { ControllerPatcher::doSamplingForDeviceSlot(gHID_SLOT_KEYBOARD); } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetCallbackData(){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetCallbackData() { memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback)); memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback)); memset(gExtensionCallback,0,sizeof(gExtensionCallback)); @@ -1104,26 +1145,32 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetCallbackData(){ } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADConnectedCallback(s32 chan, wpad_connect_callback_t callback){ - if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; } +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADConnectedCallback(s32 chan, WPADConnectCallback callback) { + if(chan >= 4) { + return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; + } gKPADConnectCallback[chan] = callback; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADExtensionCallback(s32 chan, wpad_connect_callback_t callback){ - if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; } +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setKPADExtensionCallback(s32 chan, WPADConnectCallback callback) { + if(chan >= 4) { + return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; + } gExtensionCallback[chan] = callback; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setWPADConnectCallback(s32 chan, wpad_connect_callback_t callback){ - if(chan >= 4){ return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; } +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setWPADConnectCallback(s32 chan, WPADConnectCallback callback) { + if(chan >= 4) { + return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; + } gWPADConnectCallback[chan] = callback; return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::handleCallbackData(bool button_pressed){ - if(button_pressed && gCallbackCooldown == 0){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::handleCallbackData(bool button_pressed) { + if(button_pressed && gCallbackCooldown == 0) { gCallbackCooldown = 0xFF; /*if(HID_DEBUG){ log_printf("my_VPADRead(line %d): Pressed the TV button. Maybe we can call the callbacks.!\n",__LINE__); } @@ -1131,32 +1178,38 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::handleCallbackData(bool bu if(HID_DEBUG){ log_printf("my_VPADRead(line %d): gWPADConnectCallback = %08X %08X %08X %08X\n",__LINE__,gWPADConnectCallback[0],gWPADConnectCallback[1],gWPADConnectCallback[2],gWPADConnectCallback[3]); } if(HID_DEBUG){ log_printf("my_VPADRead(line %d): gKPADConnectCallback = %08X %08X %08X %08X\n",__LINE__,gKPADConnectCallback[0],gKPADConnectCallback[1],gKPADConnectCallback[2],gKPADConnectCallback[3]); }*/ - for(s32 i = 0;i<4;i++){ - bool doCall = false; - if(i == 0){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1); } - if(i == 1){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2); } - if(i == 2){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3); } - if(i == 3){ doCall = ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4); } - if(doCall){ - if(gWPADConnectCallback[i] != NULL){ - log_printf("my_VPADRead(line %d): Called WPAD connect callback for pro controller in slot %d!\n",__LINE__,(i+1)); - gWPADConnectCallback[i](i,0); - } - if(gKPADConnectCallback[i] != NULL){ - log_printf("my_VPADRead(line %d): Called KPAD connect callback for pro controller in slot %d!\n",__LINE__,(i+1)); - gKPADConnectCallback[i](i,0); - } - if(gExtensionCallback[i] != NULL){ - log_printf("my_VPADRead(line %d): Called extension callback for pro controller in slot %d!\n",__LINE__,(i+1)); - gExtensionCallback[i](i,WPAD_EXT_PRO_CONTROLLER); - } - } + if(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) { + ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_0); + } + if(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) { + ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_1); + } + if(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) { + ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_2); + } + if(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4)) { + ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_3); } } - if(gCallbackCooldown > 0){ + if(gCallbackCooldown > 0) { gCallbackCooldown--; } return CONTROLLER_PATCHER_ERROR_NONE; } +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::handleCallbackDataInternal(WPADChan chan) { + if(gWPADConnectCallback[chan] != NULL) { + log_printf("Called WPAD connect callback for pro controller in slot %d!\n",chan + 1); + gWPADConnectCallback[chan](chan,0); + } + if(gKPADConnectCallback[chan] != NULL) { + log_printf("Called KPAD connect callback for pro controller in slot %d!\n",chan + 1); + gKPADConnectCallback[chan](chan,0); + } + if(gExtensionCallback[chan] != NULL) { + log_printf("Called extension callback for pro controller in slot %d!\n",chan + 1); + gExtensionCallback[chan](chan,WPAD_EXT_PRO_CONTROLLER); + } + return CONTROLLER_PATCHER_ERROR_NONE; +} diff --git a/source/config/ConfigParser.cpp b/source/config/ConfigParser.cpp index 14be571..5636848 100644 --- a/source/config/ConfigParser.cpp +++ b/source/config/ConfigParser.cpp @@ -21,18 +21,18 @@ #include #include -ConfigParser::ConfigParser(std::string configData){ +ConfigParser::ConfigParser(std::string configData) { this->content = configData; this->contentLines = StringTools::stringSplit(content, "\n"); - if(contentLines.empty()){ - return; + if(contentLines.empty()) { + return; } //remove the comments and make everything uppercase - for(u32 i = 0; i < contentLines.size(); i++){ + for(u32 i = 0; i < contentLines.size(); i++) { std::vector comments = StringTools::stringSplit(contentLines[i], "//"); - if(!comments.empty()){ + if(!comments.empty()) { contentLines[i] = comments[0]; } //we want everything uppercase @@ -41,78 +41,78 @@ ConfigParser::ConfigParser(std::string configData){ //remove empty lines std::vector contentline2; - for(u32 i = 0; i < contentLines.size(); i++){ - if(strlen(contentLines[i].c_str()) > 0){ - contentline2.push_back(contentLines[i]); + for(u32 i = 0; i < contentLines.size(); i++) { + if(strlen(contentLines[i].c_str()) > 0) { + contentline2.push_back(contentLines[i]); } } contentLines = contentline2; Init(); } -ConfigParser::~ConfigParser(){ +ConfigParser::~ConfigParser() { } -PARSE_TYPE ConfigParser::getType(){ +PARSE_TYPE ConfigParser::getType() { return type_b; } -void ConfigParser::setType(PARSE_TYPE newType){ +void ConfigParser::setType(PARSE_TYPE newType) { this->type_b = newType; } -u16 ConfigParser::getSlot(){ +u16 ConfigParser::getSlot() { return this->slot_b; } -void ConfigParser::setSlot(u16 newSlot){ +void ConfigParser::setSlot(u16 newSlot) { this->slot_b = newSlot; } -bool ConfigParser::Init(){ - if(contentLines.size() == 0){ +bool ConfigParser::Init() { + if(contentLines.size() == 0) { DEBUG_FUNCTION_LINE("File seems to be empty. Make sure to have a proper header\n"); return false; } const char * line = contentLines[0].c_str(); s32 len = strlen(line); - if(len <= 4){ + if(len <= 4) { DEBUG_FUNCTION_LINE("Header is too short.\n"); return false; } std::string identify; - if(line[0] == '[' && line[len-1] == ']'){ + if(line[0] == '[' && line[len-1] == ']') { identify = contentLines[0].substr(1,len-2); - }else{ + } else { DEBUG_FUNCTION_LINE("Not a proper config file!\n"); return false; } - if(identify.compare("GAMEPAD") == 0){ + if(identify.compare("GAMEPAD") == 0) { DEBUG_FUNCTION_LINE("Its a gamepad config file!\n"); setSlot(gGamePadSlot); setType(PARSE_GAMEPAD); - }else if(identify.compare("MOUSE") == 0){ + } else if(identify.compare("MOUSE") == 0) { DEBUG_FUNCTION_LINE("Its a mouse config file!\n"); setSlot(gMouseSlot); setType(PARSE_MOUSE); this->vid = HID_MOUSE_VID; this->pid = HID_MOUSE_PID; - }else if(identify.compare("KEYBOARD") == 0){ + } else if(identify.compare("KEYBOARD") == 0) { DEBUG_FUNCTION_LINE("Its a keyboard config file!\n"); setSlot(gHID_SLOT_KEYBOARD); setType(PARSE_KEYBOARD); this->vid = HID_KEYBOARD_VID; this->pid = HID_KEYBOARD_PID; - }else{ + } else { DEBUG_FUNCTION_LINE("Its a controller config file!\n"); setSlot(getSlotController(identify)); setType(PARSE_CONTROLLER); } - if(getSlot() == HID_INVALID_SLOT){ + if(getSlot() == HID_INVALID_SLOT) { return false; } @@ -121,39 +121,54 @@ bool ConfigParser::Init(){ return true; } -void ConfigParser::parseSingleLine(std::string line){ - if(line.empty()){DEBUG_FUNCTION_LINE("Can't parse line. it's empty\n"); return;} - std::vector cur_values = StringTools::stringSplit(line,"="); - if(cur_values.size() != 2){ - if(HID_DEBUG || cur_values.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",line.c_str()); } +void ConfigParser::parseSingleLine(std::string line) { + if(line.empty()) { + DEBUG_FUNCTION_LINE("Can't parse line. it's empty\n"); return; - }else{ + } + std::vector cur_values = StringTools::stringSplit(line,"="); + if(cur_values.size() != 2) { + if(HID_DEBUG || cur_values.size() > 2) { + DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",line.c_str()); + } + return; + } else { u16 hid_slot = getSlot(); - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("leftpart = \"%s\" \n",cur_values[0].c_str()); } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("rightpart = \"%s\" \n",cur_values[1].c_str()); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("leftpart = \"%s\" \n",cur_values[0].c_str()); + } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("rightpart = \"%s\" \n",cur_values[1].c_str()); + } s32 keyslot = -1; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Checking single value\n"); } - if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD){ + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Checking single value\n"); + } + if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD) { keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]); - }else if(getType() == PARSE_MOUSE){ + } else if(getType() == PARSE_MOUSE) { keyslot = ConfigValues::getKeySlotMouse(cur_values[0]); - }else{ + } else { keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]); } - if(keyslot != -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a single value\n"); } + if(keyslot != -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Its a single value\n"); + } long rightValue = -1; bool valueSet = false; - if(cur_values[0].compare("DPAD_MODE") == 0){ + if(cur_values[0].compare("DPAD_MODE") == 0) { const u8 * values_ = NULL; - if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL){ + if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL) { if(values_[STICK_CONF_MAGIC_VERSION] != STICK_CONF_MAGIC_VALUE) - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Settings preset DPAD MODE and Mask\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Settings preset DPAD MODE and Mask\n"); + } config_controller[hid_slot][CONTRPS_DPAD_MODE][0] = CONTROLLER_PATCHER_VALUE_SET; config_controller[hid_slot][CONTRPS_DPAD_MODE][1] = values_[CONTRDPAD_MODE]; - if(values_[CONTRDPAD_MASK] != 0x00){ + if(values_[CONTRDPAD_MASK] != 0x00) { config_controller[hid_slot][CONTRPS_DPAD_MASK][0] = CONTROLLER_PATCHER_VALUE_SET; config_controller[hid_slot][CONTRPS_DPAD_MASK][1] = values_[CONTRDPAD_MASK]; } @@ -161,47 +176,63 @@ void ConfigParser::parseSingleLine(std::string line){ } } - if(!valueSet){ - if(getType() == PARSE_KEYBOARD){ - if((rightValue = ConfigValues::getPresetValuesKeyboard(cur_values[1]))!= -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined Keyboard! \"%s\" is %d\n",cur_values[1].c_str(),rightValue);} - }else{ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); } + if(!valueSet) { + if(getType() == PARSE_KEYBOARD) { + if((rightValue = ConfigValues::getPresetValuesKeyboard(cur_values[1]))!= -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Used pre-defined Keyboard! \"%s\" is %d\n",cur_values[1].c_str(),rightValue); + } + } else { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); + } char * ptr; rightValue = strtol(cur_values[1].c_str(),&ptr,16); } - }else{ + } else { rightValue = ConfigValues::getPresetValue(cur_values[1]); - if(getType() == PARSE_MOUSE){ //No parsing for the mouse - if(rightValue == -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Invalid mouse value, lets skip it %s\n",cur_values[1].c_str()); } - return; - } - }else{ - if(rightValue == -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); } + if(getType() == PARSE_MOUSE) { //No parsing for the mouse + if(rightValue == -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Invalid mouse value, lets skip it %s\n",cur_values[1].c_str()); + } + return; + } + } else { + if(rightValue == -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("I need to parse %s\n",cur_values[1].c_str()); + } char * ptr; rightValue = strtol(cur_values[1].c_str(),&ptr,16); } } } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Setting value to %d\n",rightValue); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Setting value to %d\n",rightValue); + } config_controller[hid_slot][keyslot][0] = CONTROLLER_PATCHER_VALUE_SET; config_controller[hid_slot][keyslot][1] = rightValue; } - }else{ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Check pair value\n"); } + } else { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Check pair value\n"); + } keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]); - if(keyslot != -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a pair value\n"); } + if(keyslot != -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Its a pair value\n"); + } - if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("And its no preset\n"); } + if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("And its no preset\n"); + } std::vector rightvalues = StringTools::stringSplit(cur_values[1],","); - if(rightvalues.size() != 2){ + if(rightvalues.size() != 2) { DEBUG_FUNCTION_LINE("%d instead of 2 key=values pairs in line\n",rightvalues.size()); return; } @@ -212,43 +243,49 @@ void ConfigParser::parseSingleLine(std::string line){ config_controller[hid_slot][keyslot][0] = firstValue; config_controller[hid_slot][keyslot][1] = secondValue; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Set %02X,%02X\n",firstValue,secondValue); } - }else{ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found preset value!!\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Set %02X,%02X\n",firstValue,secondValue); + } + } else { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Found preset value!!\n"); + } } - }else{ + } else { DEBUG_FUNCTION_LINE("The setting \"%s\" is unknown!\n",cur_values[0].c_str()); } } } } -bool ConfigParser::resetConfig(){ +bool ConfigParser::resetConfig() { s32 slot = getSlot(); if((slot == HID_INVALID_SLOT) || (slot >= gHIDMaxDevices)) return false; - for(s32 j = (CONTRPS_PID+1);j< CONTRPS_MAX_VALUE;j++){ + for(s32 j = (CONTRPS_PID+1); j< CONTRPS_MAX_VALUE; j++) { config_controller[slot][j][0] = CONTROLLER_PATCHER_INVALIDVALUE; config_controller[slot][j][1] = CONTROLLER_PATCHER_INVALIDVALUE; } return true; } -s32 ConfigParser::getSlotController(std::string identify){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Getting Controller Slot\n"); } +s32 ConfigParser::getSlotController(std::string identify) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Getting Controller Slot\n"); + } std::vector values = StringTools::stringSplit(identify,","); - if(values.size() != 2){ + if(values.size() != 2) { DEBUG_FUNCTION_LINE("You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",identify.c_str()); return HID_INVALID_SLOT; } s32 vid = getValueFromKeyValue(values[0],"VID","="); - if(vid < 0){ + if(vid < 0) { return HID_INVALID_SLOT; } s32 pid = getValueFromKeyValue(values[1],"PID","="); - if(pid < 0){ + if(pid < 0) { return HID_INVALID_SLOT; } DEBUG_FUNCTION_LINE("VID: %04x PID: %04x\n",vid,pid); @@ -262,8 +299,10 @@ s32 ConfigParser::getSlotController(std::string identify){ s32 result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo); s32 slot = deviceinfo.slotdata.deviceslot; s32 hid = 0; - if(result < 0){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Its a new controller, lets save it\n"); } + if(result < 0) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Its a new controller, lets save it\n"); + } HIDSlotData slotdata; ControllerPatcherUtils::getNextSlotData(&slotdata); @@ -271,30 +310,37 @@ s32 ConfigParser::getSlotController(std::string identify){ slot = slotdata.deviceslot; hid = slotdata.hidmask; - if(slot >= gHIDMaxDevices){ + if(slot >= gHIDMaxDevices) { DEBUG_FUNCTION_LINE("We don't a space for a new controller, please delete .inis\n"); return HID_INVALID_SLOT; } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,StringTools::byte_to_binary(hid)); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,StringTools::byte_to_binary(hid)); + } config_controller[slot][CONTRPS_VID][0] = (vid & 0xFF00) >> 8; config_controller[slot][CONTRPS_VID][1] = (vid & 0x00FF); config_controller[slot][CONTRPS_PID][0] = (pid & 0xFF00) >> 8; config_controller[slot][CONTRPS_PID][1] = (pid & 0x00FF); - if(HID_DEBUG){ - DEBUG_FUNCTION_LINE("Saved vid: %04X pid: %04X\n", - config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1], - config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Saved vid: %04X pid: %04X\n", + config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1], + config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]); + } config_controller_hidmask[slot] = hid; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Saved the hid\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Saved the hid\n"); + } - }else{ - if(slot < gHIDMaxDevices){ + } else { + if(slot < gHIDMaxDevices) { hid = config_controller_hidmask[slot]; - if(HID_DEBUG){ DEBUG_FUNCTION_LINE(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,StringTools::byte_to_binary(hid)); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,StringTools::byte_to_binary(hid)); + } DEBUG_FUNCTION_LINE("We already have data of this controller, lets modify it\n"); - }else{ + } else { DEBUG_FUNCTION_LINE("Something really odd happend to the slots. %d is bigger then max (%d)\n",slot,gHIDMaxDevices); return HID_INVALID_SLOT; } @@ -304,42 +350,50 @@ s32 ConfigParser::getSlotController(std::string identify){ return slot; } -bool ConfigParser::parseIni(){ - if(getSlot() == HID_INVALID_SLOT){ +bool ConfigParser::parseIni() { + if(getSlot() == HID_INVALID_SLOT) { DEBUG_FUNCTION_LINE("Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",getType(),gHIDMaxDevices); return false; } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Parsing content, type %d\n",getType()); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Parsing content, type %d\n",getType()); + } s32 start = 1; - if(contentLines.size() <= 1){ + if(contentLines.size() <= 1) { DEBUG_FUNCTION_LINE("File only contains a header.\n"); return false; } - if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){ + if(contentLines[1].compare("[IGNOREDEFAULT]") == 0) { resetConfig(); DEBUG_FUNCTION_LINE("Ignoring existing settings of this device\n"); start++; } - for(u32 i = start; i < contentLines.size(); i++){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("line %d: \"%s\" \n",(i+1),contentLines[i].c_str()); } + for(u32 i = start; i < contentLines.size(); i++) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("line %d: \"%s\" \n",(i+1),contentLines[i].c_str()); + } parseSingleLine(contentLines[i]); } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Parsing of the file is done.\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Parsing of the file is done.\n"); + } return true; } -s32 ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter){ +s32 ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter) { std::vector string_value = StringTools::stringSplit(value_pair,delimiter); - if(string_value.size() != 2){ - if(HID_DEBUG || string_value.size() > 2){ DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",value_pair.c_str()); } + if(string_value.size() != 2) { + if(HID_DEBUG || string_value.size() > 2) { + DEBUG_FUNCTION_LINE("Not a valid key=pair line %s\n",value_pair.c_str()); + } return -1; } - if(string_value[0].compare(expectedKey) != 0){ + if(string_value[0].compare(expectedKey) != 0) { DEBUG_FUNCTION_LINE("Key part not %s, its %s",expectedKey.c_str(),string_value[0].c_str()); return -1; } diff --git a/source/config/ConfigValues.cpp b/source/config/ConfigValues.cpp index 22eec65..d588a0a 100644 --- a/source/config/ConfigValues.cpp +++ b/source/config/ConfigValues.cpp @@ -23,24 +23,26 @@ ConfigValues *ConfigValues::instance = NULL; -ConfigValues::ConfigValues(){ +ConfigValues::ConfigValues() { InitValues(); } -ConfigValues::~ConfigValues(){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("\n");} +ConfigValues::~ConfigValues() { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("\n"); + } } -const u8 * ConfigValues::getValuesForPreset(std::map values,std::string possibleValue){ +const u8 * ConfigValues::getValuesForPreset(std::map values,std::string possibleValue) { std::map::iterator it; it = values.find(possibleValue); - if (it != values.end()){ + if (it != values.end()) { return it->second; } return NULL; } -bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,s32 slot,s32 keyslot){ +bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,s32 slot,s32 keyslot) { if(setIfValueIsPreset(presetGCValues,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true; if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true; @@ -50,18 +52,22 @@ bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,s32 slot,s3 } //We need this function here so we can use preset sticks. -bool ConfigValues::setIfValueIsPreset(std::map values,std::string possibleValue,s32 slot,s32 keyslot){ - if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE){ +bool ConfigValues::setIfValueIsPreset(std::map values,std::string possibleValue,s32 slot,s32 keyslot) { + if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE) { return false; } const u8 * values_ = NULL; if( keyslot == CONTRPS_VPAD_BUTTON_L_STICK_X || - keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y || - keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X || - keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("This may be a predefined stick %s\n",possibleValue.c_str());} - if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Found predefined stick!\n");} + keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y || + keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X || + keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("This may be a predefined stick %s\n",possibleValue.c_str()); + } + if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Found predefined stick!\n"); + } config_controller[slot][keyslot][0] = values_[STICK_CONF_BYTE]; //CONTRPS_VPAD_BUTTON_L_STICK_X config_controller[slot][keyslot][1] = values_[STICK_CONF_DEFAULT]; config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT @@ -75,7 +81,7 @@ bool ConfigValues::setIfValueIsPreset(std::map values,std } } - if((values_ = getValuesForPreset(values,possibleValue)) != NULL){ + if((values_ = getValuesForPreset(values,possibleValue)) != NULL) { config_controller[slot][keyslot][0] = values_[0]; config_controller[slot][keyslot][1] = values_[1]; return true; @@ -84,39 +90,43 @@ bool ConfigValues::setIfValueIsPreset(std::map values,std } -s32 ConfigValues::getValueFromMap(std::map values,std::string nameOfString){ +s32 ConfigValues::getValueFromMap(std::map values,std::string nameOfString) { std::map::iterator it; it = values.find(nameOfString); - if (it != values.end()){ - return it->second; + if (it != values.end()) { + return it->second; } //Value not found return -1; } -s32 ConfigValues::getPresetValueEx(std::string possibleString){ +s32 ConfigValues::getPresetValueEx(std::string possibleString) { s32 rightValue = -1; - if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue); } - }else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){ - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue); } + if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue); + } + } else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1) { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue); + } } return rightValue; } - void ConfigValues::addDeviceNameEx(u16 vid,u16 pid,std::string value){ +void ConfigValues::addDeviceNameEx(u16 vid,u16 pid,std::string value) { deviceNames[StringTools::strfmt("%04X%04X",vid,pid).c_str()] = value; - } +} -std::string ConfigValues::getStringByVIDPIDEx(u16 vid,u16 pid){ +std::string ConfigValues::getStringByVIDPIDEx(u16 vid,u16 pid) { std::string result = ""; std::map::iterator it; it = deviceNames.find(StringTools::strfmt("%04X%04X",vid,pid)); - if (it != deviceNames.end()){ + if (it != deviceNames.end()) { result = it->second; - }else{ + } else { result = StringTools::strfmt("VID: 0x%04X\nPID: 0x%04X",vid,pid); } return result; diff --git a/source/network/CPTCPServer.hpp b/source/network/CPTCPServer.hpp index 895d766..109a6b4 100644 --- a/source/network/CPTCPServer.hpp +++ b/source/network/CPTCPServer.hpp @@ -46,12 +46,12 @@ #define DEFAULT_TCP_PORT 8112 -class CPTCPServer: TCPServer{ +class CPTCPServer: TCPServer { friend class ControllerPatcher; private: - static CPTCPServer *getInstance() { - if(!instance){ + static CPTCPServer *getInstance() { + if(!instance) { instance = new CPTCPServer(DEFAULT_TCP_PORT); } @@ -59,19 +59,19 @@ private: } static void destroyInstance() { - if(instance){ + if(instance) { delete instance; instance = NULL; } } - static s32 getPriority(){ + static s32 getPriority() { s32 priority = 28; if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN - OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA - OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR - OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR - OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA + OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA + OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR + OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR + OSGetTitleID() == 0x00050000101a3c00) { //The Binding of Isaac: Rebirth USA priority = 10; DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority); } diff --git a/source/network/UDPClient.cpp b/source/network/UDPClient.cpp index a7ef74f..ff13121 100644 --- a/source/network/UDPClient.cpp +++ b/source/network/UDPClient.cpp @@ -24,33 +24,34 @@ UDPClient * UDPClient::instance = NULL; -UDPClient::UDPClient(u32 ip, s32 port){ +UDPClient::UDPClient(u32 ip, s32 port) { sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (sockfd < 0) - return; + if (sockfd < 0) + return; - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = port; - connect_addr.sin_addr.s_addr = ip; + struct sockaddr_in connect_addr; + memset(&connect_addr, 0, sizeof(connect_addr)); + connect_addr.sin_family = AF_INET; + connect_addr.sin_port = port; + connect_addr.sin_addr.s_addr = ip; - if(connect(sockfd, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) - { - socketclose(sockfd); - sockfd = -1; - } + if(connect(sockfd, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) { + socketclose(sockfd); + sockfd = -1; + } } -UDPClient::~UDPClient(){ - if (this->sockfd != -1){ +UDPClient::~UDPClient() { + if (this->sockfd != -1) { socketclose(sockfd); } - if(HID_DEBUG){ log_printf("UDPClient::~UDPClient(line %d): Thread has been closed\n",__LINE__); } + if(HID_DEBUG) { + log_printf("UDPClient::~UDPClient(line %d): Thread has been closed\n",__LINE__); + } } -bool UDPClient::sendData(char * data,s32 length){ - if(sockfd < 0 || data == 0 || length < 0 || gUsedProtocolVersion < WIIU_CP_TCP_HANDSHAKE_VERSION_3){ +bool UDPClient::sendData(char * data,s32 length) { + if(sockfd < 0 || data == 0 || length < 0 || gUsedProtocolVersion < WIIU_CP_TCP_HANDSHAKE_VERSION_3) { return false; } if(length > 1400) length = 1400; diff --git a/source/network/UDPClient.hpp b/source/network/UDPClient.hpp index 6363037..326fd47 100644 --- a/source/network/UDPClient.hpp +++ b/source/network/UDPClient.hpp @@ -21,7 +21,7 @@ #define DEFAULT_UDP_CLIENT_PORT 8114 -class UDPClient{ +class UDPClient { friend class ControllerPatcher; friend class ControllerPatcherHID; friend class CPTCPServer; @@ -29,7 +29,7 @@ public: private: static UDPClient *getInstance() { - if(instance == NULL){ + if(instance == NULL) { createInstance(); } return instance; @@ -37,7 +37,7 @@ private: static UDPClient *createInstance() { - if(instance != NULL){ + if(instance != NULL) { destroyInstance(); } instance = new UDPClient(gUDPClientip,DEFAULT_UDP_CLIENT_PORT); @@ -46,7 +46,7 @@ private: } static void destroyInstance() { - if(instance != NULL){ + if(instance != NULL) { delete instance; instance = NULL; } diff --git a/source/network/UDPServer.cpp b/source/network/UDPServer.cpp index 4a39939..91aeddf 100644 --- a/source/network/UDPServer.cpp +++ b/source/network/UDPServer.cpp @@ -26,9 +26,9 @@ CThread * UDPServer::pThread = NULL; UDPServer * UDPServer::instance = NULL; -UDPServer::UDPServer(s32 port){ +UDPServer::UDPServer(s32 port) { s32 ret; - struct sockaddr_in addr; + struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = port; @@ -44,31 +44,33 @@ UDPServer::UDPServer(s32 port){ StartUDPThread(this); } -UDPServer::~UDPServer(){ +UDPServer::~UDPServer() { CThread * pThreadPointer = UDPServer::pThread; - if(pThreadPointer != NULL){ + if(pThreadPointer != NULL) { exitThread = 1; - if(pThreadPointer != NULL){ + if(pThreadPointer != NULL) { delete pThreadPointer; UDPServer::pThread = NULL; - if (this->sockfd != -1){ + if (this->sockfd != -1) { socketclose(sockfd); } this->sockfd = -1; } } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Thread has been closed\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Thread has been closed\n"); + } } -void UDPServer::StartUDPThread(UDPServer * server){ +void UDPServer::StartUDPThread(UDPServer * server) { s32 priority = 28; if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN - OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA - OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR - OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR - OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA + OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA + OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR + OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR + OSGetTitleID() == 0x00050000101a3c00) { //The Binding of Isaac: Rebirth USA priority = 10; DEBUG_FUNCTION_LINE("This game needs higher thread priority. We set it to %d\n",priority); } @@ -76,8 +78,8 @@ void UDPServer::StartUDPThread(UDPServer * server){ UDPServer::pThread->resumeThread(); } -bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum){ - if(((int)*offset + typesize) > maximum){ +bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum) { + if(((int)*offset + typesize) > maximum) { DEBUG_FUNCTION_LINE("Transfer error. Excepted %04X bytes, but only got %04X\n",(*offset + typesize),maximum); return false; } @@ -86,82 +88,84 @@ bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * off return true; } -void UDPServer::DoUDPThread(CThread *thread, void *arg){ +void UDPServer::DoUDPThread(CThread *thread, void *arg) { UDPServer * args = (UDPServer * )arg; args->DoUDPThreadInternal(); } -void UDPServer::DoUDPThreadInternal(){ +void UDPServer::DoUDPThreadInternal() { u8 buffer[MAX_UDP_SIZE]; s32 n; my_cb_user user; - while(1){ + while(1) { //s32 usingVar = exitThread; if(exitThread)break; memset(buffer,0,MAX_UDP_SIZE); n = recv(sockfd,buffer,MAX_UDP_SIZE,0); - if (n < 0){ + if (n < 0) { s32 errno_ = socketlasterr(); OSSleepTicks(OSMicrosecondsToTicks(2000)); - if(errno_ != 11 && errno_ != 9){ + if(errno_ != 11 && errno_ != 9) { break; } - continue; + continue; } s32 bufferoffset = 0; u8 type; memcpy((void *)&type,buffer,sizeof(type)); bufferoffset += sizeof(type); switch (buffer[0]) { - case WIIU_CP_UDP_CONTROLLER_READ_DATA: { - if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){ - u8 count_commands; - memcpy((void *)&count_commands,buffer+bufferoffset,sizeof(count_commands)); - bufferoffset += sizeof(count_commands); - for(s32 i = 0;i= WIIU_CP_TCP_HANDSHAKE_VERSION_1) { + u8 count_commands; + memcpy((void *)&count_commands,buffer+bufferoffset,sizeof(count_commands)); + bufferoffset += sizeof(count_commands); + for(s32 i = 0; ipad_slot < HID_MAX_PADS_COUNT){ + if(usr->pad_slot < HID_MAX_PADS_COUNT) { slot = usr->pad_slot; } @@ -59,7 +59,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne data_ptr->type = DEVICE_TYPE_MOUSE; //DEBUG_FUNCTION_LINE("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered); - if(buf[0] == 2 && bytes_transfered > 3){ // using the other mouse mode + if(buf[0] == 2 && bytes_transfered > 3) { // using the other mouse mode buf +=1; } @@ -76,7 +76,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne cur_mouse_data->deltaY = y_value; cur_mouse_data->left_click = buf[0]; - cur_mouse_data->right_click = buf[0]>>1; + cur_mouse_data->right_click = buf[0]>>1; if(cur_mouse_data->X < 0) cur_mouse_data->X = 0; if(cur_mouse_data->X > 1280) cur_mouse_data->X = 1280; @@ -89,36 +89,38 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne //DEBUG_FUNCTION_LINE("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value); HIDRead(handle, usr->buf, bytes_transfered, myHIDMouseReadCallback, usr); - } + } } -void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){ - if(error == 0 && p_user != NULL && gHIDAttached){ - my_cb_user *usr = (my_cb_user*)p_user; +void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user) { + if(error == 0 && p_user != NULL && gHIDAttached) { + my_cb_user *usr = (my_cb_user*)p_user; - HIDReadCallback(handle,buf,bytes_transfered,usr); + HIDReadCallback(handle,buf,bytes_transfered,usr); - if(usr->slotdata.hidmask == gHID_LIST_DS4){ - OSSleepTicks(OSMicrosecondsToTicks(2000)); //DS4 is way tooo fast. sleeping to reduce lag. (need to check the other pads) - } + if(usr->slotdata.hidmask == gHID_LIST_DS4) { + OSSleepTicks(OSMicrosecondsToTicks(2000)); //DS4 is way tooo fast. sleeping to reduce lag. (need to check the other pads) + } HIDRead(handle, usr->buf, bytes_transfered, myHIDReadCallback, usr); - } + } } /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Intern Callback actions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach){ - if(attach){ +s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach) { + if(attach) { DEBUG_FUNCTION_LINE("vid %04x pid %04x connected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("interface index %02x\n", p_device->interfaceIndex); - DEBUG_FUNCTION_LINE("sub class %02x\n", p_device->subClass); - DEBUG_FUNCTION_LINE("protocol %02x\n", p_device->protocol); - DEBUG_FUNCTION_LINE("max packet in %02x\n", p_device->maxPacketSizeRx); - DEBUG_FUNCTION_LINE("max packet out %02x\n", p_device->maxPacketSizeRx); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("interface index %02x\n", p_device->interfaceIndex); + DEBUG_FUNCTION_LINE("sub class %02x\n", p_device->subClass); + DEBUG_FUNCTION_LINE("protocol %02x\n", p_device->protocol); + DEBUG_FUNCTION_LINE("max packet in %02x\n", p_device->maxPacketSizeRx); + DEBUG_FUNCTION_LINE("max packet out %02x\n", p_device->maxPacketSizeRx); + } } - if(!attach){ + if(!attach) { DEBUG_FUNCTION_LINE("vid %04x pid %04x disconnected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); } DeviceInfo device_info; @@ -133,24 +135,24 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p slotdata->hidmask = gHID_LIST_KEYBOARD; slotdata->deviceslot = gHID_SLOT_KEYBOARD; //DEBUG_FUNCTION_LINE("Found Keyboard: device: %s slot: %d\n",byte_to_binary(device_info.slotdata.hidmask),device_info.slotdata.deviceslot); - }else if ((p_device->subClass == 1) && (p_device->protocol == 2)){ // MOUSE + } else if ((p_device->subClass == 1) && (p_device->protocol == 2)) { // MOUSE slotdata->hidmask = gHID_LIST_MOUSE; slotdata->deviceslot = gMouseSlot; //DEBUG_FUNCTION_LINE("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot); - }else{ + } else { s32 ret; - if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ + if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0) { DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",ret); return HID_DEVICE_DETACH; - }else{ + } else { //DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",ret); } } - if(slotdata->hidmask){ - if(attach){ + if(slotdata->hidmask) { + if(attach) { s32 bufSize = 64; - if(slotdata->hidmask != gHID_LIST_MOUSE && config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){ + if(slotdata->hidmask != gHID_LIST_MOUSE && config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET) { bufSize = config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][1]; } unsigned char *buf = (unsigned char *) memalign(64,bufSize); @@ -163,9 +165,9 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p gHIDAttached |= slotdata->hidmask; gHIDCurrentDevice |= slotdata->hidmask; s32 pads_per_device = 1; - if(config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { pads_per_device = config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][1]; - if(pads_per_device > HID_MAX_PADS_COUNT){//maximum of HID_MAX_PADS_COUNT + if(pads_per_device > HID_MAX_PADS_COUNT) { //maximum of HID_MAX_PADS_COUNT pads_per_device = HID_MAX_PADS_COUNT; } } @@ -177,8 +179,8 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p s32 failed = 1; - for(s32 i = 0;ipads_per_device = pads_per_device; usr->pad_slot = pad_slot; - for(s32 i = 0;ideviceslot].pad_data[pad_slot+i],0,sizeof(HID_Data)); gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].handle = p_device->handle; @@ -220,9 +222,11 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data)); } - if(HID_DEBUG){ DEBUG_FUNCTION_LINE("Device successfully attached\n"); } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Device successfully attached\n"); + } - if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD + if(slotdata->hidmask == gHID_LIST_GC) { // GC PAD //The GC Adapter has all ports in one device. Set them all. gHID_Devices[slotdata->deviceslot].pad_data[0].slotdata = device_info.slotdata; gHID_Devices[slotdata->deviceslot].pad_data[1].slotdata = device_info.slotdata; @@ -232,16 +236,16 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p buf[0] = 0x13; HIDWrite(p_device->handle, usr->buf, 1, NULL,NULL); HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_MOUSE){ + } else if (slotdata->hidmask == gHID_LIST_MOUSE) { HIDSetProtocol(p_device->handle, p_device->interfaceIndex, 0, 0, 0); //HIDGetDescriptor(p_device->handle,0x22,0x00,0,my_buf,512,my_foo_cb,NULL); HIDSetIdle(p_device->handle,p_device->interfaceIndex,1,NULL,NULL); gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; HIDRead(p_device->handle, buf, p_device->maxPacketSizeRx, myHIDMouseReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_SWITCH_PRO){ + } 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 + if(read_result == 64) { + if(usr->buf[01] == 0x01) { //We need to do the handshake DEBUG_FUNCTION_LINE("Switch Pro Controller handshake needed\n"); /** Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering) @@ -261,31 +265,34 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p buf[1] = 0x04; HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); - }else{ + } else { DEBUG_FUNCTION_LINE("Switch Pro Controller handshake already done\n"); } HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr); } - }else if (slotdata->hidmask == gHID_LIST_KEYBOARD){ + } else if (slotdata->hidmask == gHID_LIST_KEYBOARD) { HIDSetProtocol(p_device->handle, p_device->interfaceIndex, 1, 0, 0); HIDSetIdle(p_device->handle, p_device->interfaceIndex, 0, 0, 0); HIDRead(p_device->handle, buf, p_device->maxPacketSizeRx, myHIDReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_DS3){ + } else if (slotdata->hidmask == gHID_LIST_DS3) { HIDSetProtocol(p_device->handle, p_device->interfaceIndex, 1, 0, 0); HIDDS3Rumble(p_device->handle,usr,0); - buf[0] = 0x42; buf[1] = 0x0c; buf[2] = 0x00; buf[3] = 0x00; + buf[0] = 0x42; + buf[1] = 0x0c; + buf[2] = 0x00; + buf[3] = 0x00; HIDSetReport(p_device->handle, HID_REPORT_FEATURE, PS3_F4_REPORT_ID, buf, PS3_F4_REPORT_LEN, NULL, NULL); HIDRead(p_device->handle, usr->buf, p_device->maxPacketSizeRx, myHIDReadCallback, usr); - }else{ + } else { HIDRead(p_device->handle, usr->buf, p_device->maxPacketSizeRx, myHIDReadCallback, usr); } return HID_DEVICE_ATTACH; - }else{ + } else { my_cb_user * user_data = NULL; s32 founddata = 0; - for(s32 i = 0;ideviceslot].pad_data[i].handle == p_device->handle){ + for(s32 i = 0; ideviceslot].pad_data[i].handle == p_device->handle) { gHID_Devices[slotdata->deviceslot].pad_data[i].handle = 0; DCFlushRange(&gHID_Devices[slotdata->deviceslot].pad_data[i].handle,sizeof(gHID_Devices[slotdata->deviceslot].pad_data[i].handle)); @@ -298,21 +305,23 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p } } - if(user_data){ + if(user_data) { config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] &= ~ (1 << user_data->pad_slot); DCFlushRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); DCInvalidateRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); - if(user_data->buf){ + if(user_data->buf) { free(user_data->buf); user_data->buf = NULL; } free(user_data); user_data = NULL; - }else{ - if(founddata){ DEBUG_FUNCTION_LINE("user_data null. You may have a memory leak.\n"); } + } else { + if(founddata) { + DEBUG_FUNCTION_LINE("user_data null. You may have a memory leak.\n"); + } return HID_DEVICE_DETACH; } - if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0){ + if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0) { gHIDAttached &= ~slotdata->hidmask; gHIDCurrentDevice &= ~slotdata->hidmask; @@ -321,29 +330,33 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p DCFlushRange(&gHIDCurrentDevice,sizeof(gHIDCurrentDevice)); DCInvalidateRange(&gHIDCurrentDevice,sizeof(gHIDCurrentDevice)); - if (slotdata->hidmask == gHID_LIST_MOUSE){ + if (slotdata->hidmask == gHID_LIST_MOUSE) { gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; } - }else{ - if(HID_DEBUG){DEBUG_FUNCTION_LINE("We still have pad for deviceslot %d connected.\n",slotdata->deviceslot); } + } else { + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("We still have pad for deviceslot %d connected.\n",slotdata->deviceslot); + } + } + if(HID_DEBUG) { + DEBUG_FUNCTION_LINE("Device successfully detached\n"); } - if(HID_DEBUG){DEBUG_FUNCTION_LINE("Device successfully detached\n"); } } - }else{ + } else { DEBUG_FUNCTION_LINE("HID-Device currently not supported! You can add support through config files\n"); - } - return HID_DEVICE_DETACH; + } + return HID_DEVICE_DETACH; } -void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){ +void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr) { ControllerPatcherUtils::doSampling(usr->slotdata.deviceslot,usr->pad_slot,false); //DEBUG_FUNCTION_LINE("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot); - if(usr->slotdata.hidmask == gHID_LIST_GC){ + 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++){ + 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. @@ -357,10 +370,10 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b DEBUG_FUNCTION_LINE("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++; DEBUG_FUNCTION_LINE("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){ + } 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){ + if(usr->slotdata.hidmask == gHID_LIST_SWITCH_PRO && buf != NULL && bytes_transfered >= 0x20) { u8 buffer[0x13]; memcpy(buffer,buf+0x0D,0x013); @@ -379,7 +392,7 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b //We want to get the next input! s32 res = HIDWrite(handle, buf, 9, NULL,NULL); - if(res == 9){ //Check if it's the USB data format. + 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; @@ -407,24 +420,24 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b //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)){ + ((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)){ + } 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)){ + } 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)){ + } 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){ + } 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){ + } 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){ + } 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){ + } 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; } @@ -448,15 +461,15 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b s32 skip = 0; //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]){ + 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){ + if(!skip) { u32 slot = 0; - if(usr->pad_slot < HID_MAX_PADS_COUNT){ + 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. @@ -479,19 +492,19 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b * Other functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(VPADStatus * buffer,std::vector& data){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(VPADStatus * buffer,std::vector& data) { if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; HID_Data * data_cur; s32 buttons_hold; - for(u32 i = 0;islotdata.hidmask & gHID_LIST_MOUSE){ //Reset the input when we have no new inputs + if(data_cur->slotdata.hidmask & gHID_LIST_MOUSE) { //Reset the input when we have no new inputs HID_Mouse_Data * mouse_data = &data_cur->data_union.mouse.cur_mouse_data; - if(mouse_data->valuedChanged == 1){ //Fix for the mouse cursor + if(mouse_data->valuedChanged == 1) { //Fix for the mouse cursor mouse_data->valuedChanged = 0; - }else{ + } else { mouse_data->deltaX = 0; mouse_data->deltaY = 0; } @@ -540,7 +553,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V } // Caculates a valid stick position - if(data.size() > 0){ + if(data.size() > 0) { ControllerPatcherUtils::normalizeStickValues(&buffer->leftStick); ControllerPatcherUtils::normalizeStickValues(&buffer->rightStick); } @@ -548,17 +561,17 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V return CONTROLLER_PATCHER_ERROR_NONE; } -std::vector ControllerPatcherHID::getHIDDataAll(){ +std::vector ControllerPatcherHID::getHIDDataAll() { u32 hid = gHIDCurrentDevice; std::vector data_list; - for(s32 i = 0;i < gHIDMaxDevices;i++){ - if((hid & (1 << i)) != 0){ + for(s32 i = 0; i < gHIDMaxDevices; i++) { + if((hid & (1 << i)) != 0) { u32 cur_hidmask = config_controller_hidmask[i]; - for(s32 pad = 0; pad < HID_MAX_PADS_COUNT; pad++){ + for(s32 pad = 0; pad < HID_MAX_PADS_COUNT; pad++) { s32 res; HID_Data * new_data = NULL; - if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid. + if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0) { // Checks if the pad is invalid. //DEBUG_FUNCTION_LINE("error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",StringTools::byte_to_binary(cur_hidmask),pad,res); continue; } @@ -572,18 +585,18 @@ std::vector ControllerPatcherHID::getHIDDataAll(){ /* The slotdata in the HID_Data pointer is empty. We need to provide the hidmask via the parameter */ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(u32 hidmask, s32 pad, HID_Data ** data){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(u32 hidmask, s32 pad, HID_Data ** data) { if(data == NULL) return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER; if(!(hidmask & gHIDCurrentDevice)) return CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED; if(pad < 0 && pad > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; s32 device_slot = ControllerPatcherUtils::getDeviceSlot(hidmask); - if(device_slot < 0){ + if(device_slot < 0) { return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; } s32 real_pad = pad; - if((device_slot != gHID_SLOT_GC) && config_controller[device_slot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if((device_slot != gHID_SLOT_GC) && config_controller[device_slot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { s32 pad_count = config_controller[device_slot][CONTRPS_PAD_COUNT][1]; if(pad_count > HID_MAX_PADS_COUNT) pad_count = HID_MAX_PADS_COUNT; pad = (pad/(pad_count))*pad_count; @@ -591,7 +604,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(u32 hidmask, s32 result = ControllerPatcherUtils::checkActivePad(hidmask,pad); - if(result < 0){ //Not pad connected to adapter + if(result < 0) { //Not pad connected to adapter return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; } @@ -601,40 +614,40 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(u32 hidmask, } -void ControllerPatcherHID::HIDGCRumble(u32 handle,my_cb_user *usr){ +void ControllerPatcherHID::HIDGCRumble(u32 handle,my_cb_user *usr) { if(usr == NULL) return; if(!ControllerPatcher::isRumbleActivated()) return; s32 rumblechanged = 0; - for(s32 i = 0;islotdata.deviceslot].pad_data[i]); - if(data_ptr->rumbleActive != usr->rumblestatus[i]){ + if(data_ptr->rumbleActive != usr->rumblestatus[i]) { rumblechanged = 1; } usr->rumblestatus[i] = data_ptr->rumbleActive; usr->buf[i+1] = usr->rumblestatus[i]; } usr->forceRumbleInTicks[0]--; - if(rumblechanged || usr->forceRumbleInTicks[0] <= 0){ + if(rumblechanged || usr->forceRumbleInTicks[0] <= 0) { usr->buf[0] = 0x11; HIDWrite(handle, usr->buf, 5, NULL, NULL); usr->forceRumbleInTicks[0] = 10; } } -void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){ +void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad) { if(usr == NULL || pad > HID_MAX_PADS_COUNT) return; if(!ControllerPatcher::isRumbleActivated()) return; s32 rumblechanged = 0; HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[pad]); - if(data_ptr->rumbleActive != usr->rumblestatus[pad]){ + if(data_ptr->rumbleActive != usr->rumblestatus[pad]) { usr->rumblestatus[pad] = data_ptr->rumbleActive; rumblechanged = 1; } usr->forceRumbleInTicks[pad]--; - if(rumblechanged || usr->forceRumbleInTicks[pad] <= 0){ + if(rumblechanged || usr->forceRumbleInTicks[pad] <= 0) { //DEBUG_FUNCTION_LINE("Rumble: %d %d\n",usr->rumblestatus[pad],usr->rumbleForce[pad]); //Seding to the network client! char bytes[6]; @@ -648,22 +661,21 @@ void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){ bytes[i++] = usr->rumblestatus[pad]; UDPClient * instance = UDPClient::getInstance(); - if(instance != NULL){ + if(instance != NULL) { instance->sendData(bytes,6); } - if(usr->slotdata.hidmask == gHID_LIST_DS3){ + if(usr->slotdata.hidmask == gHID_LIST_DS3) { HIDDS3Rumble(handle,usr,usr->rumblestatus[pad]); - }else{ + } else { // Not implemented for other devices =( } usr->forceRumbleInTicks[pad] = 10; } } -static u8 ds3_rumble_Report[48] = -{ +static u8 ds3_rumble_Report[48] = { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x27, 0x10, 0x00, 0x32, @@ -676,7 +688,7 @@ static u8 ds3_rumble_Report[48] = 0x00, 0x00, 0x00, }; -void ControllerPatcherHID::HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble){ +void ControllerPatcherHID::HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble) { memcpy(usr->buf, ds3_rumble_Report, 48); if (rumble) { diff --git a/source/patcher/ControllerPatcherHID.hpp b/source/patcher/ControllerPatcherHID.hpp index 647178f..c1c15d0 100644 --- a/source/patcher/ControllerPatcherHID.hpp +++ b/source/patcher/ControllerPatcherHID.hpp @@ -40,38 +40,38 @@ #define SWAP16(x) ((x>>8) | ((x&0xFF)<<8)) #define SWAP8(x) ((x>>4) | ((x&0xF)<<4)) -class ControllerPatcherHID{ - friend class ControllerPatcher; - friend class ControllerPatcherUtils; - public: - static s32 externAttachDetachCallback(HIDDevice *p_device, HIDAttachEvent attach); - static void externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); +class ControllerPatcherHID { + friend class ControllerPatcher; + friend class ControllerPatcherUtils; +public: + static s32 externAttachDetachCallback(HIDDevice *p_device, HIDAttachEvent attach); + static void externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); - private: - static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADStatus * buffer,std::vector& data); - static std::vector getHIDDataAll(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(u32 hidmask, s32 pad, HID_Data ** data); +private: + static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADStatus * buffer,std::vector& data); + static std::vector getHIDDataAll(); + static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(u32 hidmask, s32 pad, HID_Data ** data); -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Rumble - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * Rumble + *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - static void HIDRumble(u32 handle,my_cb_user *usr,u32 pad); + static void HIDRumble(u32 handle,my_cb_user *usr,u32 pad); - static void HIDGCRumble(u32 handle,my_cb_user *usr); + static void HIDGCRumble(u32 handle,my_cb_user *usr); - static void HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble); + static void HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble); -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * HID Callbacks - *--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - static s32 myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach); + /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * HID Callbacks + *--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ + static s32 myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach); - static void myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); - static void myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); + static void myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); + static void myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); - static s32 AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach); - static void HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); + static s32 AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach); + static void HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); }; #endif /* _CONTROLLER_PATCHER_HID_H_ */ diff --git a/source/patcher/ControllerPatcherUtils.cpp b/source/patcher/ControllerPatcherUtils.cpp index 9ff1fbf..832210f 100644 --- a/source/patcher/ControllerPatcherUtils.cpp +++ b/source/patcher/ControllerPatcherUtils.cpp @@ -20,11 +20,11 @@ #include -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){ - for(s32 i = 0;i< gHIDMaxDevices;i++){ - for(s32 j = 0;j<4;j++){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data) { + for(s32 i = 0; i< gHIDMaxDevices; i++) { + for(s32 j = 0; j<4; j++) { //log_printf("%d %d %d %d\n",i,j,gHID_Devices[i].pad_data[j].handle,(u32)handle); - if(gHID_Devices[i].pad_data[j].handle == (u32)handle){ + if(gHID_Devices[i].pad_data[j].handle == (u32)handle) { *data = gHID_Devices[i].pad_data[j].user_data; return CONTROLLER_PATCHER_ERROR_NONE; } @@ -36,87 +36,91 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 h * Analyse inputs *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton) { if(data == NULL || buttons_hold == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 deviceslot = data->slotdata.deviceslot; s32 result = -1; - do{ - if(data->type == DEVICE_TYPE_MOUSE){ + do { + if(data->type == DEVICE_TYPE_MOUSE) { HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ - if(VPADButton == VPAD_BUTTON_TOUCH){ - if(ms_data->left_click & 0x01){ - result = 1; break; + if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH) { + if(VPADButton == VPAD_BUTTON_TOUCH) { + if(ms_data->left_click & 0x01) { + result = 1; + break; } } - }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][1]]){ - if(ms_data->left_click & 0x01){ - result = 1; break; + } else if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM) { + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][0] == CONTROLLER_PATCHER_VALUE_SET) { + if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][1]]) { + if(ms_data->left_click & 0x01) { + result = 1; + break; } } } - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][1]]){ - if(ms_data->right_click & 0x01){ - result = 1; break; + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][0] == CONTROLLER_PATCHER_VALUE_SET) { + if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][1]]) { + if(ms_data->right_click & 0x01) { + result = 1; + break; } } } } - result = 0; break; + result = 0; + break; } u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 cur_config = 0; - if(VPADButton == VPAD_BUTTON_A){ + if(VPADButton == VPAD_BUTTON_A) { cur_config = CONTRPS_VPAD_BUTTON_A; - }else if(VPADButton == VPAD_BUTTON_B){ + } else if(VPADButton == VPAD_BUTTON_B) { cur_config = CONTRPS_VPAD_BUTTON_B; - }else if(VPADButton == VPAD_BUTTON_X){ + } else if(VPADButton == VPAD_BUTTON_X) { cur_config = CONTRPS_VPAD_BUTTON_X; - }else if(VPADButton == VPAD_BUTTON_Y){ + } else if(VPADButton == VPAD_BUTTON_Y) { cur_config = CONTRPS_VPAD_BUTTON_Y; - }else if(VPADButton == VPAD_BUTTON_L){ + } else if(VPADButton == VPAD_BUTTON_L) { cur_config = CONTRPS_VPAD_BUTTON_L; - }else if(VPADButton == VPAD_BUTTON_R){ + } else if(VPADButton == VPAD_BUTTON_R) { cur_config = CONTRPS_VPAD_BUTTON_R; - }else if(VPADButton == VPAD_BUTTON_ZL){ + } else if(VPADButton == VPAD_BUTTON_ZL) { cur_config = CONTRPS_VPAD_BUTTON_ZL; - }else if(VPADButton == VPAD_BUTTON_ZR){ + } else if(VPADButton == VPAD_BUTTON_ZR) { cur_config = CONTRPS_VPAD_BUTTON_ZR; - }else if(VPADButton == VPAD_BUTTON_STICK_L){ + } else if(VPADButton == VPAD_BUTTON_STICK_L) { cur_config = CONTRPS_VPAD_BUTTON_STICK_L; - }else if(VPADButton == VPAD_BUTTON_STICK_R){ + } else if(VPADButton == VPAD_BUTTON_STICK_R) { cur_config = CONTRPS_VPAD_BUTTON_STICK_R; - }else if(VPADButton == VPAD_BUTTON_PLUS){ + } else if(VPADButton == VPAD_BUTTON_PLUS) { cur_config = CONTRPS_VPAD_BUTTON_PLUS; - }else if(VPADButton == VPAD_BUTTON_MINUS){ + } else if(VPADButton == VPAD_BUTTON_MINUS) { cur_config = CONTRPS_VPAD_BUTTON_MINUS; - }else if(VPADButton == VPAD_BUTTON_HOME){ + } else if(VPADButton == VPAD_BUTTON_HOME) { cur_config = CONTRPS_VPAD_BUTTON_HOME; } //! Special DPAD treatment. - if(config_controller[deviceslot][CONTRPS_DPAD_MODE][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Hat){ + if(config_controller[deviceslot][CONTRPS_DPAD_MODE][0] == CONTROLLER_PATCHER_VALUE_SET) { + if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Hat) { u8 mask = 0x0F; - if(config_controller[deviceslot][CONTRPS_DPAD_MASK][0] == CONTROLLER_PATCHER_VALUE_SET){ - mask = config_controller[deviceslot][CONTRPS_DPAD_MASK][1]; + if(config_controller[deviceslot][CONTRPS_DPAD_MASK][0] == CONTROLLER_PATCHER_VALUE_SET) { + mask = config_controller[deviceslot][CONTRPS_DPAD_MASK][1]; } - if(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][0]] != config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][1]){ // Not neutral + if(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][0]] != config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][1]) { // Not neutral u8 dir1_0 = 0,dir1_1 = 0; u8 dir2_0 = 0,dir2_1 = 0; u8 dir3_0 = 0,dir3_1 = 0; u8 direction = 0; - if(VPADButton == VPAD_BUTTON_LEFT){ + if(VPADButton == VPAD_BUTTON_LEFT) { dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_W][0]; dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][0]; dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][0]; @@ -124,7 +128,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_ dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][1]; dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][1]; direction = 1; - }else if(VPADButton == VPAD_BUTTON_RIGHT){ + } else if(VPADButton == VPAD_BUTTON_RIGHT) { dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_E][0]; dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][0]; dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][0]; @@ -132,7 +136,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_ dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][1]; dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][1]; direction = 1; - }else if(VPADButton == VPAD_BUTTON_DOWN){ + } else if(VPADButton == VPAD_BUTTON_DOWN) { dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_S][0]; dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][0]; dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][0]; @@ -140,7 +144,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_ dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][1]; dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][1]; direction = 1; - }else if(VPADButton == VPAD_BUTTON_UP){ + } else if(VPADButton == VPAD_BUTTON_UP) { dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_N][0]; dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][0]; dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][0]; @@ -150,26 +154,29 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_ direction = 1; } if(direction && (((cur_data[dir1_0] & mask) == dir1_1) || - ((cur_data[dir2_0] & mask) == dir2_1) || - ((cur_data[dir3_0] & mask) == dir3_1))) {result = 1; break;} + ((cur_data[dir2_0] & mask) == dir2_1) || + ((cur_data[dir3_0] & mask) == dir3_1))) { + result = 1; + break; + } } - }else if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values){ + } else if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values) { s32 contrps_value = 0; - if(VPADButton == VPAD_BUTTON_LEFT){ + if(VPADButton == VPAD_BUTTON_LEFT) { contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT; - }else if(VPADButton == VPAD_BUTTON_RIGHT){ + } else if(VPADButton == VPAD_BUTTON_RIGHT) { contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_RIGHT; - }else if(VPADButton == VPAD_BUTTON_UP){ + } else if(VPADButton == VPAD_BUTTON_UP) { contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_UP; - }else if(VPADButton == VPAD_BUTTON_DOWN){ + } else if(VPADButton == VPAD_BUTTON_DOWN) { contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_DOWN; } - if(contrps_value != 0){ + if(contrps_value != 0) { s32 value_byte = CONTROLLER_PATCHER_INVALIDVALUE; - if((value_byte = config_controller[deviceslot][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE){ - if(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]){ + if((value_byte = config_controller[deviceslot][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE) { + if(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]) { result = 1; break; } @@ -179,49 +186,80 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_ } //! Normal DPAD treatment. - if(VPADButton == VPAD_BUTTON_LEFT){ + if(VPADButton == VPAD_BUTTON_LEFT) { cur_config = CONTRPS_VPAD_BUTTON_LEFT; - }else if(VPADButton == VPAD_BUTTON_RIGHT){ + } else if(VPADButton == VPAD_BUTTON_RIGHT) { cur_config = CONTRPS_VPAD_BUTTON_RIGHT; - }else if(VPADButton == VPAD_BUTTON_DOWN){ + } else if(VPADButton == VPAD_BUTTON_DOWN) { cur_config = CONTRPS_VPAD_BUTTON_DOWN; - }else if(VPADButton == VPAD_BUTTON_UP){ + } else if(VPADButton == VPAD_BUTTON_UP) { cur_config = CONTRPS_VPAD_BUTTON_UP; } - if(result && config_controller[deviceslot][CONTRPS_DOUBLE_USE][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(config_controller[deviceslot][CONTRPS_DOUBLE_USE][1] == CONTROLLER_PATCHER_GC_DOUBLE_USE){ - if(cur_data[config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][0]] & config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][1]){ - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED,cur_config)){result = 0; break;} - }else{ - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED,cur_config)){result = 0; break;} + if(result && config_controller[deviceslot][CONTRPS_DOUBLE_USE][0] == CONTROLLER_PATCHER_VALUE_SET) { + if(config_controller[deviceslot][CONTRPS_DOUBLE_USE][1] == CONTROLLER_PATCHER_GC_DOUBLE_USE) { + if(cur_data[config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][0]] & config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][1]) { + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED,cur_config)) { + result = 0; + break; + } + } else { + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED,cur_config)) { + result = 0; + break; + } + if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED,cur_config)) { + result = 0; + break; + } } } } - if(isValueSet(data,cur_config) == 1){ - result = 1; break; - }else{ + if(isValueSet(data,cur_config) == 1) { + result = 1; + break; + } else { //log_printf("Invalid data! deviceslot(slot): %d config: %d\n",deviceslot,cur_config); } - }while(0); //The break will become handy ;) + } while(0); //The break will become handy ;) - if(result == 1){ + if(result == 1) { *buttons_hold |= VPADButton; // -1 would be also true. return 1; } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config) { if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; @@ -231,25 +269,25 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * s32 deviceslot = data->slotdata.deviceslot; s32 result = CONTROLLER_PATCHER_ERROR_NONE; - if(config_controller[deviceslot][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //Invalid data - if(hidmask & gHID_LIST_KEYBOARD){ + if(config_controller[deviceslot][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE) { //Invalid data + if(hidmask & gHID_LIST_KEYBOARD) { if(isInKeyboardData(cur_data,config_controller[deviceslot][cur_config][1]) > 0) { result = 1; } - }else{ - if((cur_data[config_controller[deviceslot][cur_config][0]] & config_controller[deviceslot][cur_config][1]) == config_controller[deviceslot][cur_config][1]){ + } else { + if((cur_data[config_controller[deviceslot][cur_config][0]] & config_controller[deviceslot][cur_config][1]) == config_controller[deviceslot][cur_config][1]) { result = 1; } } } return result; - } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsigned char * keyboardData,s32 key){ +} +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsigned char * keyboardData,s32 key) { if(keyboardData == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - for(s32 i = 0;i 1){ - break; - }else if (keyboardData[i] == key){ + for(s32 i = 0; i 1) { + break; + } else if (keyboardData[i] == key) { return 1; } } @@ -260,27 +298,27 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsi * Utils for setting the Button data *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT) { if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; u32 new_value = VPADButton; - if(config_controller[gGamePadSlot][CONTRPS_SLOT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //using new value! - new_value = gGamePadValues[config_controller[gGamePadSlot][CONTRPS_SLOT][1]]; + if(config_controller[gGamePadSlot][CONTRPS_SLOT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { //using new value! + new_value = gGamePadValues[config_controller[gGamePadSlot][CONTRPS_SLOT][1]]; } setButtonData(old_buffer,new_buffer,VPADButton,new_value); return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton) { if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if((old_buffer->hold & oldVPADButton) == oldVPADButton){ + if((old_buffer->hold & oldVPADButton) == oldVPADButton) { new_buffer->hold |= newVPADButton; } - if((old_buffer->release & oldVPADButton) == oldVPADButton){ + if((old_buffer->release & oldVPADButton) == oldVPADButton) { new_buffer->release |= newVPADButton; } - if((old_buffer->trigger & oldVPADButton) == oldVPADButton){ + if((old_buffer->trigger & oldVPADButton) == oldVPADButton) { new_buffer->trigger |= newVPADButton; } @@ -291,16 +329,16 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADSta * Pad Status functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hidmask,s32 pad){ - if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hidmask,s32 pad) { + if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3) { if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1; return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; - }else{ + } else { s32 deviceslot = getDeviceSlot(hidmask); if(deviceslot < 0 ) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; s32 connected_pads = config_controller[deviceslot][CONTRPS_CONNECTED_PADS][1]; - if((connected_pads & (1 << pad)) > 0){ + if((connected_pads & (1 << pad)) > 0) { return 1; } } @@ -324,53 +362,61 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(u32 hidm * Stick functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::normalizeStickValues(VPADVec2D * stick){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::normalizeStickValues(VPADVec2D * stick) { if(stick == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; f32 max_val = 0.0f; f32 mul_val = 0.0f; - if((max_val = (fabs(stick->x)) + fabs(stick->y)) > 1.414f){ + if((max_val = (fabs(stick->x)) + fabs(stick->y)) > 1.414f) { mul_val = 1.414f / max_val; stick->x *= mul_val; stick->y *= mul_val; } - if(stick->x > 1.0f){ stick->x = 1.0f; } - if(stick->y > 1.0f){ stick->y = 1.0f; } - if(stick->x < -1.0f){ stick->x = -1.0f; } - if(stick->y < -1.0f){ stick->y = -1.0f; } + if(stick->x > 1.0f) { + stick->x = 1.0f; + } + if(stick->y > 1.0f) { + stick->y = 1.0f; + } + if(stick->x < -1.0f) { + stick->x = -1.0f; + } + if(stick->y < -1.0f) { + stick->y = -1.0f; + } return CONTROLLER_PATCHER_ERROR_NONE; } -f32 ControllerPatcherUtils::convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone){ +f32 ControllerPatcherUtils::convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone) { s8 new_value = (s8)(value - default_val); u8 range = 0; - if(value >= max){ + if(value >= max) { if(invert == 0x01) return -1.0f; return 1.0f; - }else if(value <= min){ + } else if(value <= min) { if(invert == 0x01) return 1.0f; return -1.0f; } - if((value-deadzone) > default_val){ + if((value-deadzone) > default_val) { new_value -= deadzone; range = (max - (default_val + deadzone)); - }else if((value+deadzone) < default_val){ + } else if((value+deadzone) < default_val) { new_value += deadzone; range = ((default_val - deadzone) - min); - }else{ + } else { return 0.0f; } - if(invert != 0x01){ + if(invert != 0x01) { return (new_value / (1.0f*range)); - }else{ + } else { return -1.0f*(new_value / (1.0f*range)); } } -VPADVec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){ +VPADVec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values) { VPADVec2D stick; stick.x = 0.0f; stick.y = 0.0f; @@ -380,53 +426,53 @@ VPADVec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){ u8 left = ((stick_values & STICK_VALUE_LEFT) == STICK_VALUE_LEFT); u8 right = ((stick_values & STICK_VALUE_RIGHT) == STICK_VALUE_RIGHT); - if(up){ - if(!down){ + if(up) { + if(!down) { stick.y = 1.0f; } - if(left || right){ + if(left || right) { stick.y = 0.707f; if(left) stick.x = -0.707f; if(right) stick.x = 0.707f; } - }else if(down){ - if(!up){ + } else if(down) { + if(!up) { stick.y = -1.0f; } - if(left || right){ + if(left || right) { stick.y = -0.707f; if(left) stick.x = -0.707f; if(right) stick.x = 0.707f; } - }else{ - if(left){ - if(!right){ + } else { + if(left) { + if(!right) { stick.x = -1.0f; - } + } - }else if(right){ - if(!down){ + } else if(right) { + if(!down) { stick.x = 1.0f; - } + } } } return stick; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADStatus * buffer){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADStatus * buffer) { if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 deviceslot = data->slotdata.deviceslot; - if (data->type == DEVICE_TYPE_MOUSE){ - if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values + if (data->type == DEVICE_TYPE_MOUSE) { + if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM) { // TODO: tweak values HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; f32 x_value = ms_data->deltaX/10.0f; f32 y_value = -1.0f*(ms_data->deltaY/10.0f); - if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][1] == DEF_L_STICK){ + if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][0] != CONTROLLER_PATCHER_INVALIDVALUE) { + if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][1] == DEF_L_STICK) { buffer->leftStick.x += x_value; buffer->leftStick.y += y_value; return CONTROLLER_PATCHER_ERROR_NONE; @@ -436,117 +482,149 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H buffer->rightStick.x += x_value; buffer->rightStick.y += y_value; } - }else{ + } else { u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 deadzone = 0; - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][1]; + if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE) { + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET) { + deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][1]; } buffer->leftStick.x += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT][1], - deadzone); + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][0], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT][1], + deadzone); } - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE) { deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][1]; + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET) { + deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][1]; } buffer->leftStick.y += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT][1], - deadzone); + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][0], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT][1], + deadzone); } - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE) { deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][1]; + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET) { + deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][1]; } buffer->rightStick.x += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT][1], - deadzone); + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][0], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT][1], + deadzone); } - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE) { deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][1]; + if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET) { + deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][1]; } buffer->rightStick.y += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT][1], - deadzone); + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][0], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][1], + config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT][1], + deadzone); } u8 stick_values = 0; - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_UP)){ stick_values |= STICK_VALUE_UP; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_DOWN)){ stick_values |= STICK_VALUE_DOWN; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_LEFT)){ stick_values |= STICK_VALUE_LEFT; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_RIGHT)){ stick_values |= STICK_VALUE_RIGHT; } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_UP)) { + stick_values |= STICK_VALUE_UP; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_DOWN)) { + stick_values |= STICK_VALUE_DOWN; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_LEFT)) { + stick_values |= STICK_VALUE_LEFT; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_RIGHT)) { + stick_values |= STICK_VALUE_RIGHT; + } - if(stick_values > 0 ){ + if(stick_values > 0 ) { VPADVec2D stick = getAnalogValueByButtons(stick_values); buffer->leftStick.x += stick.x; buffer->leftStick.y += stick.y; } stick_values = 0; - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_UP)){ stick_values |= STICK_VALUE_UP; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_DOWN)){ stick_values |= STICK_VALUE_DOWN; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_LEFT)){ stick_values |= STICK_VALUE_LEFT; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_RIGHT)){ stick_values |= STICK_VALUE_RIGHT; } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_UP)) { + stick_values |= STICK_VALUE_UP; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_DOWN)) { + stick_values |= STICK_VALUE_DOWN; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_LEFT)) { + stick_values |= STICK_VALUE_LEFT; + } + if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_RIGHT)) { + stick_values |= STICK_VALUE_RIGHT; + } - if(stick_values > 0 ){ + if(stick_values > 0 ) { VPADVec2D stick = getAnalogValueByButtons(stick_values); buffer->rightStick.x += stick.x; buffer->rightStick.y += stick.y; } - if(config_controller[deviceslot][CONTRPS_VPAD_STICK_L_COPY_DPAD][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_VPAD_STICK_L_COPY_DPAD][0] == 1){ + if(config_controller[deviceslot][CONTRPS_VPAD_STICK_L_COPY_DPAD][0] != CONTROLLER_PATCHER_INVALIDVALUE) { + if(config_controller[deviceslot][CONTRPS_VPAD_STICK_L_COPY_DPAD][0] == 1) { u8 stick_values = 0; - if(buffer->hold & VPAD_BUTTON_UP){ stick_values |= STICK_VALUE_UP; } - if(buffer->hold & VPAD_BUTTON_DOWN){ stick_values |= STICK_VALUE_DOWN; } - if(buffer->hold & VPAD_BUTTON_LEFT){ stick_values |= STICK_VALUE_LEFT; } - if(buffer->hold & VPAD_BUTTON_RIGHT){ stick_values |= STICK_VALUE_RIGHT; } + if(buffer->hold & VPAD_BUTTON_UP) { + stick_values |= STICK_VALUE_UP; + } + if(buffer->hold & VPAD_BUTTON_DOWN) { + stick_values |= STICK_VALUE_DOWN; + } + if(buffer->hold & VPAD_BUTTON_LEFT) { + stick_values |= STICK_VALUE_LEFT; + } + if(buffer->hold & VPAD_BUTTON_RIGHT) { + stick_values |= STICK_VALUE_RIGHT; + } - if(stick_values > 0 ){ + if(stick_values > 0 ) { VPADVec2D stick = getAnalogValueByButtons(stick_values); buffer->leftStick.x += stick.x; buffer->leftStick.y += stick.y; } } } - if(config_controller[deviceslot][CONTRPS_VPAD_STICK_R_COPY_DPAD][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_VPAD_STICK_R_COPY_DPAD][0] == 1){ + if(config_controller[deviceslot][CONTRPS_VPAD_STICK_R_COPY_DPAD][0] != CONTROLLER_PATCHER_INVALIDVALUE) { + if(config_controller[deviceslot][CONTRPS_VPAD_STICK_R_COPY_DPAD][0] == 1) { u8 stick_values = 0; - if(buffer->hold & VPAD_BUTTON_UP){ stick_values |= STICK_VALUE_UP; } - if(buffer->hold & VPAD_BUTTON_DOWN){ stick_values |= STICK_VALUE_DOWN; } - if(buffer->hold & VPAD_BUTTON_LEFT){ stick_values |= STICK_VALUE_LEFT; } - if(buffer->hold & VPAD_BUTTON_RIGHT){ stick_values |= STICK_VALUE_RIGHT; } + if(buffer->hold & VPAD_BUTTON_UP) { + stick_values |= STICK_VALUE_UP; + } + if(buffer->hold & VPAD_BUTTON_DOWN) { + stick_values |= STICK_VALUE_DOWN; + } + if(buffer->hold & VPAD_BUTTON_LEFT) { + stick_values |= STICK_VALUE_LEFT; + } + if(buffer->hold & VPAD_BUTTON_RIGHT) { + stick_values |= STICK_VALUE_RIGHT; + } - if(stick_values > 0 ){ + if(stick_values > 0 ) { VPADVec2D stick = getAnalogValueByButtons(stick_values); buffer->rightStick.x += stick.x; buffer->rightStick.y += stick.y; @@ -563,7 +641,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks) { if(buffer == NULL || last_emulatedSticks == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; u32 emulatedSticks = 0; @@ -573,29 +651,29 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA s32 r_x_full = (buffer->rightStick.x > 0.5f || buffer->rightStick.x < -0.5f)? 1:0; s32 r_y_full = (buffer->rightStick.y > 0.5f || buffer->rightStick.y < -0.5f)? 1:0; - if((buffer->leftStick.x > 0.5f) || (buffer->leftStick.x > 0.1f && !l_y_full)){ + if((buffer->leftStick.x > 0.5f) || (buffer->leftStick.x > 0.1f && !l_y_full)) { emulatedSticks |= VPAD_STICK_L_EMULATION_RIGHT; } - if((buffer->leftStick.x < -0.5f) || (buffer->leftStick.x < -0.1f && !l_y_full)){ + if((buffer->leftStick.x < -0.5f) || (buffer->leftStick.x < -0.1f && !l_y_full)) { emulatedSticks |= VPAD_STICK_L_EMULATION_LEFT; } - if((buffer->leftStick.y > 0.5f) || (buffer->leftStick.y > 0.1f && !l_x_full)){ + if((buffer->leftStick.y > 0.5f) || (buffer->leftStick.y > 0.1f && !l_x_full)) { emulatedSticks |= VPAD_STICK_L_EMULATION_UP; } - if((buffer->leftStick.y < -0.5f) || (buffer->leftStick.y < -0.1f && !l_x_full)){ + if((buffer->leftStick.y < -0.5f) || (buffer->leftStick.y < -0.1f && !l_x_full)) { emulatedSticks |= VPAD_STICK_L_EMULATION_DOWN; } - if((buffer->rightStick.x > 0.5f) || (buffer->rightStick.x > 0.1f && !r_y_full)){ + if((buffer->rightStick.x > 0.5f) || (buffer->rightStick.x > 0.1f && !r_y_full)) { emulatedSticks |= VPAD_STICK_R_EMULATION_RIGHT; } - if((buffer->rightStick.x < -0.5f) || (buffer->rightStick.x < -0.1f && !r_y_full)){ + if((buffer->rightStick.x < -0.5f) || (buffer->rightStick.x < -0.1f && !r_y_full)) { emulatedSticks |= VPAD_STICK_R_EMULATION_LEFT; } - if((buffer->rightStick.y > 0.5f) || (buffer->rightStick.y > 0.1f && !r_x_full)){ + if((buffer->rightStick.y > 0.5f) || (buffer->rightStick.y > 0.1f && !r_x_full)) { emulatedSticks |= VPAD_STICK_R_EMULATION_UP; } - if((buffer->rightStick.y < -0.5f) || (buffer->rightStick.y < -0.1f && !r_x_full)){ + if((buffer->rightStick.y < -0.5f) || (buffer->rightStick.y < -0.1f && !r_x_full)) { emulatedSticks |= VPAD_STICK_R_EMULATION_DOWN; } @@ -613,49 +691,49 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA * Touch functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADStatus * buffer){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADStatus * buffer) { if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ + if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH) { s32 buttons_hold; - if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){ - HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; - if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - s32 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f)); - s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f)); - buffer->tpNormal.x = x_mouse; - buffer->tpNormal.y = y_mouse; - buffer->tpNormal.touched = 1; - buffer->tpNormal.validity = 0; - buffer->tpFiltered1.x = x_mouse; - buffer->tpFiltered1.y = y_mouse; - buffer->tpFiltered1.touched = 1; - buffer->tpFiltered1.validity = 0; - buffer->tpFiltered2.x = x_mouse; - buffer->tpFiltered2.y = y_mouse; - buffer->tpFiltered2.touched = 1; - buffer->tpFiltered2.validity = 0; + if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)) { + HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; + if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; + s32 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f)); + s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f)); + buffer->tpNormal.x = x_mouse; + buffer->tpNormal.y = y_mouse; + buffer->tpNormal.touched = 1; + buffer->tpNormal.validity = 0; + buffer->tpFiltered1.x = x_mouse; + buffer->tpFiltered1.y = y_mouse; + buffer->tpFiltered1.touched = 1; + buffer->tpFiltered1.validity = 0; + buffer->tpFiltered2.x = x_mouse; + buffer->tpFiltered2.y = y_mouse; + buffer->tpFiltered2.touched = 1; + buffer->tpFiltered2.validity = 0; } } return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data) { u32 hidmask = data->slotdata.hidmask; - if(hidmask & gHID_LIST_KEYBOARD){ + if(hidmask & gHID_LIST_KEYBOARD) { u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * last_data = &data->data_union.controller.last_hid_data[0]; - if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0)) && gMouseModeCoolDown == 0){ + if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0)) && gMouseModeCoolDown == 0) { gMouseModeCoolDown = 60; - if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ + if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM) { gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; //log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to touch \n",__LINE__); - }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ + } else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH) { //log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to aim \n",__LINE__); gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; } } - if(gMouseModeCoolDown > 0){ + if(gMouseModeCoolDown > 0) { gMouseModeCoolDown--; } } @@ -666,7 +744,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode( * Other functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesPRO){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesPRO) { if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesPRO == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 buttons_hold = 0; @@ -734,7 +812,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADSt return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRead(VPADStatus * vpad_buffer,WPADStatusProController * pro_buffer){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRead(VPADStatus * vpad_buffer,WPADStatusProController * pro_buffer) { if(vpad_buffer == NULL || pro_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 buttons_hold = 0; @@ -786,7 +864,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRea return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesVPAD){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesVPAD) { if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesVPAD == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; s32 buttons_hold = 0; @@ -840,42 +918,42 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADS return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkValueinConfigController(s32 deviceslot,s32 CONTRPS_slot,s32 expectedValue){ - if(config_controller[deviceslot][CONTRPS_slot][0] != CONTROLLER_PATCHER_INVALIDVALUE){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkValueinConfigController(s32 deviceslot,s32 CONTRPS_slot,s32 expectedValue) { + if(config_controller[deviceslot][CONTRPS_slot][0] != CONTROLLER_PATCHER_INVALIDVALUE) { if(expectedValue == config_controller[deviceslot][CONTRPS_slot][1]) return 1; } return 0; } -void ControllerPatcherUtils::setConfigValue(u8 * dest, u8 first, u8 second){ +void ControllerPatcherUtils::setConfigValue(u8 * dest, u8 first, u8 second) { dest[0] = first; dest[1] = second; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(u32 hidmask){ - for(s32 i = 0;i < gHIDMaxDevices;i++){ - if(hidmask & config_controller_hidmask[i]){ - return i; +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(u32 hidmask) { + for(s32 i = 0; i < gHIDMaxDevices; i++) { + if(hidmask & config_controller_hidmask[i]) { + return i; } } return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidPid(DeviceInfo * info){ - if(info != NULL){ - for(s32 i = 0;i< gHIDMaxDevices;i++){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidPid(DeviceInfo * info) { + if(info != NULL) { + for(s32 i = 0; i< gHIDMaxDevices; i++) { u16 my_vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1]; u16 my_pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1]; //log_printf("info->vidpid.vid (%04X) == my_vid (%04X) && info->vidpid.pid (%04X) == my_pid (%04X)\n",info->vidpid.vid,my_vid,info->vidpid.pid,my_pid); - if(info->vidpid.vid == my_vid && info->vidpid.pid == my_pid){ + if(info->vidpid.vid == my_vid && info->vidpid.pid == my_pid) { info->slotdata.hidmask = config_controller_hidmask[i]; info->slotdata.deviceslot = i; info->pad_count = 1; - if(config_controller[i][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - info->pad_count = config_controller[i][CONTRPS_PAD_COUNT][1]; - if(info->pad_count > HID_MAX_PADS_COUNT){ + if(config_controller[i][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { + info->pad_count = config_controller[i][CONTRPS_PAD_COUNT][1]; + if(info->pad_count > HID_MAX_PADS_COUNT) { info->pad_count = HID_MAX_PADS_COUNT; - } + } } return CONTROLLER_PATCHER_ERROR_NONE; @@ -888,7 +966,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidP return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSlotData * slotdata){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSlotData * slotdata) { if(slotdata == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(gHIDRegisteredDevices >= gHIDMaxDevices) return CONTROLLER_PATCHER_ERROR_NO_FREE_SLOT; slotdata->deviceslot = gHIDRegisteredDevices; @@ -898,7 +976,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSl return CONTROLLER_PATCHER_ERROR_NONE; } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid){ +CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid) { if(vidpid == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; if(deviceslot >= gHIDMaxDevices || deviceslot < 0) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; vidpid->vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1]; @@ -907,16 +985,16 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot return CONTROLLER_PATCHER_ERROR_NONE; } -s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data){ +s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data) { s32 slot_incr = 0; - if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { s32 pad_count = config_controller[deviceslot][CONTRPS_PAD_COUNT][1]; - if(pad_count > HID_MAX_PADS_COUNT){ + if(pad_count > HID_MAX_PADS_COUNT) { pad_count = HID_MAX_PADS_COUNT; } - for(s32 i= 0;iactive){ + if(padinfo->active) { DeviceInfo device_info; memset(&device_info,0,sizeof(device_info)); device_info.vidpid = padinfo->vidpid; s32 res = -1; - if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) >= 0){ - if(!ignorePadSlot){ + if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) >= 0) { + if(!ignorePadSlot) { s32 real_pad = (padinfo->pad/(device_info.pad_count))*device_info.pad_count; - if(real_pad == padslot && device_info.slotdata.deviceslot == deviceslot){ - if(ControllerPatcherUtils::checkActivePad(device_info.slotdata.hidmask,padinfo->pad)){ + if(real_pad == padslot && device_info.slotdata.deviceslot == deviceslot) { + if(ControllerPatcherUtils::checkActivePad(device_info.slotdata.hidmask,padinfo->pad)) { gSamplingCallback(chan); } } - }else{ + } else { gSamplingCallback(chan); } } diff --git a/source/patcher/ControllerPatcherUtils.hpp b/source/patcher/ControllerPatcherUtils.hpp index 8f24fd3..1a8cd5b 100644 --- a/source/patcher/ControllerPatcherUtils.hpp +++ b/source/patcher/ControllerPatcherUtils.hpp @@ -32,290 +32,290 @@ #include "../ControllerPatcherIncludes.hpp" -class ControllerPatcherUtils{ +class ControllerPatcherUtils { //give the other classes access to the private functions. friend class ControllerPatcher; friend class ControllerPatcherHID; friend class ConfigParser; - public: - /** - \brief Returns the device slot for a given HID-Mask. +public: + /** + \brief Returns the device slot for a given HID-Mask. - \param hidmask Given HID-Mask + \param hidmask Given HID-Mask - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is the deviceslot of the given HID-Mask - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceSlot(u32 hidmask); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is the deviceslot of the given HID-Mask + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceSlot(u32 hidmask); - /** - \brief Returns the device slot for a given HID-Mask. + /** + \brief Returns the device slot for a given HID-Mask. - \param handle Given HID-handle - \param data Given my_cb_user ** where the result will be stored. Valid pointer when result is >= 0. + \param handle Given HID-handle + \param data Given my_cb_user ** where the result will be stored. Valid pointer when result is >= 0. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given my_cb_user **. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDataByHandle(s32 handle, my_cb_user ** data); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given my_cb_user **. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getDataByHandle(s32 handle, my_cb_user ** data); - /** - \brief Returns the VID/PID for the given device slot. + /** + \brief Returns the VID/PID for the given device slot. - \param deviceslot Given device slot - \param vidpid Pointer to the DeviceVIDPIDInfo struct where the result will be stored. + \param deviceslot Given device slot + \param vidpid Pointer to the DeviceVIDPIDInfo struct where the result will be stored. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given DeviceVIDPIDInfo *. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given DeviceVIDPIDInfo *. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid); - /** \brief Set the VPAD data for a given KPAD data. - * - * \param vpad_buffer VPADStatus* A pointer to the VPAD Data where the result will be stored. - * \param pro_buffer KPADData* A pointer to the given KPADData data. - * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToVPAD(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesVPAD); - private: + /** \brief Set the VPAD data for a given KPAD data. + * + * \param vpad_buffer VPADStatus* A pointer to the VPAD Data where the result will be stored. + * \param pro_buffer KPADData* A pointer to the given KPADData data. + * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. + * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToVPAD(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesVPAD); +private: /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Analyse inputs *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** \brief Checks if a the given @p VPADButton was pressed in the given HID @data. When it was pressed, the result will be set the in given @p buttons_hold - * - * \param data Pointer to the HID_Data from where the input is read. - * \param buttons_hold Pointer to the u32 where the result will be written to. - * \param VPADButton The button that will be checked - * \return When the functions failed result < 0 is returned.If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton); + /** \brief Checks if a the given @p VPADButton was pressed in the given HID @data. When it was pressed, the result will be set the in given @p buttons_hold + * + * \param data Pointer to the HID_Data from where the input is read. + * \param buttons_hold Pointer to the u32 where the result will be written to. + * \param VPADButton The button that will be checked + * \return When the functions failed result < 0 is returned.If the result is >= 0 the function was successful. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton); - /** \brief Checks if a given value is set in the HID_DATA given the data in the slot number provided by cur_config. - * - * \param data Pointer to the HID_Data from where the input is read. - * \param cur_config slot of the configuration array which will be checked. - * \return When the functions failed result < 0 is returned. If the value is set, 1 will be returned. Otherwise 0. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR isValueSet(HID_Data * data,s32 cur_config); + /** \brief Checks if a given value is set in the HID_DATA given the data in the slot number provided by cur_config. + * + * \param data Pointer to the HID_Data from where the input is read. + * \param cur_config slot of the configuration array which will be checked. + * \return When the functions failed result < 0 is returned. If the value is set, 1 will be returned. Otherwise 0. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR isValueSet(HID_Data * data,s32 cur_config); - /** \brief Checks if a given key in the keyboard data is pressed. - * - * \param keyboardData A pointer to the keyboard data. - * \param key A pointer to the keyboard data. - * \return When the functions failed result < 0 is returned. If the key is active pressed, 1 is returned. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR isInKeyboardData(unsigned char * keyboardData,s32 key); + /** \brief Checks if a given key in the keyboard data is pressed. + * + * \param keyboardData A pointer to the keyboard data. + * \param key A pointer to the keyboard data. + * \return When the functions failed result < 0 is returned. If the key is active pressed, 1 is returned. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR isInKeyboardData(unsigned char * keyboardData,s32 key); /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Utils for setting the Button data *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** \brief Checks if a @p VPADButton (VPAD_BUTTON_XXX) is set in the given @p CONTRPS_SLOT (usually the one for buttons remapping) of the GamePad. When its set it'll be - * set for the corresponding Button (aka button remapping). When the @p CONTRPS_SLOT is not valid, the normal buttons layout will be used. - * - * \param old_buffer A pointer to a VPADStatus struct from which will be read. - * \param new_buffer A pointer to a VPADStatus struct where the result will be written. - * \param VPADButton The buttons that will be may replaced - * \param CONTRPS_SLOT The CONTRPS_SLOT where the VPAD_Buttons we want to use instead of the parameter "VPADButton" could be saved. - * \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT); + /** \brief Checks if a @p VPADButton (VPAD_BUTTON_XXX) is set in the given @p CONTRPS_SLOT (usually the one for buttons remapping) of the GamePad. When its set it'll be + * set for the corresponding Button (aka button remapping). When the @p CONTRPS_SLOT is not valid, the normal buttons layout will be used. + * + * \param old_buffer A pointer to a VPADStatus struct from which will be read. + * \param new_buffer A pointer to a VPADStatus struct where the result will be written. + * \param VPADButton The buttons that will be may replaced + * \param CONTRPS_SLOT The CONTRPS_SLOT where the VPAD_Buttons we want to use instead of the parameter "VPADButton" could be saved. + * \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT); - /** - \brief Checks if a given button (oldVPADButton) is set in a given VPADStatus struct (old_buffer). If its set, it will set an other - button (newVPADButton) to the second given VPADStatus struct (new_buffer) + /** + \brief Checks if a given button (oldVPADButton) is set in a given VPADStatus struct (old_buffer). If its set, it will set an other + button (newVPADButton) to the second given VPADStatus struct (new_buffer) - \param old_buffer A pointer to a VPADStatus struct from which will be read. - \param new_buffer A pointer to a VPADStatus struct where the result will be written. - \param oldVPADButton The buttons that need to be set in the first VPADStatus - \param newVPADButton The buttons that will be set in the second VPADStatus, when the oldVPADButton is pressed in the first buffer. + \param old_buffer A pointer to a VPADStatus struct from which will be read. + \param new_buffer A pointer to a VPADStatus struct where the result will be written. + \param oldVPADButton The buttons that need to be set in the first VPADStatus + \param newVPADButton The buttons that will be set in the second VPADStatus, when the oldVPADButton is pressed in the first buffer. - \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton); + \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton); /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Pad Status functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Checks if a controller is attached for the given HID-Mask and pad. + /** + \brief Checks if a controller is attached for the given HID-Mask and pad. - \param hidmask Bit-Mask of the target hid-device. - \param pad Defines for which pad the connection will be checked. + \param hidmask Bit-Mask of the target hid-device. + \param pad Defines for which pad the connection will be checked. - \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkActivePad(u32 hidmask,s32 pad); + \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR checkActivePad(u32 hidmask,s32 pad); - /** - \brief Returns the first active pad of devices with the given HID-Mask. Currently only implemented for the GC-Adapter. Every other pad will always return 0. + /** + \brief Returns the first active pad of devices with the given HID-Mask. Currently only implemented for the GC-Adapter. Every other pad will always return 0. - \param hidmask Bit-Mask of the target hid-device. + \param hidmask Bit-Mask of the target hid-device. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is fist active pad. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(u32 hidmask); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is fist active pad. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(u32 hidmask); /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Stick functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Normalizes the stick to valid values. + /** + \brief Normalizes the stick to valid values. - \param stick Pointer to the stick that will be normalized + \param stick Pointer to the stick that will be normalized - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR normalizeStickValues(VPADVec2D * stick); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR normalizeStickValues(VPADVec2D * stick); - /** - \brief Converts the digital absolute stick data into a float value. It also applies the deadzones, and can invert the result. + /** + \brief Converts the digital absolute stick data into a float value. It also applies the deadzones, and can invert the result. - \param value Given current value of the stick axis - \param default_val Value in neutral axis-position - \param min Value that represents -1.0f - \param max Value that represents 1.0f - \param invert Set to 1 if the axis needs to be inverted - \param deadzone Deadzone + \param value Given current value of the stick axis + \param default_val Value in neutral axis-position + \param min Value that represents -1.0f + \param max Value that represents 1.0f + \param invert Set to 1 if the axis needs to be inverted + \param deadzone Deadzone - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static f32 convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static f32 convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone); - /** - \brief Calculates a the stick data (VPADVec2D) from given digital direction. + /** + \brief Calculates a the stick data (VPADVec2D) from given digital direction. - \param stick_values bits need to set for each direction. (STICK_VALUE_UP,STICK_VALUE_DOWN,STICK_VALUE_LEFT,STICK_VALUE_RIGHT) + \param stick_values bits need to set for each direction. (STICK_VALUE_UP,STICK_VALUE_DOWN,STICK_VALUE_LEFT,STICK_VALUE_RIGHT) - \return The VPADVec2D with the set values. - **/ - static VPADVec2D getAnalogValueByButtons(u8 stick_values); + \return The VPADVec2D with the set values. + **/ + static VPADVec2D getAnalogValueByButtons(u8 stick_values); - /** - \brief Handles the analog-stick data of HID devices. The result will written in the VPADStatus buffer. + /** + \brief Handles the analog-stick data of HID devices. The result will written in the VPADStatus buffer. - \param data Pointer to the current data of the HID device - \param buffer Pointer to VPADStatus where the analog-stick data will be set. + \param data Pointer to the current data of the HID device + \param buffer Pointer to VPADStatus where the analog-stick data will be set. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR convertAnalogSticks(HID_Data * data,VPADStatus * buffer); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR convertAnalogSticks(HID_Data * data,VPADStatus * buffer); /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Mouse functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Set the touch data in the VPADStatus buffer. - Currently its only possible to set the touch data from a Mouse + /** + \brief Set the touch data in the VPADStatus buffer. + Currently its only possible to set the touch data from a Mouse - \param data The current data of the HID device - \param buffer Pointer to VPADStatus where the touch data will be set. + \param data The current data of the HID device + \param buffer Pointer to VPADStatus where the touch data will be set. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setTouch(HID_Data * data,VPADStatus * buffer); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR setTouch(HID_Data * data,VPADStatus * buffer); - /** \brief Checks if the mouse mode needs to be changed. Sets it to the new mode if necessary. - * Currently the incoming data needs to be from a keyboard. - * - * \param data HID_Data* Pointer to the current data - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkAndSetMouseMode(HID_Data * data); + /** \brief Checks if the mouse mode needs to be changed. Sets it to the new mode if necessary. + * Currently the incoming data needs to be from a keyboard. + * + * \param data HID_Data* Pointer to the current data + * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR checkAndSetMouseMode(HID_Data * data); - /** - \brief Set the emulated sticks for a given VPAD data. + /** + \brief Set the emulated sticks for a given VPAD data. - \param buffer: A pointer to the given VPAD Data. - \param last_emulatedSticks: A pointer to the button presses of the previous call. Will be updated while calling. + \param buffer: A pointer to the given VPAD Data. + \param last_emulatedSticks: A pointer to the button presses of the previous call. Will be updated while calling. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks); /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Other functions *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** \brief Set the Pro Controller for a given VPAD data. - * - * \param vpad_buffer VPADStatus* A pointer to the given VPAD Data. - * \param pro_buffer KPADData* A pointer to the KPADData where the result will be stored. - * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToPro(VPADStatus * vpad_buffer, KPADStatus * pro_buffer, u32 * lastButtonsPressesPRO); - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToProWPADRead(VPADStatus * vpad_buffer,WPADStatusProController * pro_buffer); + /** \brief Set the Pro Controller for a given VPAD data. + * + * \param vpad_buffer VPADStatus* A pointer to the given VPAD Data. + * \param pro_buffer KPADData* A pointer to the KPADData where the result will be stored. + * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. + * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + * + */ + static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToPro(VPADStatus * vpad_buffer, KPADStatus * pro_buffer, u32 * lastButtonsPressesPRO); + static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToProWPADRead(VPADStatus * vpad_buffer,WPADStatusProController * pro_buffer); - /** - \brief Checks if the value at the given device + CONTRPS slot equals the expected value. + /** + \brief Checks if the value at the given device + CONTRPS slot equals the expected value. - \param device_slot - \param CONTRPS_slot - \param expectedValue + \param device_slot + \param CONTRPS_slot + \param expectedValue - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkValueinConfigController(s32 device_slot,s32 CONTRPS_slot,s32 expectedValue); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR checkValueinConfigController(s32 device_slot,s32 CONTRPS_slot,s32 expectedValue); - /** - \brief Sets two u8 values to the given pointer. + /** + \brief Sets two u8 values to the given pointer. - \param dest: pointer to the destination array. - \param first: Value that will be written in @p dest[0] - \param second: Value that will be written in @p dest[1] - **/ - static void setConfigValue(u8 * dest , u8 first, u8 second); + \param dest: pointer to the destination array. + \param first: Value that will be written in @p dest[0] + \param second: Value that will be written in @p dest[1] + **/ + static void setConfigValue(u8 * dest , u8 first, u8 second); - /** - \brief Saves a new free device slot and the corresponding HID-Mask in the given @p HIDSlotData pointer + /** + \brief Saves a new free device slot and the corresponding HID-Mask in the given @p HIDSlotData pointer - \param slotdata Pointer to the HIDSlotData struct where the result will be saved. + \param slotdata Pointer to the HIDSlotData struct where the result will be saved. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getNextSlotData(HIDSlotData * slotdata); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getNextSlotData(HIDSlotData * slotdata); - /** - \brief Fills up a given DeviceInfo, which provides a valid VID/PID, with HIDSlotData. + /** + \brief Fills up a given DeviceInfo, which provides a valid VID/PID, with HIDSlotData. - \param info Pointer the target DeviceInfo. The VID/PID need to be set, the HIDSlotData will be filled with data. + \param info Pointer the target DeviceInfo. The VID/PID need to be set, the HIDSlotData will be filled with data. - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceInfoFromVidPid(DeviceInfo * info); + \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. + **/ + static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceInfoFromVidPid(DeviceInfo * info); - /** - \brief returns the internal slot number of the device. Some adapters have multiple slot and send the data for each one - alternating (with an identifier at the beginning). This function searches for the identifier (if it's set) and returns the - slot number relative to this pad. + /** + \brief returns the internal slot number of the device. Some adapters have multiple slot and send the data for each one + alternating (with an identifier at the beginning). This function searches for the identifier (if it's set) and returns the + slot number relative to this pad. - \param device slot - \param current input data - \return The relative slot in the device - **/ - static s32 getPadSlotInAdapter(s32 deviceslot, u8 * input_data); + \param device slot + \param current input data + \return The relative slot in the device + **/ + static s32 getPadSlotInAdapter(s32 deviceslot, u8 * input_data); - /** - \brief returns a pointer to the ControllerMapping to the given controller type + /** + \brief returns a pointer to the ControllerMapping to the given controller type - \param type controller type + \param type controller type - \return pointer to ControllerMapping data, null is type was invalid - **/ - static ControllerMappingPAD * getControllerMappingByType(UController_Type type); + \return pointer to ControllerMapping data, null is type was invalid + **/ + static ControllerMappingPAD * getControllerMappingByType(UController_Type type); - static CONTROLLER_PATCHER_RESULT_OR_ERROR doSampling(u16 deviceslot,u8 padslot,bool ignorePadSlot); + static CONTROLLER_PATCHER_RESULT_OR_ERROR doSampling(u16 deviceslot,u8 padslot,bool ignorePadSlot); - static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingSingle(WPADChan chan, u16 deviceslot, u8 padslot, bool ignorePadSlot); + static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingSingle(WPADChan chan, u16 deviceslot, u8 padslot, bool ignorePadSlot); }; #endif /* _CONTROLLER_PATCHER_UTIL_H_ */ diff --git a/source/utils/CPRetainVars.cpp b/source/utils/CPRetainVars.cpp index 32716ee..4dd43f3 100644 --- a/source/utils/CPRetainVars.cpp +++ b/source/utils/CPRetainVars.cpp @@ -70,6 +70,7 @@ u8 gGlobalRumbleActivated __attribute__((section(".data"))) = 0; u32 gUDPClientip __attribute__((section(".data"))) = 0; ControllerMappingPADInfo* gProPadInfo[4] __attribute__((section(".data"))) = {&gControllerMapping.proController[0].pad_infos[0], - &gControllerMapping.proController[1].pad_infos[0], - &gControllerMapping.proController[2].pad_infos[0], - &gControllerMapping.proController[3].pad_infos[0]} ; + &gControllerMapping.proController[1].pad_infos[0], + &gControllerMapping.proController[2].pad_infos[0], + &gControllerMapping.proController[3].pad_infos[0] + } ; diff --git a/source/utils/PadConst.cpp b/source/utils/PadConst.cpp index efbcc9a..830d808 100644 --- a/source/utils/PadConst.cpp +++ b/source/utils/PadConst.cpp @@ -58,36 +58,40 @@ const uint8_t HID_GC_BUTTON_R[] = { 0x08,HID_GC_BUTTON_R_VALUE}; const uint8_t HID_GC_BUTTON_DPAD_TYPE[] = { CONTRPDM_Normal,0x00}; const uint8_t HID_GC_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x03, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x09, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x1A, //STICK_CONF_MIN, - 0xE4};//STICK_CONF_MAX, + 0x03, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x1A, //STICK_CONF_MIN, + 0xE4 + };//STICK_CONF_MAX, const uint8_t HID_GC_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x04, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x09, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x11, //STICK_CONF_MIN, - 0xE1};//STICK_CONF_MAX, + 0x04, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x11, //STICK_CONF_MIN, + 0xE1 + };//STICK_CONF_MAX, const uint8_t HID_GC_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x05, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x09, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x2B, //STICK_CONF_MIN, - 0xE2};//STICK_CONF_MAX, + 0x05, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x2B, //STICK_CONF_MIN, + 0xE2 + };//STICK_CONF_MAX, const uint8_t HID_GC_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x06, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x09, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x1D, //STICK_CONF_MIN, - 0xDB};//STICK_CONF_MAX, + 0x06, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x1D, //STICK_CONF_MIN, + 0xDB + };//STICK_CONF_MAX, //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! DS3 @@ -117,36 +121,40 @@ const uint8_t HID_DS3_BUTTON_GUIDE[] = { 0x04,HID_DS3_BUTTON_GUIDE_VALUE}; const uint8_t HID_DS3_BUTTON_DPAD_TYPE[] = { CONTRPDM_Normal,0x00}; const uint8_t HID_DS3_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x06, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x06, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS3_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x07, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x07, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS3_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x08, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x08, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS3_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x09, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x09, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! DS4 @@ -184,36 +192,40 @@ const uint8_t HID_DS4_BUTTON_GUIDE[] = { 0x07,HID_DS4_BUTTON_GUIDE_VALU const uint8_t HID_DS4_BUTTON_T_PAD_CLICK[] = { 0x07,HID_DS4_BUTTON_T_PAD_CLICK_VALUE}; const uint8_t HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x01, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x01, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x02, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x05, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x02, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x05, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x03, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x07, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x03, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x07, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_DS4_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x04, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x09, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x04, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! XInput @@ -243,36 +255,40 @@ const uint8_t HID_XINPUT_BUTTON_DOWN[] = { 0x07,HID_XINPUT_BUTTON_DOWN_VAL const uint8_t HID_XINPUT_BUTTON_UP[] = { 0x07,HID_XINPUT_BUTTON_UP_VALUE}; const uint8_t HID_XINPUT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x00, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x00, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x10, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_XINPUT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x01, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x01, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x10, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_XINPUT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x02, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x02, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x10, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, const uint8_t HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x03, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, + 0x03, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x10, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF + };//STICK_CONF_MAX, @@ -310,33 +326,37 @@ const uint8_t HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[] = { 0x02,HID_SWITCH_PRO_B const uint8_t 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, + 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 uint8_t 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, + 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 uint8_t 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, + 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 uint8_t 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, + 0x0A, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x08, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x22, //STICK_CONF_MIN, + 0xE4 + };//STICK_CONF_MAX,