Format the files

This commit is contained in:
Maschell 2018-06-19 17:46:37 +02:00
parent a1ae51e073
commit c2e273f46f
17 changed files with 1551 additions and 1315 deletions

View File

@ -15,14 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
/**
* @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,8 +33,8 @@
#include <vpad/input.h>
#include "ControllerPatcherDefs.h"
class ControllerPatcher{
public:
class ControllerPatcher {
public:
/*-----------------------------------------------------------------------------------------------------------------------------------
* Initialization
*----------------------------------------------------------------------------------------------------------------------------------*/

View File

@ -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,15 +217,15 @@ enum Controller_Patcher_DPAD_Settings
/**
* @brief Stores data if the Slot the device is using in gHID_Devices
*/
typedef struct _HIDSlotData{
typedef struct _HIDSlotData {
u16 deviceslot; /**< deviceslot number */
u32 hidmask; /**< Used HID-Mask */
}HIDSlotData;
} HIDSlotData;
/**
* @brief Struct where the data for the callback funtion is stored
*/
typedef struct _my_cb_user{
typedef struct _my_cb_user {
u8 *buf; /**< pointer the buffer that is used */
u32 transfersize; /**< number of transfered data */
u32 handle; /**< HID handle */
@ -238,7 +234,7 @@ typedef struct _my_cb_user{
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;
} 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{
typedef struct _DeviceVIDPIDInfo {
u16 vid; /**< Vendor ID of this device */
u16 pid; /**< Product ID of this device */
}DeviceVIDPIDInfo;
} DeviceVIDPIDInfo;
/**
* @brief Infos of the device
*/
typedef struct _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;
} 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,

View File

@ -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<std::string> 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<std::string> ConfigReader::ScanFolder(std::string path){
std::vector<std::string> ConfigReader::ScanFolder(std::string path) {
std::vector<std::string> config_files;
struct dirent *dirent = NULL;
DIR *dirHandle = opendir(path.c_str());
if (dirHandle == NULL){
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){
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<std::string> path){
void ConfigReader::processFileList(std::vector<std::string> path) {
for(std::vector<std::string>::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<std::string> 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,' ');

View File

@ -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;
@ -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;i<HID_MAX_DEVICES_PER_SLOT;i++){
for(s32 i=0; i<HID_MAX_DEVICES_PER_SLOT; i++) {
ControllerMappingPADInfo * info = &(cm_map_pad->pad_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;i<HID_MAX_DEVICES_PER_SLOT;i++){
if(cm_map_pad->pad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController){
for(s32 i =0; i<HID_MAX_DEVICES_PER_SLOT; i++) {
if(cm_map_pad->pad_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;
}
@ -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;i<HID_MAX_DEVICES_PER_SLOT;i++){
for(s32 i = 0; i<HID_MAX_DEVICES_PER_SLOT; i++) {
ControllerMappingPADInfo * padinfo = &(CMPAD->pad_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,14 +828,14 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp
s32 buttons_hold = 0;
for(s32 pad = 0;pad<HID_MAX_PADS_COUNT;pad++){
for(s32 pad = 0; pad<HID_MAX_PADS_COUNT; pad++) {
buttons_hold = 0;
buttondata[pad].btn_h = 0;
buttondata[pad].btn_d = 0;
buttondata[pad].btn_r = 0;
s32 res;
if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0){
if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0) {
continue;
}
@ -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<HID_Data *> data_list;
for(s32 i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){
for(s32 i = 0; i<HID_MAX_DEVICES_PER_SLOT; i++) {
ControllerMappingPADInfo cm_map_pad_info = gControllerMapping.proController[chan].pad_infos[i];
if(!cm_map_pad_info.active){
if(!cm_map_pad_info.active) {
continue;
}
DeviceInfo device_info;
@ -858,7 +899,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
device_info.vidpid = cm_map_pad_info.vidpid;
s32 res;
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){
if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0) {
DEBUG_FUNCTION_LINE("ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) = %d\n",res);
continue;
}
@ -875,7 +916,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
data_list.push_back(data_cur);
}
if(data_list.empty()){
if(data_list.empty()) {
return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA;
}
s32 res = 0;
@ -884,7 +925,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
//ControllerPatcher::printVPADButtons(vpad_buffer); //Leads to random crashes on transitions.
//a bit hacky?
if(mode == PRO_CONTROLLER_MODE_KPADDATA){
if(mode == PRO_CONTROLLER_MODE_KPADDATA) {
KPADStatus * pro_buffer = (KPADStatus *) data;
if((res = ControllerPatcherUtils::translateToPro(vpad_buffer,pro_buffer,&last_button_hold[chan])) < 0 ) return res;
} else if(mode == PRO_CONTROLLER_MODE_WPADReadData) {
@ -899,7 +940,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHI
return CONTROLLER_PATCHER_ERROR_NONE;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(VPADStatus * buffer){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(VPADStatus * buffer) {
if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
//if(gControllerMapping.gamepad.enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED;
@ -911,15 +952,15 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
if (cm_map_pad.useAll == 1) {
data_list = ControllerPatcherHID::getHIDDataAll();
}else{
for(s32 i = 0;i<HID_MAX_DEVICES_PER_SLOT;i++){
} else {
for(s32 i = 0; i<HID_MAX_DEVICES_PER_SLOT; i++) {
ControllerMappingPADInfo cm_map_pad_info = cm_map_pad.pad_infos[i];
if(cm_map_pad_info.active){
if(cm_map_pad_info.active) {
DeviceInfo device_info;
memset(&device_info,0,sizeof(device_info));
device_info.vidpid = cm_map_pad_info.vidpid;
if(ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) < 0){
if(ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) < 0) {
continue;
//return CONTROLLER_PATCHER_ERROR_UNKNOWN_VID_PID;
}
@ -930,7 +971,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
pad = cm_map_pad_info.pad;
s32 res = ControllerPatcherHID::getHIDData(hidmask,pad,&data);
if(res < 0){
if(res < 0) {
continue;
//return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA;
}
@ -938,24 +979,24 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(V
}
}
}
if(data_list.empty()){
if(data_list.empty()) {
return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA;
}
ControllerPatcherHID::setVPADControllerData(buffer,data_list);
for(u32 i = 0; i < data_list.size();i++){
for(u32 i = 0; i < data_list.size(); i++) {
data_list[i]->rumbleActive = !!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(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) {
ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_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(ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) {
ControllerPatcher::handleCallbackDataInternal(WPAD_CHAN_1);
}
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_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;
}

View File

@ -21,18 +21,18 @@
#include <stdlib.h>
#include <string.h>
ConfigParser::ConfigParser(std::string configData){
ConfigParser::ConfigParser(std::string configData) {
this->content = configData;
this->contentLines = StringTools::stringSplit(content, "\n");
if(contentLines.empty()){
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<std::string> comments = StringTools::stringSplit(contentLines[i], "//");
if(!comments.empty()){
if(!comments.empty()) {
contentLines[i] = comments[0];
}
//we want everything uppercase
@ -41,8 +41,8 @@ ConfigParser::ConfigParser(std::string configData){
//remove empty lines
std::vector<std::string> contentline2;
for(u32 i = 0; i < contentLines.size(); i++){
if(strlen(contentLines[i].c_str()) > 0){
for(u32 i = 0; i < contentLines.size(); i++) {
if(strlen(contentLines[i].c_str()) > 0) {
contentline2.push_back(contentLines[i]);
}
}
@ -50,69 +50,69 @@ ConfigParser::ConfigParser(std::string configData){
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<std::string> 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<std::string> 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()); }
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()); }
} 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<std::string> 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{
} else {
if(HID_DEBUG) {
DEBUG_FUNCTION_LINE("Found preset value!!\n");
}
}
} 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<std::string> 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){
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[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<std::string> 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;
}

View File

@ -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<std::string,const u8*> values,std::string possibleValue){
const u8 * ConfigValues::getValuesForPreset(std::map<std::string,const u8*> values,std::string possibleValue) {
std::map<std::string,const u8*>::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<std::string,const u8*> values,std::string possibleValue,s32 slot,s32 keyslot){
if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE){
bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> 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_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<std::string,const u8*> 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,10 +90,10 @@ bool ConfigValues::setIfValueIsPreset(std::map<std::string,const u8*> values,std
}
s32 ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string nameOfString){
s32 ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string nameOfString) {
std::map<std::string,int>::iterator it;
it = values.find(nameOfString);
if (it != values.end()){
if (it != values.end()) {
return it->second;
}
@ -95,28 +101,32 @@ s32 ConfigValues::getValueFromMap(std::map<std::string,int> values,std::string n
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<std::string,std::string>::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;

View File

@ -46,12 +46,12 @@
#define DEFAULT_TCP_PORT 8112
class CPTCPServer: TCPServer{
class CPTCPServer: TCPServer {
friend class ControllerPatcher;
private:
static CPTCPServer *getInstance() {
if(!instance){
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() == 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);
}

View File

@ -24,7 +24,7 @@
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;
@ -35,22 +35,23 @@ UDPClient::UDPClient(u32 ip, s32 port){
connect_addr.sin_port = port;
connect_addr.sin_addr.s_addr = ip;
if(connect(sockfd, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0)
{
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;

View File

@ -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;
}

View File

@ -26,7 +26,7 @@
CThread * UDPServer::pThread = NULL;
UDPServer * UDPServer::instance = NULL;
UDPServer::UDPServer(s32 port){
UDPServer::UDPServer(s32 port) {
s32 ret;
struct sockaddr_in addr;
@ -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() == 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,25 +88,25 @@ 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;
@ -115,11 +117,11 @@ void UDPServer::DoUDPThreadInternal(){
bufferoffset += sizeof(type);
switch (buffer[0]) {
case WIIU_CP_UDP_CONTROLLER_READ_DATA: {
if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){
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<count_commands;i++){
for(s32 i = 0; i<count_commands; i++) {
s32 handle;
u16 deviceSlot;
u32 hid;
@ -132,7 +134,7 @@ void UDPServer::DoUDPThreadInternal(){
if(!cpyIncrementBufferOffset((void *)&padslot, (void *)buffer,&bufferoffset,sizeof(padslot), n))continue;
if(!cpyIncrementBufferOffset((void *)&datasize, (void *)buffer,&bufferoffset,sizeof(datasize), n))continue;
u8 * databuffer = (u8*) malloc(datasize * sizeof(u8));
if(!databuffer){
if(!databuffer) {
DEBUG_FUNCTION_LINE("Allocating memory failed\n");
continue;
}
@ -144,12 +146,12 @@ void UDPServer::DoUDPThreadInternal(){
user.slotdata.deviceslot = deviceSlot;
user.slotdata.hidmask = hid;
if(gNetworkController[deviceSlot][padslot][0] == 0){
if(gNetworkController[deviceSlot][padslot][0] == 0) {
DEBUG_FUNCTION_LINE("Ehm. Pad is not connected. STOP SENDING DATA ;) \n");
}else{
} else {
ControllerPatcherHID::externHIDReadCallback(handle,databuffer,datasize,&user);
}
if(databuffer){
if(databuffer) {
free(databuffer);
databuffer = NULL;
}
@ -158,10 +160,12 @@ void UDPServer::DoUDPThreadInternal(){
}
break;
}
default:{
default: {
break;
}
}
}
if(HID_DEBUG){ DEBUG_FUNCTION_LINE("UDPServer Thread ended\n"); }
if(HID_DEBUG) {
DEBUG_FUNCTION_LINE("UDPServer Thread ended\n");
}
}

View File

@ -23,7 +23,7 @@
#define WIIU_CP_UDP_CONTROLLER_READ_DATA 0x03
class UDPServer{
class UDPServer {
friend class ControllerPatcher;
private:
@ -34,7 +34,7 @@ private:
}
static void destroyInstance() {
if(instance != NULL){
if(instance != NULL) {
delete instance;
instance = NULL;
}

View File

@ -26,13 +26,13 @@
* public implementation for the network controller
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
s32 ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, HIDAttachEvent attach){
s32 ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, HIDAttachEvent attach) {
HIDClient client;
memset(&client,0,sizeof(client));
return AttachDetachCallback(&client,p_device,attach);
}
void ControllerPatcherHID::externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){
void ControllerPatcherHID::externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr) {
HIDReadCallback(handle,buf,bytes_transfered,usr);
}
@ -40,16 +40,16 @@ void ControllerPatcherHID::externHIDReadCallback(u32 handle, unsigned char *buf,
* private implementation for the HID Api.
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
s32 ControllerPatcherHID::myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach){
s32 ControllerPatcherHID::myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach) {
return AttachDetachCallback(p_client,p_device,attach);
}
void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){
if(error == 0){
void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user) {
if(error == 0) {
my_cb_user *usr = (my_cb_user*)p_user;
u32 slot = 0;
if(usr->pad_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;
}
@ -92,13 +92,13 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne
}
}
void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){
if(error == 0 && p_user != NULL && gHIDAttached){
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);
if(usr->slotdata.hidmask == gHID_LIST_DS4){
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);
@ -109,16 +109,18 @@ void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned cha
* 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);
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); }
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;i<HID_MAX_PADS_COUNT;i += pads_per_device){
if(!(pad_count & (1 << i))){
for(s32 i = 0; i<HID_MAX_PADS_COUNT; i += pads_per_device) {
if(!(pad_count & (1 << i))) {
failed = 0;
pad_count |= (1 << i);
pad_slot = i;
@ -186,13 +188,13 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
}
}
if(failed){
if(failed) {
DEBUG_FUNCTION_LINE("error: I can only handle %d devices of the same type. Sorry \n",HID_MAX_PADS_COUNT);
if(buf){
if(buf) {
free(buf);
buf = NULL;
}
if(usr){
if(usr) {
free(usr);
usr = NULL;
}
@ -207,7 +209,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
usr->pads_per_device = pads_per_device;
usr->pad_slot = pad_slot;
for(s32 i = 0;i<pads_per_device;i++){
for(s32 i = 0; i<pads_per_device; i++) {
memset(&gHID_Devices[slotdata->deviceslot].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;i<HID_MAX_PADS_COUNT;i++){
if(gHID_Devices[slotdata->deviceslot].pad_data[i].handle == p_device->handle){
for(s32 i = 0; i<HID_MAX_PADS_COUNT; i++) {
if(gHID_Devices[slotdata->deviceslot].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"); }
}
}else{
if(HID_DEBUG) {
DEBUG_FUNCTION_LINE("Device successfully detached\n");
}
}
} else {
DEBUG_FUNCTION_LINE("HID-Device currently not supported! You can add support through config files\n");
}
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<HID_Data *>& data){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(VPADStatus * buffer,std::vector<HID_Data *>& data) {
if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
HID_Data * data_cur;
s32 buttons_hold;
for(u32 i = 0;i<data.size();i++){
for(u32 i = 0; i<data.size(); i++) {
data_cur = data[i];
if(data_cur->slotdata.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<HID_Data *> ControllerPatcherHID::getHIDDataAll(){
std::vector<HID_Data *> ControllerPatcherHID::getHIDDataAll() {
u32 hid = gHIDCurrentDevice;
std::vector<HID_Data *> 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<HID_Data *> 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;i<HID_GC_PAD_COUNT;i++){
for(s32 i = 0; i<HID_GC_PAD_COUNT; i++) {
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.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) {

View File

@ -40,19 +40,19 @@
#define SWAP16(x) ((x>>8) | ((x&0xFF)<<8))
#define SWAP8(x) ((x>>4) | ((x&0xF)<<4))
class ControllerPatcherHID{
class ControllerPatcherHID {
friend class ControllerPatcher;
friend class ControllerPatcherUtils;
public:
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:
private:
static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADStatus * buffer,std::vector<HID_Data *>& data);
static std::vector<HID_Data *> getHIDDataAll();
static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(u32 hidmask, s32 pad, HID_Data ** data);
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Rumble
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
@ -62,7 +62,7 @@ class ControllerPatcherHID{
static void HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble);
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* HID Callbacks
*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static s32 myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, HIDAttachEvent attach);

View File

@ -20,11 +20,11 @@
#include <utils/logger.h>
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){
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];
@ -151,25 +155,28 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
}
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[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<HID_KEYBOARD_DATA_LENGTH;i++){
if(keyboardData[i] == 0 && i > 1){
for(s32 i = 0; i<HID_KEYBOARD_DATA_LENGTH; i++) {
if(keyboardData[i] == 0 && i > 1) {
break;
}else if (keyboardData[i] == key){
} else if (keyboardData[i] == key) {
return 1;
}
}
@ -260,11 +298,11 @@ 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!
if(config_controller[gGamePadSlot][CONTRPS_SLOT][0] != CONTROLLER_PATCHER_INVALIDVALUE) { //using new value!
new_value = gGamePadValues[config_controller[gGamePadSlot][CONTRPS_SLOT][1]];
}
@ -272,15 +310,15 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingDat
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,32 +426,32 @@ 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;
}
}
@ -413,20 +459,20 @@ VPADVec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){
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,14 +482,14 @@ 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){
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];
}
@ -455,9 +501,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
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){
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]],
@ -468,9 +514,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
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){
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];
}
@ -482,9 +528,9 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
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){
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];
}
@ -498,55 +544,87 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
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,11 +691,11 @@ 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)){
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));
@ -639,23 +717,23 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * d
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,40 +918,40 @@ 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]){
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){
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(info->pad_count > HID_MAX_PADS_COUNT) {
info->pad_count = HID_MAX_PADS_COUNT;
}
}
@ -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;i<pad_count;i++){
if( config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0] != CONTROLLER_PATCHER_INVALIDVALUE){
if(input_data[config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0]] == config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][1]){
for(s32 i= 0; i<pad_count; i++) {
if( config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0] != CONTROLLER_PATCHER_INVALIDVALUE) {
if(input_data[config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][0]] == config_controller[deviceslot][CONTRPS_PAD1_FILTER + i][1]) {
slot_incr = i;
break;
}
@ -926,25 +1004,25 @@ s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data)
return slot_incr;
}
ControllerMappingPAD * ControllerPatcherUtils::getControllerMappingByType(UController_Type type){
ControllerMappingPAD * ControllerPatcherUtils::getControllerMappingByType(UController_Type type) {
ControllerMappingPAD * cm_map_pad = NULL;
if(type == UController_Type_Gamepad){
if(type == UController_Type_Gamepad) {
cm_map_pad = &(gControllerMapping.gamepad);
}else if(type == UController_Type_Pro1){
} else if(type == UController_Type_Pro1) {
cm_map_pad = &(gControllerMapping.proController[0]);
}else if(type == UController_Type_Pro2){
} else if(type == UController_Type_Pro2) {
cm_map_pad = &(gControllerMapping.proController[1]);
}else if(type == UController_Type_Pro3){
} else if(type == UController_Type_Pro3) {
cm_map_pad = &(gControllerMapping.proController[2]);
}else if(type == UController_Type_Pro4){
} else if(type == UController_Type_Pro4) {
cm_map_pad = &(gControllerMapping.proController[3]);
}
return cm_map_pad;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::doSampling(u16 deviceslot,u8 padslot = 0,bool ignorePadSlot = false){
if(gSamplingCallback != NULL){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::doSampling(u16 deviceslot,u8 padslot = 0,bool ignorePadSlot = false) {
if(gSamplingCallback != NULL) {
doSamplingSingle(WPAD_CHAN_0, deviceslot, padslot, ignorePadSlot);
doSamplingSingle(WPAD_CHAN_1, deviceslot, padslot, ignorePadSlot);
doSamplingSingle(WPAD_CHAN_2, deviceslot, padslot, ignorePadSlot);
@ -953,24 +1031,24 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::doSampling(u16 device
return CONTROLLER_PATCHER_ERROR_NONE;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::doSamplingSingle(WPADChan chan, u16 deviceslot,u8 padslot = 0,bool ignorePadSlot = false){
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::doSamplingSingle(WPADChan chan, u16 deviceslot,u8 padslot = 0,bool ignorePadSlot = false) {
ControllerMappingPADInfo * padinfo = gProPadInfo[chan];
if(padinfo->active){
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);
}
}

View File

@ -32,13 +32,13 @@
#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:
public:
/**
\brief Returns the device slot for a given HID-Mask.
@ -77,7 +77,7 @@ class ControllerPatcherUtils{
*
*/
static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToVPAD(VPADStatus * vpad_buffer,KPADStatus * pro_buffer,u32 * lastButtonsPressesVPAD);
private:
private:
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Analyse inputs
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

View File

@ -72,4 +72,5 @@ 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[3].pad_infos[0]
} ;

View File

@ -63,7 +63,8 @@ const uint8_t HID_GC_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x09, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x1A, //STICK_CONF_MIN,
0xE4};//STICK_CONF_MAX,
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,
@ -71,7 +72,8 @@ const uint8_t HID_GC_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x09, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x11, //STICK_CONF_MIN,
0xE1};//STICK_CONF_MAX,
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,
@ -79,7 +81,8 @@ const uint8_t HID_GC_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x09, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x2B, //STICK_CONF_MIN,
0xE2};//STICK_CONF_MAX,
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,
@ -87,7 +90,8 @@ const uint8_t HID_GC_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x09, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x1D, //STICK_CONF_MIN,
0xDB};//STICK_CONF_MAX,
0xDB
};//STICK_CONF_MAX,
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! DS3
@ -122,7 +126,8 @@ const uint8_t HID_DS3_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x06, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -130,7 +135,8 @@ const uint8_t HID_DS3_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x06, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -138,7 +144,8 @@ const uint8_t HID_DS3_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x06, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -146,7 +153,8 @@ const uint8_t HID_DS3_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x06, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
0xFF
};//STICK_CONF_MAX,
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! DS4
@ -189,7 +197,8 @@ const uint8_t HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x06, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -197,7 +206,8 @@ const uint8_t HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x05, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -205,7 +215,8 @@ const uint8_t HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x07, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -213,7 +224,8 @@ const uint8_t HID_DS4_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGI
0x09, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
0xFF
};//STICK_CONF_MAX,
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! XInput
@ -248,7 +260,8 @@ const uint8_t HID_XINPUT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_M
0x10, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -256,7 +269,8 @@ const uint8_t HID_XINPUT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_M
0x10, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -264,7 +278,8 @@ const uint8_t HID_XINPUT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_M
0x10, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
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,
@ -272,7 +287,8 @@ const uint8_t HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_M
0x10, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x00, //STICK_CONF_MIN,
0xFF};//STICK_CONF_MAX,
0xFF
};//STICK_CONF_MAX,
@ -315,7 +331,8 @@ const uint8_t HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK
0x01, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x28, //STICK_CONF_MIN,
0xDF};//STICK_CONF_MAX,
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,
@ -323,7 +340,8 @@ const uint8_t HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK
0x06, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x16, //STICK_CONF_MIN,
0xD7};//STICK_CONF_MAX,
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,
@ -331,7 +349,8 @@ const uint8_t HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK
0x04, //STICK_CONF_DEADZONE,
0x00, //STICK_CONF_INVERT,
0x29, //STICK_CONF_MIN,
0xE2};//STICK_CONF_MAX,
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,
@ -339,4 +358,5 @@ const uint8_t HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK
0x08, //STICK_CONF_DEADZONE,
0x01, //STICK_CONF_INVERT,
0x22, //STICK_CONF_MIN,
0xE4};//STICK_CONF_MAX,
0xE4
};//STICK_CONF_MAX,