diff --git a/config_parser.cpp b/config_parser.cpp new file mode 100644 index 0000000..3163fd5 --- /dev/null +++ b/config_parser.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#include +#include +#include +#include + +#include "config_parser.h" +#include "config_reader.h" +#include "config_values.h" +#include "string_tools.hpp" + +ConfigParser::ConfigParser(std::string configData) +{ + this->content = configData; + this->contentLines = MyStringSplit(content, "\n"); + + if(contentLines.empty()) + return; + + //remove the comments and make everything uppercase + for(u32 i = 0; i < contentLines.size(); i++){ + std::vector comments = MyStringSplit(contentLines[i], "//"); + if(!comments.empty()){ + contentLines[i] = comments[0]; + } + //we want everything uppercase + std::transform(contentLines[i].begin(), contentLines[i].end(),contentLines[i].begin(), ::toupper); + } + + //remove empty lines + std::vector contentline2; + for(u32 i = 0; i < contentLines.size(); i++){ + if(strlen(contentLines[i].c_str()) > 0){ + contentline2.push_back(contentLines[i]); + } + } + contentLines = contentline2; + Init(); +} + +ConfigParser::~ConfigParser() +{ + +} + +PARSE_TYPE ConfigParser::getType(){ + return type_b; +} + +void ConfigParser::setType(PARSE_TYPE newType){ + this->type_b = newType; +} + +u16 ConfigParser::getSlot(){ + return this->slot_b; +} + +void ConfigParser::setSlot(u16 newSlot){ + this->slot_b = newSlot; +} + +bool ConfigParser::Init(){ + const char * line = contentLines[0].c_str(); + int len = strlen(line); + std::string identify; + if(line[0] == '[' && line[len-1] == ']'){ + identify = contentLines[0].substr(1,len-2); + }else{ + log_printf("Not a proper config file!\n"); + return false; + } + + if(identify.compare("GAMEPAD") == 0){ + log_printf("Its a gamepad config file!\n"); + setSlot(gGamePadSlot); + setType(PARSE_GAMEPAD); + }else if(identify.compare("MOUSE") == 0){ + log_printf("Its a mouse config file!\n"); + setSlot(gMouseSlot); + setType(PARSE_MOUSE); + }else if(identify.compare("KEYBOARD") == 0){ + log_printf("Its a keyboard config file!\n"); + setSlot(gHID_SLOT_KEYBOARD); + setType(PARSE_KEYBOARD); + }else{ + log_printf("Its a controller config file!\n"); + setSlot(getSlotController(identify)); + setType(PARSE_CONTROLLER); + } + + if(getSlot() == HID_INVALID_SLOT){ + return false; + } + + ConfigReader::increaseNumberOfLoadedFiles(); + + return true; +} + +void ConfigParser::parseSingleLine(std::string line){ + std::vector cur_values = MyStringSplit(line,"="); + if(cur_values.size() != 2){ + if(HID_DEBUG || cur_values.size() > 2) log_printf("Not a valid key=pair line %s\n",line.c_str()); + return; + }else{ + + u16 hid_slot = getSlot(); + + if(HID_DEBUG) log_printf("leftpart = \"%s\" \n",cur_values[0].c_str()); + if(HID_DEBUG) log_printf("rightpart = _%s_ \n",cur_values[1].c_str()); + int keyslot = -1; + + if(HID_DEBUG) log_printf("Checking single value\n"); + if(getType() == PARSE_GAMEPAD || getType() == PARSE_KEYBOARD){ + keyslot = ConfigValues::getKeySlotGamePad(cur_values[0]); + }else if(getType() == PARSE_MOUSE){ + keyslot = ConfigValues::getKeySlotMouse(cur_values[0]); + }else{ + keyslot = ConfigValues::getKeySlotDefaultSingleValue(cur_values[0]); + } + if(keyslot != -1){ + if(HID_DEBUG) log_printf("Its a single value\n"); + long rightValue = -1; + bool valueSet = false; + if(cur_values[0].compare("DPAD_MODE") == 0){ + const u8 * values_ = NULL; + if((values_ = ConfigValues::getValuesStickPreset(cur_values[1])) != NULL){ + if(values_[STICK_CONF_MAGIC_VERSION] != STICK_CONF_MAGIC_VALUE) + if(HID_DEBUG) log_printf("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){ + config_controller[hid_slot][CONTRPS_DPAD_MASK][0] = CONTROLLER_PATCHER_VALUE_SET; + config_controller[hid_slot][CONTRPS_DPAD_MASK][1] = values_[CONTRDPAD_MASK]; + } + valueSet = true; + } + } + + if(!valueSet){ + if(getType() == PARSE_KEYBOARD){ + if((rightValue = ConfigValues::getPresetValuesKeyboard(cur_values[1]))!= -1){ + if(HID_DEBUG) log_printf("Used pre-defined Keyboard! \"%s\" is %d\n",cur_values[1].c_str(),rightValue); + }else{ + if(HID_DEBUG) log_printf("I need to parse %s\n",cur_values[1].c_str()); + char * ptr; + rightValue = strtol(cur_values[1].c_str(),&ptr,16); + } + + if(keyslot >= DEF_L_STICK_UP && keyslot <= DEF_R_STICK_RIGHT){ + if(keyslot == DEF_L_STICK_UP){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] = rightValue; + }else if(keyslot == DEF_L_STICK_DOWN){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y][1] = rightValue; + }else if(keyslot == DEF_L_STICK_LEFT){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] = rightValue; + }else if(keyslot == DEF_L_STICK_RIGHT){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_L_STICK_X][1] = rightValue; + }else if(keyslot == DEF_R_STICK_UP){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] = rightValue; + }else if(keyslot == DEF_R_STICK_DOWN){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y][1] = rightValue; + }else if(keyslot == DEF_R_STICK_LEFT){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_R_STICK_X][0] = rightValue; + }else if(keyslot == DEF_R_STICK_RIGHT){ + config_controller[hid_slot][CONTRPS_VPAD_BUTTON_R_STICK_X][1] = rightValue; + }else{ + log_printf("Random error in Keyboard sticks\n"); + } + if(HID_DEBUG) log_printf("Set stick for Keyboard (%d)\n",keyslot); + return; + } + + }else{ + rightValue = ConfigValues::getPresetValue(cur_values[1]); + + if(getType() == PARSE_MOUSE){ //No parsing for the mouse + if(rightValue == -1){ + if(HID_DEBUG) log_printf("Invalid mouse value, lets skip it %s\n",cur_values[1].c_str()); + return; + } + }else{ + if(rightValue == -1){ + if(HID_DEBUG) log_printf("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) log_printf("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) log_printf("Check pair value\n"); + keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]); + if(keyslot != -1){ + if(HID_DEBUG) log_printf("Its a pair value\n"); + + if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){ + if(HID_DEBUG) log_printf("And its no preset\n"); + std::vector rightvalues = MyStringSplit(cur_values[1],","); + + if(rightvalues.size() != 2){ + log_printf("%d instead of 2 key=values pairs in line\n",rightvalues.size()); + return; + } + + char * ptr; + long firstValue = strtol(rightvalues[0].c_str(),&ptr,16); + long secondValue = strtol(rightvalues[1].c_str(),&ptr,16); + config_controller[hid_slot][keyslot][0] = firstValue; + config_controller[hid_slot][keyslot][1] = secondValue; + + if(HID_DEBUG) log_printf("Set %02X,%02X\n",firstValue,secondValue); + }else{ + if(HID_DEBUG) log_printf("Found preset value!!\n"); + } + }else{ + log_printf("The setting \"%s\" is unknown!\n",cur_values[0].c_str()); + } + } + } +} + +bool ConfigParser::resetConfig(){ + int slot = getSlot(); + if(slot >= gHIDMaxDevices) return false; + for(int 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; +} + +int ConfigParser::checkExistingController(int vid, int pid){ + for(int i = 0;i< gHIDMaxDevices;i++){ + u16 used_vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1]; + u16 used_pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1]; + if((used_vid == 0x00) && (used_vid == 0x00)){ + return -1; + } + if(vid == used_vid && pid == used_pid){ + return i; + } + } + return -1; +} + +int ConfigParser::getSlotController(std::string identify){ + if(HID_DEBUG) log_printf("Getting Controller Slot\n"); + + std::vector values = MyStringSplit(identify,","); + + if(values.size() != 2){ + log_printf("You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",identify.c_str()); + return HID_INVALID_SLOT; + } + + int vid = getValueFromKeyValue(values[0],"VID","="); + if(vid < 0){ + return HID_INVALID_SLOT; + } + int pid = getValueFromKeyValue(values[1],"PID","="); + if(pid < 0){ + return HID_INVALID_SLOT; + } + log_printf("VID: %04x PID: %04x\n",vid,pid); + + int slot = checkExistingController(vid,pid); + int hid = 0; + if(slot < 0){ + log_printf("Its a new controller, lets save it\n"); + slot = gHIDRegisteredDevices; + hid = getNextDeviceSlot(); + if(slot >= gHIDMaxDevices){ + log_printf("We don't a space for a new controller, please delete .inis\n"); + return HID_INVALID_SLOT; + } + if(HID_DEBUG) log_printf("Got new slot! slot: %d hid %s .. Lets registrate it!\n",slot,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); + + u16 used_vid = config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1]; + u16 used_pid = config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]; + + if(HID_DEBUG) log_printf("Saved vid: %04X pid: %04X\n",used_vid,used_pid); + + config_controller_list[slot] = hid; + + if(HID_DEBUG) log_printf("Saves the hid\n"); + config_controller_data_ptr[slot][0] = (u32)&(gHID_Devices[slot]).pad_data[0]; + config_controller_data_ptr[slot][1] = (u32)&(gHID_Devices[slot]).pad_data[1]; + config_controller_data_ptr[slot][2] = (u32)&(gHID_Devices[slot]).pad_data[2]; + config_controller_data_ptr[slot][3] = (u32)&(gHID_Devices[slot]).pad_data[3]; + + if(HID_DEBUG) log_printf("set data ptr\n"); + + }else{ + if(slot < gHIDMaxDevices){ + hid =config_controller_list[slot]; + if(HID_DEBUG) log_printf(">>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",slot,byte_to_binary(hid)); + log_printf("We already have data of this controller, lets modify it\n"); + }else{ + log_printf("Something really odd happend to the slots. %d is bigger then max (%d)\n",slot,gHIDMaxDevices); + return HID_INVALID_SLOT; + } + } + + if(HID_DEBUG) log_printf("using slot: %d hid %s\n",slot,byte_to_binary(hid)); + return slot; +} + +bool ConfigParser::parseIni(){ + if(getSlot() == HID_INVALID_SLOT){ + log_printf("Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",getType(),gHIDMaxDevices); + + } + + if(HID_DEBUG) log_printf("Parsing content, type %d\n",getType()); + + int start = 1; + if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){ + resetConfig(); + log_printf("Overwriting existing settings of this device\n"); + start++; + } + + for(u32 i = start; i < contentLines.size(); i++){ + if(HID_DEBUG) log_printf("line %d: \"%s\" \n",(i+1),contentLines[i].c_str()); + parseSingleLine(contentLines[i]); + } + + log_printf("Parsing of the file is done.\n"); + return true; +} + +int ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter){ + std::vector string_value = MyStringSplit(value_pair,delimiter); + if(string_value.size() != 2){ + if(HID_DEBUG || string_value.size() > 2) log_printf("Not a valid key=pair line %s\n",value_pair.c_str()); + return -1; + } + if(string_value[0].compare(expectedKey) != 0){ + log_printf("Key part not %s, its %s",expectedKey.c_str(),string_value[0].c_str()); + return -1; + } + char * ptr; + int value = strtol(string_value[1].c_str(),&ptr,16); + + return value; +} diff --git a/config_parser.h b/config_parser.h new file mode 100644 index 0000000..ce3d599 --- /dev/null +++ b/config_parser.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#ifndef _ConfigParser_H_ +#define _ConfigParser_H_ + +#include +#include +#include + +#include +#include + +#include "controller_patcher.h" +#include "pad_const.h" + +#include "utils/logger.h" +#include "cp_retain_vars.h" + +enum PARSE_TYPE{ + PARSE_CONTROLLER, + PARSE_GAMEPAD, + PARSE_MOUSE, + PARSE_KEYBOARD +}; + +class ConfigParser +{ +public: + //!Constructor + ConfigParser(std::string configData); + //!Destructor + ~ConfigParser(); + + PARSE_TYPE getType(); + void setType(PARSE_TYPE newType); + + u16 getSlot(); + void setSlot(u16 newSlot); + + bool parseIni(); + +private: + bool Init(); + + bool parseConfigString(std::string content); + + int getSlotController(std::string identify); + + int checkExistingController(int vid, int pid); + + int getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter); + + bool resetConfig(); + + void parseSingleLine(std::string line); + u16 slot_b; + PARSE_TYPE type_b; + std::string content; + std::vector contentLines; +}; +#endif diff --git a/config_reader.cpp b/config_reader.cpp new file mode 100644 index 0000000..23e3b88 --- /dev/null +++ b/config_reader.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#include +#include +#include + +#include "config_reader.h" +#include "config_parser.h" +#include "config_values.h" +#include "string_tools.hpp" + +int ConfigReader::numberValidFiles = 0; +ConfigReader *ConfigReader::instance = NULL; + +ConfigReader::ConfigReader() +{ + InitOSFunctionPointers(); + InitFSFunctionPointers(); + int status = 0; + if((status = InitSDCard()) == 0){ + log_printf("SD Card mounted for controller config!\n"); + std::vector fileList; + if((fileList = ScanFolder()).size() > 0){ + log_printf("Found %d config files\n",fileList.size()); + processFileList(fileList); + } + }else{ + log_printf("SD mounting failed! %d\n",status); + } +} + +void ConfigReader::processFileList(std::vector path){ + for(std::vector::iterator it = path.begin(); it != path.end(); ++it) { + log_printf("Reading %s\n",it->c_str()); + std::string result = loadFileToString(*it); + + ConfigParser parser(result); + parser.parseIni(); + } +} + +std::string ConfigReader::loadFileToString(std::string path){ + int handle = 0; + int status = 0; + std::string strBuffer; + FSStat stats; + if((status = FSGetStat(this->pClient,this->pCmd,path.c_str(),&stats,-1)) == FS_STATUS_OK){ + char * file = (char *) malloc((sizeof(char)*stats.size)+1); + if(!file){ + log_print("Failed to allocate space for reading the file\n"); + return false; + } + file[stats.size] = '\0'; + if((status = FSOpenFile(this->pClient,this->pCmd,path.c_str(),"r",&handle,-1)) == FS_STATUS_OK){ + int total_read = 0; + int ret2 = 0; + while ((ret2 = FSReadFile(pClient, pCmd, file+total_read, 1, stats.size-total_read, handle, 0, FS_RET_ALL_ERROR)) > 0){ + total_read += ret2; + } + + }else{ + log_printf("(FSOpenFile) Couldn't open file (%s), error: %d",path.c_str(),status); + free(file); + file=NULL; + return false; + } + + FSCloseFile(this->pClient,this->pCmd,handle,-1); + + strBuffer = std::string(file); + free(file); + file = NULL; + + //! remove all windows crap signs + size_t position; + while(1) + { + position = strBuffer.find('\r'); + if(position == std::string::npos) + break; + strBuffer.erase(position, 1); + } + while(1) + { + position = strBuffer.find(' '); + if(position == std::string::npos) + break; + strBuffer.erase(position, 1); + } + while(1) + { + position = strBuffer.find('\t'); + if(position == std::string::npos) + break; + strBuffer.erase(position, 1); + } + }else{ + log_printf("(GetStat) Couldn't open file (%s), error: %d",path.c_str(),status); + } + + return strBuffer; +} + + +ConfigReader::~ConfigReader() +{ + if(HID_DEBUG) log_printf("~ConfigReader\n"); + freeFSHandles(); + + if(HID_DEBUG) log_printf("~destroy the ConfigValues\n"); + ConfigValues::destroyInstance(); +} +std::vector ConfigReader::ScanFolder() +{ + std::string path = std::string(CAFE_OS_SD_PATH) + std::string(WIIU_PATH) + "/controller"; + int dirhandle = 0; + if(HID_DEBUG) log_printf("Opening %s\n",path.c_str()); + std::vector config_files; + if (this->pClient && this->pCmd){ + int status = 0; + if((status = FSOpenDir(this->pClient,this->pCmd,path.c_str(),&dirhandle,-1)) == FS_STATUS_OK){ + FSDirEntry dir_entry; + while (FSReadDir(this->pClient, this->pCmd, dirhandle, &dir_entry, FS_RET_ALL_ERROR) == FS_STATUS_OK){ + std::string full_path = path + "/" + dir_entry.name; + if((dir_entry.stat.flag&FS_STAT_FLAG_IS_DIRECTORY) != FS_STAT_FLAG_IS_DIRECTORY){ + if(EndsWith(std::string(dir_entry.name),".ini")){ + config_files.push_back(full_path); + if(HID_DEBUG) log_printf("%s \n",full_path.c_str()); + } + } + } + FSCloseDir(this->pClient,this->pCmd,dirhandle,-1); + }else{ + log_printf("Failed to open %s!\n",path.c_str()); + } + } + return config_files; +} + +void ConfigReader::freeFSHandles(){ + if(this->pClient != NULL){ + FSDelClient(this->pClient); + free(this->pClient); + this->pClient = NULL; + } + if(this->pCmd != NULL){ + free(this->pCmd); + this->pCmd = NULL; + } +} + +int ConfigReader::InitSDCard(){ + if(HID_DEBUG) log_printf("InitSDCard\n"); + + char mountSrc[FS_MOUNT_SOURCE_SIZE]; + char mountPath[FS_MAX_MOUNTPATH_SIZE]; + + freeFSHandles(); + + this->pClient = malloc(FS_CLIENT_SIZE); + this->pCmd = malloc(FS_CMD_BLOCK_SIZE); + + int status = 0; + + if (this->pClient && this->pCmd) + { + // Do an FSInit first + FSInit(); + // Add client to FS. + FSAddClientEx(this->pClient, FS_RET_NO_ERROR,-1); + + // Init command block. + FSInitCmdBlock(this->pCmd); + + // Mount sdcard + if ((status = FSGetMountSource(this->pClient, this->pCmd, FS_SOURCETYPE_EXTERNAL, &mountSrc, FS_RET_NO_ERROR)) == FS_STATUS_OK) + { + if ((status = FSMount(this->pClient, this->pCmd, &mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, FS_RET_UNSUPPORTED_CMD)) == FS_STATUS_OK) + { + return 0; + }else{ + log_printf("FSMount failed %d\n",status); + return status; + } + }else{ + log_printf("FSGetMountSource failed %d\n",status); + return status; + } + } + return -1; +} diff --git a/config_reader.h b/config_reader.h new file mode 100644 index 0000000..7a56e3e --- /dev/null +++ b/config_reader.h @@ -0,0 +1,82 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#ifndef _ConfigReader_H_ +#define _ConfigReader_H_ + +#include +#include +#include + +#include +#include + +#include "controller_patcher.h" +#include "pad_const.h" + +#include "../dynamic_libs/os_functions.h" +#include "../dynamic_libs/fs_functions.h" +#include "cp_retain_vars.h" + + + +class ConfigReader +{ +public: + static ConfigReader *getInstance() { + if(!instance) + instance = new ConfigReader(); + return instance; + } + + static void destroyInstance() { + if(instance){ + delete instance; + instance = NULL; + } + } + + static int getNumberOfLoadedFiles(){ + return ConfigReader::numberValidFiles; + } + + static void increaseNumberOfLoadedFiles(){ + ConfigReader::numberValidFiles++; + } + static int numberValidFiles; + +private: + //!Constructor + ConfigReader(); + //!Destructor + ~ConfigReader(); + + + int InitSDCard(); + void freeFSHandles(); + + void * pClient = NULL; + void * pCmd = NULL; + static ConfigReader *instance; + + + + std::string loadFileToString(std::string path); + void processFileList(std::vector path); + + std::vector ScanFolder(); +}; +#endif diff --git a/config_values.cpp b/config_values.cpp new file mode 100644 index 0000000..70c23b9 --- /dev/null +++ b/config_values.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#include +#include +#include +#include "config_values.h" +#include "utils/logger.h" +#include "cp_retain_vars.h" + +ConfigValues *ConfigValues::instance = NULL; + +ConfigValues::ConfigValues() +{ + InitValues(); +} + +ConfigValues::~ConfigValues() +{ + +} + +const u8 * ConfigValues::getValuesForPreset(std::map values,std::string possibleValue){ + std::map::iterator it; + it = values.find(possibleValue); + if (it != values.end()){ + return it->second; + } + return NULL; +} + +bool ConfigValues::setIfValueIsAControllerPresetEx(std::string value,int slot,int 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; + return false; +} + +//We need this function here so we can use preset sticks. +bool ConfigValues::setIfValueIsPreset(std::map values,std::string possibleValue,int slot,int keyslot){ + 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) log_printf("This may be a predefined stick %s\n",possibleValue.c_str()); + if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){ + if(HID_DEBUG) log_printf("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 + config_controller[slot][keyslot+DEF_STICK_OFFSET_INVERT][1] = values_[STICK_CONF_INVERT]; + config_controller[slot][keyslot+DEF_STICK_OFFSET_DEADZONE][0] = CONTROLLER_PATCHER_VALUE_SET; //CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE + config_controller[slot][keyslot+DEF_STICK_OFFSET_DEADZONE][1] = values_[STICK_CONF_DEADZONE]; + config_controller[slot][keyslot+DEF_STICK_OFFSET_MINMAX][0] = values_[STICK_CONF_MIN]; //CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX + config_controller[slot][keyslot+DEF_STICK_OFFSET_MINMAX][1] = values_[STICK_CONF_MAX]; + + return true; + } + } + + if((values_ = getValuesForPreset(values,possibleValue)) != NULL){ + config_controller[slot][keyslot][0] = values_[0]; + config_controller[slot][keyslot][1] = values_[1]; + return true; + } + return false; +} + + +int ConfigValues::getValueFromMap(std::map values,std::string nameOfString){ + std::map::iterator it; + it = values.find(nameOfString); + if (it != values.end()){ + return it->second; + } + + //Value not found + return -1; +} + +int ConfigValues::getPresetValueEx(std::string possibleString){ + int rightValue = -1; + if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){ + if(HID_DEBUG) log_printf("Used pre-defined VPAD_VALUE! \"%s\" is %d\n",possibleString.c_str(),rightValue); + }else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){ + if(HID_DEBUG) log_printf("Used pre-defined value! \"%s\" is %d\n",possibleString.c_str(),rightValue); + } + return rightValue; +} diff --git a/config_values.h b/config_values.h new file mode 100644 index 0000000..37c464c --- /dev/null +++ b/config_values.h @@ -0,0 +1,473 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ +#ifndef _ConfigValues_H_ +#define _ConfigValues_H_ + +#include +#include +#include +#include + +#include "controller_patcher.h" +#include "pad_const.h" + +class ConfigValues +{ +public: + static ConfigValues *getInstance() { + if(!instance) + instance = new ConfigValues(); + return instance; + } + + static void destroyInstance() { + if(instance){ + delete instance; + instance = NULL; + } + } + + /** + Returns NULL if no a preset! + **/ + static const u8 * getValuesStickPreset(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return NULL; + return cur_instance->getValuesForPreset(cur_instance->presetSticks,possibleValue); + } + + /** + Returns -1 if not found + **/ + static int getKeySlotGamePad(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getValueFromMap(cur_instance->CONTPRStringToValue,possibleValue); + } + /** + Returns -1 if not found + **/ + static int getKeySlotMouse(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getValueFromMap(cur_instance->mouseLeftValues,possibleValue); + } + + /** + Returns -1 if not found + **/ + static int getKeySlotDefaultSingleValue(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getValueFromMap(cur_instance->CONTPRStringToValueSingle,possibleValue); + } + + /** + Returns -1 if not found + **/ + static int getKeySlotDefaultPairedValue(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getValueFromMap(cur_instance->CONTPRStringToValue,possibleValue); + } + + /** + Returns -1 if not found + **/ + static int getPresetValuesKeyboard(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getValueFromMap(cur_instance->presetKeyboardValues,possibleValue); + } + + /** + Returns -1 if not found + **/ + static int getPresetValue(std::string possibleValue) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->getPresetValueEx(possibleValue); + } + + /** + Returns -1 if not found + **/ + static int setIfValueIsAControllerPreset(std::string value,int slot,int keyslot) + { + ConfigValues * cur_instance = getInstance(); + if(cur_instance == NULL) return -1; + return cur_instance->setIfValueIsAControllerPresetEx(value,slot,keyslot); + } + +private: + //!Constructor + ConfigValues(); + //!Destructor + ~ConfigValues(); + + static ConfigValues *instance; + + std::map mouseLeftValues; + std::map CONTPRStringToValue; + std::map CONTPRStringToValueSingle; + std::map presetValues; + std::map gGamePadValuesToCONTRPSString; + std::map presetKeyboardValues; + + std::map presetGCValues; + std::map presetDS3Values; + std::map presetDS4Values; + std::map presetSticks; + + int getValueFromMap(std::map values,std::string nameOfString); + + bool checkIfValueIsAControllerPreset(std::string value,int slot,int keyslot); + + int getPresetValueEx(std::string possibleString); + + void InitValues(){ + CONTPRStringToValue["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A; + CONTPRStringToValue["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B; + CONTPRStringToValue["VPAD_BUTTON_X"] = CONTRPS_VPAD_BUTTON_X; + CONTPRStringToValue["VPAD_BUTTON_Y"] = CONTRPS_VPAD_BUTTON_Y; + /* Normal DPAD */ + CONTPRStringToValue["VPAD_BUTTON_LEFT"] = CONTRPS_VPAD_BUTTON_LEFT; + CONTPRStringToValue["VPAD_BUTTON_RIGHT"] = CONTRPS_VPAD_BUTTON_RIGHT; + CONTPRStringToValue["VPAD_BUTTON_UP"] = CONTRPS_VPAD_BUTTON_UP; + CONTPRStringToValue["VPAD_BUTTON_DOWN"] = CONTRPS_VPAD_BUTTON_DOWN; + /* DPAD hat mode */ + CONTPRStringToValue["VPAD_BUTTON_DPAD_N"] = CONTRPS_VPAD_BUTTON_DPAD_N; + CONTPRStringToValue["VPAD_BUTTON_DPAD_NE"] = CONTRPS_VPAD_BUTTON_DPAD_NE; + CONTPRStringToValue["VPAD_BUTTON_DPAD_E"] = CONTRPS_VPAD_BUTTON_DPAD_E; + CONTPRStringToValue["VPAD_BUTTON_DPAD_SE"] = CONTRPS_VPAD_BUTTON_DPAD_SE; + CONTPRStringToValue["VPAD_BUTTON_DPAD_S"] = CONTRPS_VPAD_BUTTON_DPAD_S; + CONTPRStringToValue["VPAD_BUTTON_DPAD_SW"] = CONTRPS_VPAD_BUTTON_DPAD_SW; + CONTPRStringToValue["VPAD_BUTTON_DPAD_W"] = CONTRPS_VPAD_BUTTON_DPAD_W; + CONTPRStringToValue["VPAD_BUTTON_DPAD_NW"] = CONTRPS_VPAD_BUTTON_DPAD_NW; + CONTPRStringToValue["VPAD_BUTTON_DPAD_NEUTRAL"] = CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL; + /* DPAD Absolute mode */ + CONTPRStringToValue["VPAD_BUTTON_DPAD_ABS_UP"] = CONTRPS_VPAD_BUTTON_DPAD_ABS_UP; + CONTPRStringToValue["VPAD_BUTTON_DPAD_ABS_DOWN"] = CONTRPS_VPAD_BUTTON_DPAD_ABS_DOWN; + CONTPRStringToValue["VPAD_BUTTON_DPAD_ABS_LEFT"] = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT; + CONTPRStringToValue["VPAD_BUTTON_DPAD_ABS_RIGHT"] = CONTRPS_VPAD_BUTTON_DPAD_ABS_RIGHT; + /* */ + CONTPRStringToValue["VPAD_BUTTON_ZL"] = CONTRPS_VPAD_BUTTON_ZL; + CONTPRStringToValue["VPAD_BUTTON_ZR"] = CONTRPS_VPAD_BUTTON_ZR; + CONTPRStringToValue["VPAD_BUTTON_L"] = CONTRPS_VPAD_BUTTON_L; + CONTPRStringToValue["VPAD_BUTTON_R"] = CONTRPS_VPAD_BUTTON_R; + CONTPRStringToValue["VPAD_BUTTON_PLUS"] = CONTRPS_VPAD_BUTTON_PLUS; + CONTPRStringToValue["VPAD_BUTTON_MINUS"] = CONTRPS_VPAD_BUTTON_MINUS; + CONTPRStringToValue["VPAD_BUTTON_HOME"] = CONTRPS_VPAD_BUTTON_HOME; + CONTPRStringToValue["VPAD_BUTTON_SYNC"] = CONTRPS_VPAD_BUTTON_SYNC; + CONTPRStringToValue["VPAD_BUTTON_STICK_R"] = CONTRPS_VPAD_BUTTON_STICK_R; + CONTPRStringToValue["VPAD_BUTTON_STICK_L"] = CONTRPS_VPAD_BUTTON_STICK_L; + + /* + CONTPRStringToValue["VPAD_STICK_R_EMULATION_LEFT"] = CONTRPS_VPAD_STICK_R_EMULATION_LEFT; + CONTPRStringToValue["VPAD_STICK_R_EMULATION_RIGHT"] = CONTRPS_VPAD_STICK_R_EMULATION_RIGHT; + CONTPRStringToValue["VPAD_STICK_R_EMULATION_UP"] = CONTRPS_VPAD_STICK_R_EMULATION_UP; + CONTPRStringToValue["VPAD_STICK_R_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_R_EMULATION_DOWN; + CONTPRStringToValue["VPAD_STICK_L_EMULATION_LEFT"] = CONTRPS_VPAD_STICK_L_EMULATION_LEFT; + CONTPRStringToValue["VPAD_STICK_L_EMULATION_RIGHT"] = CONTRPS_VPAD_STICK_L_EMULATION_RIGHT; + CONTPRStringToValue["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP; + CONTPRStringToValue["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN;*/ + + CONTPRStringToValue["VPAD_L_STICK_UP"] = DEF_L_STICK_UP; + CONTPRStringToValue["VPAD_L_STICK_DOWN"] = DEF_L_STICK_DOWN; + CONTPRStringToValue["VPAD_L_STICK_LEFT"] = DEF_L_STICK_LEFT; + CONTPRStringToValue["VPAD_L_STICK_RIGHT"] = DEF_L_STICK_RIGHT; + + CONTPRStringToValue["VPAD_R_STICK_UP"] = DEF_R_STICK_UP; + CONTPRStringToValue["VPAD_R_STICK_DOWN"] = DEF_R_STICK_DOWN; + CONTPRStringToValue["VPAD_R_STICK_LEFT"] = DEF_R_STICK_LEFT; + CONTPRStringToValue["VPAD_R_STICK_RIGHT"] = DEF_R_STICK_RIGHT; + + CONTPRStringToValue["VPAD_L_STICK_X"] = CONTRPS_VPAD_BUTTON_L_STICK_X; + CONTPRStringToValue["VPAD_L_STICK_X_MINMAX"] = CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX; + CONTPRStringToValue["VPAD_L_STICK_Y"] = CONTRPS_VPAD_BUTTON_L_STICK_Y; + CONTPRStringToValue["VPAD_L_STICK_Y_MINMAX"] = CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX; + CONTPRStringToValue["VPAD_R_STICK_X"] = CONTRPS_VPAD_BUTTON_R_STICK_X; + CONTPRStringToValue["VPAD_R_STICK_X_MINMAX"] = CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX; + CONTPRStringToValue["VPAD_R_STICK_Y"] = CONTRPS_VPAD_BUTTON_R_STICK_Y; + CONTPRStringToValue["VPAD_R_STICK_Y_MINMAX"] = CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX; + CONTPRStringToValue["VPAD_BUTTON_TV"] = CONTRPS_VPAD_BUTTON_TV; + + CONTPRStringToValue["DOUBLE_USE_BUTTON_ACTIVATOR"] = CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR, + CONTPRStringToValue["INPUT_FILTER"] = CONTRPS_INPUT_FILTER; + + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_1_PRESSED"] = CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_2_PRESSED"] = CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_3_PRESSED"] = CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_4_PRESSED"] = CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_5_PRESSED"] = CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_1_RELEASED"] = CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_2_RELEASED"] = CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_3_RELEASED"] = CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_4_RELEASED"] = CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED; + CONTPRStringToValueSingle["DOUBLE_USE_BUTTON_5_RELEASED"] = CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED; + + CONTPRStringToValueSingle["BUF_SIZE"] = CONTRPS_BUF_SIZE; + CONTPRStringToValueSingle["DPAD_MODE"] = CONTRPS_DPAD_MODE; + CONTPRStringToValueSingle["DPAD_MASK"] = CONTRPS_DPAD_MASK; + CONTPRStringToValueSingle["VPAD_L_STICK_X_DEADZONE"] = CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE; + CONTPRStringToValueSingle["VPAD_L_STICK_Y_DEADZONE"] = CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE; + CONTPRStringToValueSingle["VPAD_R_STICK_X_DEADZONE"] = CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE; + CONTPRStringToValueSingle["VPAD_R_STICK_Y_DEADZONE"] = CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE; + CONTPRStringToValueSingle["VPAD_L_STICK_X_INVERT"] = CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT; + CONTPRStringToValueSingle["VPAD_L_STICK_Y_INVERT"] = CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT; + CONTPRStringToValueSingle["VPAD_R_STICK_X_INVERT"] = CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT; + CONTPRStringToValueSingle["VPAD_R_STICK_Y_INVERT"] = CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT; + CONTPRStringToValueSingle["DOUBLE_USE"] = CONTRPS_DOUBLE_USE; + CONTPRStringToValueSingle["PAD_COUNT"] = CONTRPS_PAD_COUNT; + + + mouseLeftValues["LEFT_CLICK"] = CONTRPS_VPAD_BUTTON_LEFT; + mouseLeftValues["RIGHT_CLICK"] = CONTRPS_VPAD_BUTTON_RIGHT; + mouseLeftValues["EMULATED_STICK"] = CONTRPS_MOUSE_STICK; + + + presetGCValues["GC_BUTTON_A"] = HID_GC_BUTTON_A; + presetGCValues["GC_BUTTON_B"] = HID_GC_BUTTON_B; + presetGCValues["GC_BUTTON_X"] = HID_GC_BUTTON_X; + presetGCValues["GC_BUTTON_Y"] = HID_GC_BUTTON_Y; + presetGCValues["GC_BUTTON_LEFT"] = HID_GC_BUTTON_LEFT; + presetGCValues["GC_BUTTON_RIGHT"] = HID_GC_BUTTON_RIGHT; + presetGCValues["GC_BUTTON_DOWN"] = HID_GC_BUTTON_DOWN; + presetGCValues["GC_BUTTON_UP"] = HID_GC_BUTTON_UP; + presetGCValues["GC_BUTTON_START"] = HID_GC_BUTTON_START; + presetGCValues["GC_BUTTON_Z"] = HID_GC_BUTTON_Z; + presetGCValues["GC_BUTTON_L"] = HID_GC_BUTTON_L; + presetGCValues["GC_BUTTON_R"] = HID_GC_BUTTON_R; + + presetDS3Values["DS3_BUTTON_CROSS"] = HID_DS3_BUTTON_CROSS; + presetDS3Values["DS3_BUTTON_CIRCLE"] = HID_DS3_BUTTON_CIRCLE; + presetDS3Values["DS3_BUTTON_SQUARE"] = HID_DS3_BUTTON_SQUARE; + presetDS3Values["DS3_BUTTON_TRIANGLE"] = HID_DS3_BUTTON_TRIANGLE; + + presetDS3Values["DS3_BUTTON_L1"] = HID_DS3_BUTTON_L1; + presetDS3Values["DS3_BUTTON_L2"] = HID_DS3_BUTTON_L2; + presetDS3Values["DS3_BUTTON_L3"] = HID_DS3_BUTTON_L3; + presetDS3Values["DS3_BUTTON_R1"] = HID_DS3_BUTTON_R1; + presetDS3Values["DS3_BUTTON_R2"] = HID_DS3_BUTTON_R2; + presetDS3Values["DS3_BUTTON_R3"] = HID_DS3_BUTTON_R3; + + presetDS3Values["DS3_BUTTON_SELECT"] = HID_DS3_BUTTON_SELECT; + presetDS3Values["DS3_BUTTON_START"] = HID_DS3_BUTTON_START; + presetDS3Values["DS3_BUTTON_LEFT"] = HID_DS3_BUTTON_LEFT; + presetDS3Values["DS3_BUTTON_RIGHT"] = HID_DS3_BUTTON_RIGHT; + presetDS3Values["DS3_BUTTON_UP"] = HID_DS3_BUTTON_UP; + presetDS3Values["DS3_BUTTON_DOWN"] = HID_DS3_BUTTON_DOWN; + presetDS3Values["DS3_BUTTON_GUIDE"] = HID_DS3_BUTTON_GUIDE; + + presetDS4Values["DS4_BUTTON_CROSS"] = HID_DS4_BUTTON_CROSS; + presetDS4Values["DS4_BUTTON_CIRCLE"] = HID_DS4_BUTTON_CIRCLE; + presetDS4Values["DS4_BUTTON_SQUARE"] = HID_DS4_BUTTON_SQUARE; + presetDS4Values["DS4_BUTTON_TRIANGLE"] = HID_DS4_BUTTON_TRIANGLE; + + presetDS4Values["DS4_BUTTON_L1"] = HID_DS4_BUTTON_L1; + presetDS4Values["DS4_BUTTON_L2"] = HID_DS4_BUTTON_L2; + presetDS4Values["DS4_BUTTON_L3"] = HID_DS4_BUTTON_L3; + presetDS4Values["DS4_BUTTON_R1"] = HID_DS4_BUTTON_R1; + presetDS4Values["DS4_BUTTON_R2"] = HID_DS4_BUTTON_R2; + presetDS4Values["DS4_BUTTON_R3"] = HID_DS4_BUTTON_R3; + + presetDS4Values["DS4_BUTTON_SHARE"] = HID_DS4_BUTTON_SHARE; + presetDS4Values["DS4_BUTTON_OPTIONS"] = HID_DS4_BUTTON_OPTIONS; + presetDS4Values["DS4_BUTTON_DPAD_TYPE"] = HID_DS4_BUTTON_DPAD_TYPE; + + presetDS4Values["DS4_BUTTON_DPAD_N"] = HID_DS4_BUTTON_DPAD_N; + presetDS4Values["DS4_BUTTON_DPAD_NE"] = HID_DS4_BUTTON_DPAD_NE; + presetDS4Values["DS4_BUTTON_DPAD_E"] = HID_DS4_BUTTON_DPAD_E; + presetDS4Values["DS4_BUTTON_DPAD_SE"] = HID_DS4_BUTTON_DPAD_SE; + presetDS4Values["DS4_BUTTON_DPAD_S"] = HID_DS4_BUTTON_DPAD_S; + presetDS4Values["DS4_BUTTON_DPAD_SW"] = HID_DS4_BUTTON_DPAD_SW; + presetDS4Values["DS4_BUTTON_DPAD_W"] = HID_DS4_BUTTON_DPAD_W; + presetDS4Values["DS4_BUTTON_DPAD_NW"] = HID_DS4_BUTTON_DPAD_NW; + presetDS4Values["DS4_BUTTON_DPAD_NEUTRAL"] = HID_DS4_BUTTON_DPAD_NEUTRAL; + + presetDS4Values["DS4_BUTTON_GUIDE"] = HID_DS4_BUTTON_GUIDE; + presetDS4Values["DS4_BUTTON_T_PAD_CLICK"] = HID_DS4_BUTTON_T_PAD_CLICK; + + presetKeyboardValues["KEYBOARD_SHIFT"] = HID_KEYBOARD_BUTTON_SHIFT; + presetKeyboardValues["KEYBOARD_A"] = HID_KEYBOARD_BUTTON_A; + presetKeyboardValues["KEYBOARD_B"] = HID_KEYBOARD_BUTTON_B; + presetKeyboardValues["KEYBOARD_C"] = HID_KEYBOARD_BUTTON_C; + presetKeyboardValues["KEYBOARD_D"] = HID_KEYBOARD_BUTTON_D; + presetKeyboardValues["KEYBOARD_E"] = HID_KEYBOARD_BUTTON_E; + presetKeyboardValues["KEYBOARD_F"] = HID_KEYBOARD_BUTTON_F; + presetKeyboardValues["KEYBOARD_G"] = HID_KEYBOARD_BUTTON_G; + presetKeyboardValues["KEYBOARD_H"] = HID_KEYBOARD_BUTTON_H; + presetKeyboardValues["KEYBOARD_I"] = HID_KEYBOARD_BUTTON_I; + presetKeyboardValues["KEYBOARD_J"] = HID_KEYBOARD_BUTTON_J; + presetKeyboardValues["KEYBOARD_K"] = HID_KEYBOARD_BUTTON_K; + presetKeyboardValues["KEYBOARD_L"] = HID_KEYBOARD_BUTTON_L; + presetKeyboardValues["KEYBOARD_M"] = HID_KEYBOARD_BUTTON_M; + presetKeyboardValues["KEYBOARD_N"] = HID_KEYBOARD_BUTTON_N; + presetKeyboardValues["KEYBOARD_O"] = HID_KEYBOARD_BUTTON_O; + presetKeyboardValues["KEYBOARD_P"] = HID_KEYBOARD_BUTTON_P; + presetKeyboardValues["KEYBOARD_Q"] = HID_KEYBOARD_BUTTON_Q; + presetKeyboardValues["KEYBOARD_R"] = HID_KEYBOARD_BUTTON_R; + presetKeyboardValues["KEYBOARD_S"] = HID_KEYBOARD_BUTTON_S; + presetKeyboardValues["KEYBOARD_T"] = HID_KEYBOARD_BUTTON_T; + presetKeyboardValues["KEYBOARD_U"] = HID_KEYBOARD_BUTTON_U; + presetKeyboardValues["KEYBOARD_V"] = HID_KEYBOARD_BUTTON_V; + presetKeyboardValues["KEYBOARD_W"] = HID_KEYBOARD_BUTTON_W; + presetKeyboardValues["KEYBOARD_X"] = HID_KEYBOARD_BUTTON_X; + presetKeyboardValues["KEYBOARD_Y"] = HID_KEYBOARD_BUTTON_Y; + presetKeyboardValues["KEYBOARD_Z"] = HID_KEYBOARD_BUTTON_Z; + presetKeyboardValues["KEYBOARD_F1"] = HID_KEYBOARD_BUTTON_F1; + presetKeyboardValues["KEYBOARD_F2"] = HID_KEYBOARD_BUTTON_F2; + presetKeyboardValues["KEYBOARD_F3"] = HID_KEYBOARD_BUTTON_F3; + presetKeyboardValues["KEYBOARD_F4"] = HID_KEYBOARD_BUTTON_F4; + presetKeyboardValues["KEYBOARD_F5"] = HID_KEYBOARD_BUTTON_F5; + presetKeyboardValues["KEYBOARD_F6"] = HID_KEYBOARD_BUTTON_F6; + presetKeyboardValues["KEYBOARD_F7"] = HID_KEYBOARD_BUTTON_F7; + presetKeyboardValues["KEYBOARD_F8"] = HID_KEYBOARD_BUTTON_F8; + presetKeyboardValues["KEYBOARD_F9"] = HID_KEYBOARD_BUTTON_F9; + presetKeyboardValues["KEYBOARD_F10"] = HID_KEYBOARD_BUTTON_F10; + presetKeyboardValues["KEYBOARD_F11"] = HID_KEYBOARD_BUTTON_F11; + presetKeyboardValues["KEYBOARD_F12"] = HID_KEYBOARD_BUTTON_F12; + presetKeyboardValues["KEYBOARD_1"] = HID_KEYBOARD_BUTTON_1; + presetKeyboardValues["KEYBOARD_2"] = HID_KEYBOARD_BUTTON_2; + presetKeyboardValues["KEYBOARD_3"] = HID_KEYBOARD_BUTTON_3; + presetKeyboardValues["KEYBOARD_4"] = HID_KEYBOARD_BUTTON_4; + presetKeyboardValues["KEYBOARD_5"] = HID_KEYBOARD_BUTTON_5; + presetKeyboardValues["KEYBOARD_6"] = HID_KEYBOARD_BUTTON_6; + presetKeyboardValues["KEYBOARD_7"] = HID_KEYBOARD_BUTTON_7; + presetKeyboardValues["KEYBOARD_8"] = HID_KEYBOARD_BUTTON_8; + presetKeyboardValues["KEYBOARD_9"] = HID_KEYBOARD_BUTTON_9; + presetKeyboardValues["KEYBOARD_0"] = HID_KEYBOARD_BUTTON_0; + + presetKeyboardValues["KEYBOARD_RETURN"] = HID_KEYBOARD_BUTTON_RETURN; + presetKeyboardValues["KEYBOARD_ESCAPE"] = HID_KEYBOARD_BUTTON_ESCAPE; + presetKeyboardValues["KEYBOARD_DELETE"] = HID_KEYBOARD_BUTTON_DELETE; + presetKeyboardValues["KEYBOARD_TAB"] = HID_KEYBOARD_BUTTON_TAB; + presetKeyboardValues["KEYBOARD_SPACEBAR"] = HID_KEYBOARD_BUTTON_SPACEBAR; + presetKeyboardValues["KEYBOARD_CAPSLOCK"] = HID_KEYBOARD_BUTTON_CAPSLOCK; + presetKeyboardValues["KEYBOARD_PRINTSCREEN"] = HID_KEYBOARD_BUTTON_PRINTSCREEN; + presetKeyboardValues["KEYBOARD_SCROLLLOCK"] = HID_KEYBOARD_BUTTON_SCROLLLOCK; + presetKeyboardValues["KEYBOARD_PAUSE"] = HID_KEYBOARD_BUTTON_PAUSE; + presetKeyboardValues["KEYBOARD_INSERT"] = HID_KEYBOARD_BUTTON_INSERT; + presetKeyboardValues["KEYBOARD_HOME"] = HID_KEYBOARD_BUTTON_HOME; + presetKeyboardValues["KEYBOARD_PAGEUP"] = HID_KEYBOARD_BUTTON_PAGEUP; + presetKeyboardValues["KEYBOARD_PAGEDOWN"] = HID_KEYBOARD_BUTTON_PAGEDOWN; + presetKeyboardValues["KEYBOARD_DELETEFORWARD"] = HID_KEYBOARD_BUTTON_DELETEFORWARD; + presetKeyboardValues["KEYBOARD_LEFT_CONTROL"] = HID_KEYBOARD_BUTTON_LEFT_CONTROL; + presetKeyboardValues["KEYBOARD_LEFT_ALT"] = HID_KEYBOARD_BUTTON_LEFT_ALT; + presetKeyboardValues["KEYBOARD_RIGHT_CONTROL"] = HID_KEYBOARD_BUTTON_RIGHT_CONTROL; + presetKeyboardValues["KEYBOARD_RIGHT_SHIFT"] = HID_KEYBOARD_BUTTON_RIGHT_SHIFT; + presetKeyboardValues["KEYBOARD_RIGHT_ALT"] = HID_KEYBOARD_BUTTON_RIGHT_ALT; + presetKeyboardValues["KEYBOARD_END"] = HID_KEYBOARD_BUTTON_END; + + presetKeyboardValues["KEYBOARD_LEFT"] = HID_KEYBOARD_BUTTON_LEFT; + presetKeyboardValues["KEYBOARD_RIGHT"] = HID_KEYBOARD_BUTTON_RIGHT; + presetKeyboardValues["KEYBOARD_DOWN"] = HID_KEYBOARD_BUTTON_DOWN; + presetKeyboardValues["KEYBOARD_UP"] = HID_KEYBOARD_BUTTON_UP; + + presetKeyboardValues["KEYBOARD_KEYPAD_1"] = HID_KEYBOARD_KEYPAD_BUTTON_1; + presetKeyboardValues["KEYBOARD_KEYPAD_2"] = HID_KEYBOARD_KEYPAD_BUTTON_2; + presetKeyboardValues["KEYBOARD_KEYPAD_3"] = HID_KEYBOARD_KEYPAD_BUTTON_3; + presetKeyboardValues["KEYBOARD_KEYPAD_4"] = HID_KEYBOARD_KEYPAD_BUTTON_4; + presetKeyboardValues["KEYBOARD_KEYPAD_5"] = HID_KEYBOARD_KEYPAD_BUTTON_5; + presetKeyboardValues["KEYBOARD_KEYPAD_6"] = HID_KEYBOARD_KEYPAD_BUTTON_6; + presetKeyboardValues["KEYBOARD_KEYPAD_7"] = HID_KEYBOARD_KEYPAD_BUTTON_7; + presetKeyboardValues["KEYBOARD_KEYPAD_8"] = HID_KEYBOARD_KEYPAD_BUTTON_8; + presetKeyboardValues["KEYBOARD_KEYPAD_9"] = HID_KEYBOARD_KEYPAD_BUTTON_9; + presetKeyboardValues["KEYBOARD_KEYPAD_0"] = HID_KEYBOARD_KEYPAD_BUTTON_0; + presetKeyboardValues["KEYBOARD_KEYPAD_NUMLOCK"] = HID_KEYBOARD_KEYPAD_BUTTON_NUMLOCK; + presetKeyboardValues["KEYBOARD_KEYPAD_MINUS"] = HID_KEYBOARD_KEYPAD_BUTTON_MINUS; + presetKeyboardValues["KEYBOARD_KEYPAD_PLUS"] = HID_KEYBOARD_KEYPAD_BUTTON_PLUS; + + presetValues["VPAD_L_STICK"] = DEF_L_STICK; + presetValues["VPAD_R_STICK"] = DEF_R_STICK; + + presetValues["DPAD_NORMAL"] = CONTRPDM_Normal; + presetValues["DPAD_HAT"] = CONTRPDM_Hat; + presetValues["DPAD_ABSOLUTE_2VALUES"] = CONTRPDM_Absolute_2Values; + presetValues["TRUE"] = 1; + presetValues["YES"] = 1; + presetValues["ON"] = 1; + presetValues["FALSE"] = 0; + presetValues["NO"] = 0; + presetValues["OFF"] = 0; + + presetSticks["GC_STICK_L_X"] = HID_GC_STICK_L_X; + presetSticks["GC_STICK_L_Y"] = HID_GC_STICK_L_Y; + presetSticks["GC_STICK_R_X"] = HID_GC_STICK_R_X; + presetSticks["GC_STICK_R_Y"] = HID_GC_STICK_R_Y; + + presetSticks["DS3_STICK_L_X"] = HID_DS3_STICK_L_X; + presetSticks["DS3_STICK_L_Y"] = HID_DS3_STICK_L_Y; + presetSticks["DS3_STICK_R_X"] = HID_DS3_STICK_R_X; + presetSticks["DS3_STICK_R_Y"] = HID_DS3_STICK_R_Y; + + presetSticks["DS4_STICK_L_X"] = HID_DS4_STICK_L_X; + presetSticks["DS4_STICK_L_Y"] = HID_DS4_STICK_L_Y; + presetSticks["DS4_STICK_R_X"] = HID_DS4_STICK_R_X; + presetSticks["DS4_STICK_R_Y"] = HID_DS4_STICK_R_Y; + + presetSticks["GC_DPAD_MODE"] = HID_GC_BUTTON_DPAD_TYPE; + presetSticks["DS3_DPAD_MODE"] = HID_DS3_BUTTON_DPAD_TYPE; + presetSticks["DS4_DPAD_MODE"] = HID_DS4_BUTTON_DPAD_TYPE; + + gGamePadValuesToCONTRPSString["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_X"] = CONTRPS_VPAD_BUTTON_X; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_Y"] = CONTRPS_VPAD_BUTTON_Y; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_LEFT"] = CONTRPS_VPAD_BUTTON_LEFT; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_RIGHT"] = CONTRPS_VPAD_BUTTON_RIGHT; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_UP"] = CONTRPS_VPAD_BUTTON_UP; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_DOWN"] = CONTRPS_VPAD_BUTTON_DOWN; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_ZL"] = CONTRPS_VPAD_BUTTON_ZL; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_ZR"] = CONTRPS_VPAD_BUTTON_ZR; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_L"] = CONTRPS_VPAD_BUTTON_L; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_R"] = CONTRPS_VPAD_BUTTON_R; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_PLUS"] = CONTRPS_VPAD_BUTTON_PLUS; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_MINUS"] = CONTRPS_VPAD_BUTTON_MINUS; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_HOME"] = CONTRPS_VPAD_BUTTON_HOME; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_SYNC"] = CONTRPS_VPAD_BUTTON_SYNC; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_STICK_R"] = CONTRPS_VPAD_BUTTON_STICK_R; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_STICK_L"] = CONTRPS_VPAD_BUTTON_STICK_L; + gGamePadValuesToCONTRPSString["VPAD_BUTTON_TV"] = CONTRPS_VPAD_BUTTON_TV; + + /* + //Todo: think about removing it + gGamePadValuesToCONTRPSString["VPAD_STICK_R_EMULATION_LEFT"] = CONTRPS_VPAD_STICK_R_EMULATION_LEFT; + gGamePadValuesToCONTRPSString["VPAD_STICK_R_EMULATION_RIGHT"] = CONTRPS_VPAD_STICK_R_EMULATION_RIGHT; + gGamePadValuesToCONTRPSString["VPAD_STICK_R_EMULATION_UP"] = CONTRPS_VPAD_STICK_R_EMULATION_UP; + gGamePadValuesToCONTRPSString["VPAD_STICK_R_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_R_EMULATION_DOWN; + gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_LEFT"] = CONTRPS_VPAD_STICK_L_EMULATION_LEFT; + gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_RIGHT"] = CONTRPS_VPAD_STICK_L_EMULATION_RIGHT; + gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_UP"] = CONTRPS_VPAD_STICK_L_EMULATION_UP; + gGamePadValuesToCONTRPSString["VPAD_STICK_L_EMULATION_DOWN"] = CONTRPS_VPAD_STICK_L_EMULATION_DOWN; + */ + } + + const u8 * getValuesForPreset(std::map values,std::string possibleValue); + + bool setIfValueIsPreset(std::map values,std::string possibleValue,int slot,int keyslot); + bool setIfValueIsAControllerPresetEx(std::string value,int slot,int keyslot); + +}; +#endif diff --git a/controller_patcher.c b/controller_patcher.c index c25fc97..a776cad 100644 --- a/controller_patcher.c +++ b/controller_patcher.c @@ -1,8 +1,27 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ + #include #include #include #include +#include #include "controller_patcher.h" +#include "pad_const.h" #include "dynamic_libs/os_functions.h" #include "dynamic_libs/sys_functions.h" #include "dynamic_libs/syshid_functions.h" @@ -11,357 +30,352 @@ #include "cp_retain_vars.h" #include "utils/logger.h" +static u32 last_emulatedSticks = 0; +static u32 last_button_hold = 0; + void setConfigValue(u8 * dest, u8 first, u8 second){ dest[0] = first; dest[1] = second; } +void init_button_remapping(){ + if(HID_DEBUG) log_printf("init_button_remapping! called! \n"); + if(!gButtonRemappingConfigDone){ + if(HID_DEBUG) log_printf("init_button_remapping! Remapping is running! \n"); + gButtonRemappingConfigDone = 1; + memset(gGamePadValues,0,sizeof(gGamePadValues)); // Init / Invalid everything + + gGamePadValues[CONTRPS_VPAD_BUTTON_A] = VPAD_BUTTON_A; + gGamePadValues[CONTRPS_VPAD_BUTTON_B] = VPAD_BUTTON_B; + gGamePadValues[CONTRPS_VPAD_BUTTON_X] = VPAD_BUTTON_X; + gGamePadValues[CONTRPS_VPAD_BUTTON_Y] = VPAD_BUTTON_Y; + gGamePadValues[CONTRPS_VPAD_BUTTON_LEFT] = VPAD_BUTTON_LEFT; + gGamePadValues[CONTRPS_VPAD_BUTTON_RIGHT] = VPAD_BUTTON_RIGHT; + gGamePadValues[CONTRPS_VPAD_BUTTON_UP] = VPAD_BUTTON_UP; + gGamePadValues[CONTRPS_VPAD_BUTTON_DOWN] = VPAD_BUTTON_DOWN; + gGamePadValues[CONTRPS_VPAD_BUTTON_ZL] = VPAD_BUTTON_ZL; + gGamePadValues[CONTRPS_VPAD_BUTTON_ZR] = VPAD_BUTTON_ZR; + gGamePadValues[CONTRPS_VPAD_BUTTON_L] = VPAD_BUTTON_L; + gGamePadValues[CONTRPS_VPAD_BUTTON_R] = VPAD_BUTTON_R; + gGamePadValues[CONTRPS_VPAD_BUTTON_PLUS] = VPAD_BUTTON_PLUS; + gGamePadValues[CONTRPS_VPAD_BUTTON_MINUS] = VPAD_BUTTON_MINUS; + gGamePadValues[CONTRPS_VPAD_BUTTON_HOME] = VPAD_BUTTON_HOME; + gGamePadValues[CONTRPS_VPAD_BUTTON_SYNC] = VPAD_BUTTON_SYNC; + gGamePadValues[CONTRPS_VPAD_BUTTON_STICK_R] = VPAD_BUTTON_STICK_R; + gGamePadValues[CONTRPS_VPAD_BUTTON_STICK_L] = VPAD_BUTTON_STICK_L; + gGamePadValues[CONTRPS_VPAD_BUTTON_TV] = VPAD_BUTTON_TV; + + + //TODO: Sticks + + /* + I can't think of any reason why somebody should need this? I think its just confusing. + + gGamePadValues[CONTRPS_VPAD_STICK_R_EMULATION_LEFT] = VPAD_STICK_R_EMULATION_LEFT; + gGamePadValues[CONTRPS_VPAD_STICK_R_EMULATION_RIGHT] = VPAD_STICK_R_EMULATION_RIGHT; + gGamePadValues[CONTRPS_VPAD_STICK_R_EMULATION_UP] = VPAD_STICK_R_EMULATION_UP; + gGamePadValues[CONTRPS_VPAD_STICK_R_EMULATION_DOWN] = VPAD_STICK_R_EMULATION_DOWN; + gGamePadValues[CONTRPS_VPAD_STICK_L_EMULATION_LEFT] = VPAD_STICK_L_EMULATION_LEFT; + gGamePadValues[CONTRPS_VPAD_STICK_L_EMULATION_RIGHT] = VPAD_STICK_L_EMULATION_RIGHT; + gGamePadValues[CONTRPS_VPAD_STICK_L_EMULATION_UP] = VPAD_STICK_L_EMULATION_UP; + gGamePadValues[CONTRPS_VPAD_STICK_L_EMULATION_DOWN] = VPAD_STICK_L_EMULATION_DOWN; + + */ + } +} + void init_config_controller(){ InitOSFunctionPointers(); + InitSocketFunctionPointers(); InitSysHIDFunctionPointers(); InitVPadFunctionPointers(); InitPadScoreFunctionPointers(); - - if(!config_done){ - config_done = 1; + if(HID_DEBUG) log_printf("init_config_controller called! \n"); + if(!gConfig_done){ + if(HID_DEBUG) log_printf("init_config_controller! Config is running! \n"); + gConfig_done = 1; memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // Init / Invalid everything - memset(config_controller_list,-1,sizeof(config_controller_list)); // Init / Invalid everything + memset(config_controller_list,0,sizeof(config_controller_list)); // Init / Invalid everything memset(config_controller_data_ptr,0,sizeof(config_controller_data_ptr)); // Init / Invalid everything - config_controller_list[CONTRPD_GC] = HID_LIST_GC; - config_controller_list[CONTRPD_DS3] = HID_LIST_DS3; - config_controller_list[CONTRPD_DS4] = HID_LIST_DS4; - config_controller_list[CONTRPD_SP2600] = HID_LIST_SP2600; - config_controller_list[CONTRPD_KEYBOARD] = HID_LIST_KEYBOARD; - config_controller_list[CONTRPD_PS2_ADAPTER] = HID_LIST_PS2_ADAPTER; - config_controller_list[CONTRPD_POKKEN] = HID_LIST_POKKEN; - config_controller_list[CONTRPD_PS2] = HID_LIST_PS2; - //config_controller_list[CONTRPD_YOUR_DEVICE] = HID_LIST_YOUR_DEVICE; + gGamePadSlot = gHIDRegisteredDevices; + u32 gGamePadHid = getNextDeviceSlot(); + if(HID_DEBUG) log_printf("gGamePadHid %s slot: %d\n",byte_to_binary(gGamePadHid),gGamePadSlot); + + gMouseSlot = gHIDRegisteredDevices; + gHID_LIST_MOUSE = getNextDeviceSlot(); + if(HID_DEBUG) log_printf("gHID_LIST_MOUSE %s slot: %d\n",byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); + + u32 gc_slot = gHIDRegisteredDevices; + u32 gc_hid = getNextDeviceSlot(); + gHID_LIST_GC = gc_hid; + gHID_SLOT_GC = gc_slot; + if(HID_DEBUG) log_printf("gHID_LIST_GC %s slot: %d\n",byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); + + u32 ds3_slot = gHIDRegisteredDevices; + u32 ds3_hid = getNextDeviceSlot(); + gHID_LIST_DS3 = ds3_hid; + + if(HID_DEBUG) log_printf("gHID_LIST_DS3 %s slot: %d\n",byte_to_binary(gHID_LIST_DS3),ds3_slot); + + u32 ds4_slot = gHIDRegisteredDevices; + u32 ds4_hid = getNextDeviceSlot(); + + if(HID_DEBUG) log_printf("ds4_hid %s slot: %d\n",byte_to_binary(ds4_hid),ds4_slot); + + /* + u32 snes_slot = gHIDRegisteredDevices; + u32 snes_hid = getNextDeviceSlot(); + + log_printf("snes_hid %s slot: %d\n",byte_to_binary(snes_hid),snes_slot);*/ + + u32 keyboard_slot = gHIDRegisteredDevices; + u32 keyboard_hid = getNextDeviceSlot(); + gHID_LIST_KEYBOARD = keyboard_hid; + gHID_SLOT_KEYBOARD = keyboard_slot; + + if(HID_DEBUG) log_printf("gHID_LIST_KEYBOARD %s slot: %d\n",byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); + + config_controller_list[gc_slot] = gHID_LIST_GC; + config_controller_list[ds3_slot] = gHID_LIST_DS3; + config_controller_list[ds4_slot] = ds4_hid; + config_controller_list[keyboard_slot] = gHID_LIST_KEYBOARD; //Set data for each pad. Currenty 4 Pads for each device support. May need other extra treatment - config_controller_data_ptr[CONTRPD_GC][0] = (u32)&(gHID_Devices[CONTRPD_GC]).pad_data[0]; //GC Pad Port 1 - config_controller_data_ptr[CONTRPD_GC][1] = (u32)&(gHID_Devices[CONTRPD_GC]).pad_data[1]; //GC Pad Port 2 - config_controller_data_ptr[CONTRPD_GC][2] = (u32)&(gHID_Devices[CONTRPD_GC]).pad_data[2]; //GC Pad Port 3 - config_controller_data_ptr[CONTRPD_GC][3] = (u32)&(gHID_Devices[CONTRPD_GC]).pad_data[3]; //GC Pad Port 4 - config_controller_data_ptr[CONTRPD_DS3][0] = (u32)&(gHID_Devices[CONTRPD_DS3]).pad_data[0]; - config_controller_data_ptr[CONTRPD_DS4][0] = (u32)&(gHID_Devices[CONTRPD_DS4]).pad_data[0]; - config_controller_data_ptr[CONTRPD_SP2600][0] = (u32)&(gHID_Devices[CONTRPD_SP2600]).pad_data[0]; - config_controller_data_ptr[CONTRPD_KEYBOARD][0] = (u32)&(gHID_Devices[CONTRPD_KEYBOARD]).pad_data[0]; - config_controller_data_ptr[CONTRPD_PS2_ADAPTER][0] = (u32)&(gHID_Devices[CONTRPD_PS2_ADAPTER]).pad_data[0]; - config_controller_data_ptr[CONTRPD_POKKEN][0] = (u32)&(gHID_Devices[CONTRPD_POKKEN]).pad_data[0]; - config_controller_data_ptr[CONTRPD_PS2][0] = (u32)&(gHID_Devices[CONTRPD_PS2]).pad_data[0]; + config_controller_data_ptr[gHID_SLOT_GC][0] = (u32)&(gHID_Devices[gHID_SLOT_GC]).pad_data[0]; //GC Pad Port 1 + config_controller_data_ptr[gHID_SLOT_GC][1] = (u32)&(gHID_Devices[gHID_SLOT_GC]).pad_data[1]; //GC Pad Port 2 + config_controller_data_ptr[gHID_SLOT_GC][2] = (u32)&(gHID_Devices[gHID_SLOT_GC]).pad_data[2]; //GC Pad Port 3 + config_controller_data_ptr[gHID_SLOT_GC][3] = (u32)&(gHID_Devices[gHID_SLOT_GC]).pad_data[3]; //GC Pad Port 4 + config_controller_data_ptr[ds3_slot][0] = (u32)&(gHID_Devices[ds3_slot]).pad_data[0]; + config_controller_data_ptr[ds3_slot][1] = (u32)&(gHID_Devices[ds3_slot]).pad_data[0]; + config_controller_data_ptr[ds3_slot][2] = (u32)&(gHID_Devices[ds3_slot]).pad_data[0]; + config_controller_data_ptr[ds3_slot][3] = (u32)&(gHID_Devices[ds3_slot]).pad_data[0]; + config_controller_data_ptr[ds4_slot][0] = (u32)&(gHID_Devices[ds4_slot]).pad_data[0]; + config_controller_data_ptr[ds4_slot][1] = (u32)&(gHID_Devices[ds4_slot]).pad_data[0]; + config_controller_data_ptr[ds4_slot][2] = (u32)&(gHID_Devices[ds4_slot]).pad_data[0]; + config_controller_data_ptr[ds4_slot][3] = (u32)&(gHID_Devices[ds4_slot]).pad_data[0]; + config_controller_data_ptr[gHID_SLOT_KEYBOARD][0] = (u32)&(gHID_Devices[gHID_SLOT_KEYBOARD]).pad_data[0]; + config_controller_data_ptr[gHID_SLOT_KEYBOARD][1] = (u32)&(gHID_Devices[gHID_SLOT_KEYBOARD]).pad_data[0]; + config_controller_data_ptr[gHID_SLOT_KEYBOARD][2] = (u32)&(gHID_Devices[gHID_SLOT_KEYBOARD]).pad_data[0]; + config_controller_data_ptr[gHID_SLOT_KEYBOARD][3] = (u32)&(gHID_Devices[gHID_SLOT_KEYBOARD]).pad_data[0]; + + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //! GamePad + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_VID], 0xAF,0xFE); + setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_PID], 0xAA,0xAA); + + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //! Mouse + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VID], 0xAF,0xFE); + setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_PID], 0xAA,0xAB); + + setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_LEFT], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZR); + setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_RIGHT], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_R); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! GC-Adapter //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VID], 0x05,0x7e); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_PID], 0x03,0x37); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_A], 0x01,HID_GC_BUTTON_A); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_B], 0x01,HID_GC_BUTTON_B); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_X], 0x01,HID_GC_BUTTON_X); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_Y], 0x01,HID_GC_BUTTON_Y); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Normal); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_LEFT], 0x01,HID_GC_BUTTON_LEFT); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_RIGHT], 0x01,HID_GC_BUTTON_RIGHT); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_DOWN], 0x01,HID_GC_BUTTON_DOWN); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_UP], 0x01,HID_GC_BUTTON_UP); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_MINUS], 0x02,HID_GC_BUTTON_START); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L], 0x07,HID_GC_BUTTON_L); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R], 0x08,HID_GC_BUTTON_R); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_PLUS], 0x02,HID_GC_BUTTON_START); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_ZL], 0x07,HID_GC_BUTTON_L); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_ZR], 0x08,HID_GC_BUTTON_R); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_STICK_L], 0x01,HID_GC_BUTTON_A); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_STICK_R], 0x01,HID_GC_BUTTON_B); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_DOUBLE_USE], CONTROLLER_PATCHER_VALUE_SET,CONTROLLER_PATCHER_GC_DOUBLE_USE); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_DOUBLE_USE_BUTTON], 0x02,HID_GC_BUTTON_Z); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_GC_PAD_COUNT); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VID], 0x05,0x7e); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_PID], 0x03,0x37); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_A], HID_GC_BUTTON_A[0], HID_GC_BUTTON_A[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_B], HID_GC_BUTTON_B[0], HID_GC_BUTTON_B[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_X], HID_GC_BUTTON_X[0], HID_GC_BUTTON_X[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_Y], HID_GC_BUTTON_Y[0], HID_GC_BUTTON_Y[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_GC_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_LEFT], HID_GC_BUTTON_LEFT[0], HID_GC_BUTTON_LEFT[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_RIGHT], HID_GC_BUTTON_RIGHT[0], HID_GC_BUTTON_RIGHT[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_DOWN], HID_GC_BUTTON_DOWN[0], HID_GC_BUTTON_DOWN[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_UP], HID_GC_BUTTON_UP[0], HID_GC_BUTTON_UP[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_MINUS], HID_GC_BUTTON_START[0], HID_GC_BUTTON_START[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L], HID_GC_BUTTON_L[0], HID_GC_BUTTON_L[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R], HID_GC_BUTTON_R[0], HID_GC_BUTTON_R[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_PLUS], HID_GC_BUTTON_START[0], HID_GC_BUTTON_START[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_ZL], HID_GC_BUTTON_L[0], HID_GC_BUTTON_L[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_ZR], HID_GC_BUTTON_R[0], HID_GC_BUTTON_R[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_STICK_L], HID_GC_BUTTON_A[0], HID_GC_BUTTON_A[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_STICK_R], HID_GC_BUTTON_B[0], HID_GC_BUTTON_B[1]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE], CONTROLLER_PATCHER_VALUE_SET, CONTROLLER_PATCHER_GC_DOUBLE_USE); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR], HID_GC_BUTTON_Z[0], HID_GC_BUTTON_Z[1]); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x03,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET,0x09); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x1E,0xE5); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x04,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET,0x09); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x18,0xE4); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x05,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x26,0xE1); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET,0x09); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x06,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x1A,0xDB); - setConfigValue((u8*)&config_controller[CONTRPD_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET,0x09); + //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is pressed + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_MINUS); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_L); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_R); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_L); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_R); + + //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is released + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_PLUS); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZL); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZR); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_A); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_B); + + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_GC_PAD_COUNT); + + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_GC_STICK_L_X[STICK_CONF_BYTE],HID_GC_STICK_L_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_L_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_GC_STICK_L_X[STICK_CONF_MIN], HID_GC_STICK_L_X[STICK_CONF_MAX]); + + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_GC_STICK_L_Y[STICK_CONF_BYTE],HID_GC_STICK_L_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_L_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_GC_STICK_L_Y[STICK_CONF_MIN], HID_GC_STICK_L_Y[STICK_CONF_MAX]); + + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_GC_STICK_R_X[STICK_CONF_BYTE],HID_GC_STICK_R_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_R_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_GC_STICK_R_X[STICK_CONF_MIN], HID_GC_STICK_R_X[STICK_CONF_MAX]); + + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_GC_STICK_R_Y[STICK_CONF_BYTE],HID_GC_STICK_R_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_R_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_GC_STICK_R_Y[STICK_CONF_MIN], HID_GC_STICK_R_Y[STICK_CONF_MAX]); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! DS3 //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VID], 0x05,0x4c); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_PID], 0x02,0x68); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET,128); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_A], 0x03,HID_DS3_BUTTON_CIRCLE); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_B], 0x03,HID_DS3_BUTTON_CROSS); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_X], 0x03,HID_DS3_BUTTON_TRIANGLE); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_Y], 0x03,HID_DS3_BUTTON_SQUARE); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Normal); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_LEFT], 0x02,HID_DS3_BUTTON_LEFT); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_RIGHT], 0x02,HID_DS3_BUTTON_RIGHT); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_DOWN], 0x02,HID_DS3_BUTTON_DOWN); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_UP], 0x02,HID_DS3_BUTTON_UP); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_PLUS], 0x02,HID_DS3_BUTTON_START); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_MINUS], 0x02,HID_DS3_BUTTON_SELECT); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L], 0x03,HID_DS3_BUTTON_L1); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R], 0x03,HID_DS3_BUTTON_R1); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_ZL], 0x03,HID_DS3_BUTTON_L2); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_ZR], 0x03,HID_DS3_BUTTON_R2); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_STICK_L], 0x02,HID_DS3_BUTTON_L3); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_STICK_R], 0x02,HID_DS3_BUTTON_R3); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_HOME], 0x04,HID_DS3_BUTTON_GUIDE); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_PAD_COUNT); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VID], 0x05,0x4c); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_PID], 0x02,0x68); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET,128); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_A], HID_DS3_BUTTON_CIRCLE[0], HID_DS3_BUTTON_CIRCLE[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_B], HID_DS3_BUTTON_CROSS[0], HID_DS3_BUTTON_CROSS[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_X], HID_DS3_BUTTON_TRIANGLE[0],HID_DS3_BUTTON_TRIANGLE[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_Y], HID_DS3_BUTTON_SQUARE[0], HID_DS3_BUTTON_SQUARE[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_LEFT], HID_DS3_BUTTON_LEFT[0], HID_DS3_BUTTON_LEFT[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_RIGHT], HID_DS3_BUTTON_RIGHT[0], HID_DS3_BUTTON_RIGHT[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_DOWN], HID_DS3_BUTTON_DOWN[0], HID_DS3_BUTTON_DOWN[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_UP], HID_DS3_BUTTON_UP[0], HID_DS3_BUTTON_UP[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_DS3_BUTTON_START[0], HID_DS3_BUTTON_START[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_DS3_BUTTON_SELECT[0], HID_DS3_BUTTON_SELECT[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L], HID_DS3_BUTTON_L1[0], HID_DS3_BUTTON_L1[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R], HID_DS3_BUTTON_R1[0], HID_DS3_BUTTON_R1[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_ZL], HID_DS3_BUTTON_L2[0], HID_DS3_BUTTON_L2[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_ZR], HID_DS3_BUTTON_R2[0], HID_DS3_BUTTON_R2[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_DS3_BUTTON_L3[0], HID_DS3_BUTTON_L3[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_DS3_BUTTON_R3[0], HID_DS3_BUTTON_R3[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS3_BUTTON_GUIDE[0], HID_DS3_BUTTON_GUIDE[1]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_PAD_COUNT); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x06,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x06); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x07,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x06); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,0x01); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x08,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x08); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x09,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,0x01); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x06); - setConfigValue((u8*)&config_controller[CONTRPD_DS3][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x00,0xFF); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS3_STICK_L_X[STICK_CONF_BYTE],HID_DS3_STICK_L_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_L_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS3_STICK_L_X[STICK_CONF_MIN], HID_DS3_STICK_L_X[STICK_CONF_MAX]); + + + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS3_STICK_L_Y[STICK_CONF_BYTE],HID_DS3_STICK_L_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_L_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS3_STICK_L_Y[STICK_CONF_MIN], HID_DS3_STICK_L_Y[STICK_CONF_MAX]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_STICK_L_Y[STICK_CONF_INVERT]); + + + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_DS3_STICK_R_X[STICK_CONF_BYTE],HID_DS3_STICK_R_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_R_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_DS3_STICK_R_X[STICK_CONF_MIN], HID_DS3_STICK_R_X[STICK_CONF_MAX]); + + + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_DS3_STICK_R_Y[STICK_CONF_BYTE],HID_DS3_STICK_R_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_R_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_DS3_STICK_R_Y[STICK_CONF_MIN], HID_DS3_STICK_R_Y[STICK_CONF_MAX]); + setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,HID_DS3_STICK_R_Y[STICK_CONF_INVERT]); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! DS4 //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VID], 0x05,0x4c); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_PID], 0x05,0xc4); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET,128); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_A], 0x05,HID_DS4_BUTTON_CIRCLE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_B], 0x05,HID_DS4_BUTTON_CROSS); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_X], 0x05,HID_DS4_BUTTON_TRIANGLE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_Y], 0x05,HID_DS4_BUTTON_SQUARE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Hat); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,0x0F); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_N], 0x05,HID_DS4_BUTTON_DPAD_N); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_NE], 0x05,HID_DS4_BUTTON_DPAD_NE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_E], 0x05,HID_DS4_BUTTON_DPAD_E); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_SE], 0x05,HID_DS4_BUTTON_DPAD_SE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_S], 0x05,HID_DS4_BUTTON_DPAD_S); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_SW], 0x05,HID_DS4_BUTTON_DPAD_SW); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_W], 0x05,HID_DS4_BUTTON_DPAD_W); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_NW], 0x05,HID_DS4_BUTTON_DPAD_NW); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], 0x05,HID_DS4_BUTTON_DPAD_NEUTRAL); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_PLUS], 0x06,HID_DS4_BUTTON_OPTIONS); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_MINUS], 0x06,HID_DS4_BUTTON_SHARE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L], 0x06,HID_DS4_BUTTON_L1); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R], 0x06,HID_DS4_BUTTON_R1); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_ZL], 0x06,HID_DS4_BUTTON_L2); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_ZR], 0x06,HID_DS4_BUTTON_R2); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_STICK_L], 0x06,HID_DS4_BUTTON_L3); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_STICK_R], 0x06,HID_DS4_BUTTON_R3); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_HOME], 0x07,HID_DS4_BUTTON_GUIDE); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_DS4_PAD_COUNT); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VID], 0x05,0x4c); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PID], 0x05,0xc4); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET,128); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_A], HID_DS4_BUTTON_CIRCLE[0], HID_DS4_BUTTON_CIRCLE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_B], HID_DS4_BUTTON_CROSS[0], HID_DS4_BUTTON_CROSS[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_X], HID_DS4_BUTTON_TRIANGLE[0], HID_DS4_BUTTON_TRIANGLE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_Y], HID_DS4_BUTTON_SQUARE[0], HID_DS4_BUTTON_SQUARE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_N], HID_DS4_BUTTON_DPAD_N[0], HID_DS4_BUTTON_DPAD_N[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NE], HID_DS4_BUTTON_DPAD_NE[0], HID_DS4_BUTTON_DPAD_NE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_E], HID_DS4_BUTTON_DPAD_E[0], HID_DS4_BUTTON_DPAD_E[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_SE], HID_DS4_BUTTON_DPAD_SE[0], HID_DS4_BUTTON_DPAD_SE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_S], HID_DS4_BUTTON_DPAD_S[0], HID_DS4_BUTTON_DPAD_S[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_SW], HID_DS4_BUTTON_DPAD_SW[0], HID_DS4_BUTTON_DPAD_SW[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_W], HID_DS4_BUTTON_DPAD_W[0], HID_DS4_BUTTON_DPAD_W[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NW], HID_DS4_BUTTON_DPAD_NW[0], HID_DS4_BUTTON_DPAD_NW[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], HID_DS4_BUTTON_DPAD_NEUTRAL[0], HID_DS4_BUTTON_DPAD_NEUTRAL[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_DS4_BUTTON_OPTIONS[0], HID_DS4_BUTTON_OPTIONS[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_DS4_BUTTON_SHARE[0], HID_DS4_BUTTON_SHARE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L], HID_DS4_BUTTON_L1[0], HID_DS4_BUTTON_L1[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R], HID_DS4_BUTTON_R1[0], HID_DS4_BUTTON_R1[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_ZL], HID_DS4_BUTTON_L2[0], HID_DS4_BUTTON_L2[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_ZR], HID_DS4_BUTTON_R2[0], HID_DS4_BUTTON_R2[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_DS4_BUTTON_L3[0], HID_DS4_BUTTON_L3[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_DS4_BUTTON_R3[0], HID_DS4_BUTTON_R3[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS4_BUTTON_GUIDE[0], HID_DS4_BUTTON_GUIDE[1]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_DS4_PAD_COUNT); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x01,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x06); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x02,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,0x01); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x05); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x03,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x07); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x04,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,0x01); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE],CONTROLLER_PATCHER_VALUE_SET,0x09); - setConfigValue((u8*)&config_controller[CONTRPD_DS4][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x00,0xFF); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Saitek P2600 - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS4_STICK_L_X[STICK_CONF_BYTE],HID_DS4_STICK_L_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS4_STICK_L_X[STICK_CONF_MIN], HID_DS4_STICK_L_X[STICK_CONF_MAX]); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VID], 0x06,0xA3); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_PID], 0x5F,0x0D); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_A], 0x05,HID_SP2600_BUTTON_3); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_B], 0x05,HID_SP2600_BUTTON_2); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_X], 0x05,HID_SP2600_BUTTON_4); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_Y], 0x05,HID_SP2600_BUTTON_1); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Hat); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,0xF0); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_N], 0x06,HID_SP2600_BUTTON_DPAD_N); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_NE], 0x06,HID_SP2600_BUTTON_DPAD_NE); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_E], 0x06,HID_SP2600_BUTTON_DPAD_E); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_SE], 0x06,HID_SP2600_BUTTON_DPAD_SE); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_S], 0x06,HID_SP2600_BUTTON_DPAD_S); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_SW], 0x06,HID_SP2600_BUTTON_DPAD_SW); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_W], 0x06,HID_SP2600_BUTTON_DPAD_W); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_NW], 0x06,HID_SP2600_BUTTON_DPAD_NW); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], 0x06,HID_SP2600_BUTTON_DPAD_NEUTRAL); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_PLUS], 0x06,HID_SP2600_BUTTON_FPS); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_MINUS], 0x06,HID_SP2600_BUTTON_Analog); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_L], 0x05,HID_SP2600_BUTTON_5); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_R], 0x05,HID_SP2600_BUTTON_6); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_ZL], 0x05,HID_SP2600_BUTTON_7); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_ZR], 0x05,HID_SP2600_BUTTON_8); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_SP2600_PAD_COUNT); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS4_STICK_L_Y[STICK_CONF_BYTE],HID_DS4_STICK_L_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS4_STICK_L_Y[STICK_CONF_MIN], HID_DS4_STICK_L_Y[STICK_CONF_MAX]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,HID_DS4_STICK_L_Y[STICK_CONF_INVERT]); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x01,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x02,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x03,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x04,0x80); - setConfigValue((u8*)&config_controller[CONTRPD_SP2600][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x00,0xFF); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! PS2_ADAPTER - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_DS4_STICK_R_X[STICK_CONF_BYTE],HID_DS4_STICK_R_X[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_R_X[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_DS4_STICK_R_X[STICK_CONF_MIN], HID_DS4_STICK_R_X[STICK_CONF_MAX]); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VID], 0x0e,0x8f); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_PID], 0x00,0x03); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_A], 0x05,HID_PS2_ADAPTER_BUTTON_CIRCLE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_B], 0x05,HID_PS2_ADAPTER_BUTTON_CROSS); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_X], 0x05,HID_PS2_ADAPTER_BUTTON_TRIANGLE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_Y], 0x05,HID_PS2_ADAPTER_BUTTON_SQUARE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_PLUS], 0x06,HID_PS2_ADAPTER_BUTTON_START); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_MINUS], 0x06,HID_PS2_ADAPTER_BUTTON_SELECT); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_L], 0x06,HID_PS2_ADAPTER_BUTTON_L1); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_R], 0x06,HID_PS2_ADAPTER_BUTTON_R1); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_ZL], 0x06,HID_PS2_ADAPTER_BUTTON_L2); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_ZR], 0x06,HID_PS2_ADAPTER_BUTTON_R2); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Hat); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,0x0F); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_N], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_N); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_NE], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_NE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_E], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_E); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_SE], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_SE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_S], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_S); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_SW], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_SW); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_W], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_W); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_NW], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_NW); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], 0x05,HID_PS2_ADAPTER_BUTTON_DPAD_NEUTRAL); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_PS2_ADAPTER_PAD_COUNT); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x02,0x7B); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x03,0x84); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x00,0x7B); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x01,0x84); - setConfigValue((u8*)&config_controller[CONTRPD_PS2_ADAPTER][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x00,0xFF); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Pokken - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VID], 0x0f,0x0d); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_PID], 0x00,0x92); - - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_A], 0x05,HID_POKKEN_BUTTON_1); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_B], 0x05,HID_POKKEN_BUTTON_2); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_X], 0x05,HID_POKKEN_BUTTON_3); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_Y], 0x05,HID_POKKEN_BUTTON_4); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_PLUS], 0x06,HID_POKKEN_BUTTON_5); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_MINUS], 0x06,HID_POKKEN_BUTTON_6); - - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_L], 0x06,HID_POKKEN_BUTTON_7); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_R], 0x06,HID_POKKEN_BUTTON_8); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_ZL], 0x06,HID_POKKEN_BUTTON_9); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_ZR], 0x06,HID_POKKEN_BUTTON_10); - - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Hat); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,0x0F); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_N], 0x05,HID_POKKEN_BUTTON_DPAD_N); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_NE], 0x05,HID_POKKEN_BUTTON_DPAD_NE); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_E], 0x05,HID_POKKEN_BUTTON_DPAD_E); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_SE], 0x05,HID_POKKEN_BUTTON_DPAD_SE); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_S], 0x05,HID_POKKEN_BUTTON_DPAD_S); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_SW], 0x05,HID_POKKEN_BUTTON_DPAD_SW); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_W], 0x05,HID_POKKEN_BUTTON_DPAD_W); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_NW], 0x05,HID_POKKEN_BUTTON_DPAD_NW); - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], 0x05,HID_POKKEN_BUTTON_DPAD_NEUTRAL); - - setConfigValue((u8*)&config_controller[CONTRPD_POKKEN][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_POKKEN_PAD_COUNT); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! PS2 - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VID], 0x08,0x10); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_PID], 0x00,0x01); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_A], 0x05,HID_PS2_BUTTON_CIRCLE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_B], 0x05,HID_PS2_BUTTON_CROSS); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_X], 0x05,HID_PS2_BUTTON_TRIANGLE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_Y], 0x05,HID_PS2_BUTTON_SQUARE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_PLUS], 0x06,HID_PS2_BUTTON_START); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_MINUS], 0x06,HID_PS2_BUTTON_SELECT); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_L], 0x06,HID_PS2_BUTTON_L1); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_R], 0x06,HID_PS2_BUTTON_R1); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_ZL], 0x06,HID_PS2_BUTTON_L2); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_ZR], 0x06,HID_PS2_BUTTON_R2); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Hat); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET,0x0F); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_N], 0x05,HID_PS2_BUTTON_DPAD_N); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_NE], 0x05,HID_PS2_BUTTON_DPAD_NE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_E], 0x05,HID_PS2_BUTTON_DPAD_E); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_SE], 0x05,HID_PS2_BUTTON_DPAD_SE); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_S], 0x05,HID_PS2_BUTTON_DPAD_S); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_SW], 0x05,HID_PS2_BUTTON_DPAD_SW); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_W], 0x05,HID_PS2_BUTTON_DPAD_W); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_NW], 0x05,HID_PS2_BUTTON_DPAD_NW); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], 0x05,HID_PS2_BUTTON_DPAD_NEUTRAL); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_PS2_PAD_COUNT); - - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_L_STICK_X], 0x03,0x7B); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_L_STICK_Y], 0x04,0x84); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_R_STICK_X], 0x02,0x7B); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], 0x00,0xFF); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_R_STICK_Y], 0x01,0x84); - setConfigValue((u8*)&config_controller[CONTRPD_PS2][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], 0x00,0xFF); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_DS4_STICK_R_Y[STICK_CONF_BYTE],HID_DS4_STICK_R_Y[STICK_CONF_DEFAULT]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_R_Y[STICK_CONF_DEADZONE]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_DS4_STICK_R_Y[STICK_CONF_MIN], HID_DS4_STICK_R_Y[STICK_CONF_MAX]); + setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET,HID_DS4_STICK_R_Y[STICK_CONF_INVERT]); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Keyboard //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VID], 0xAF,0xFE); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_PID], 0xAA,0xAC); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_A], 0x00,HID_KEYBOARD_BUTTON_E); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_B], 0x00,HID_KEYBOARD_BUTTON_Q); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_X], 0x00,HID_KEYBOARD_BUTTON_SPACEBAR); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_Y], 0x00,HID_KEYBOARD_BUTTON_R); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Normal); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_LEFT], 0x00,HID_KEYBOARD_BUTTON_LEFT); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_RIGHT], 0x00,HID_KEYBOARD_BUTTON_RIGHT); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_DOWN], 0x00,HID_KEYBOARD_BUTTON_DOWN); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_UP], 0x00,HID_KEYBOARD_BUTTON_UP); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_PLUS], 0x00,HID_KEYBOARD_BUTTON_RETURN); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_MINUS], 0x00,HID_KEYBOARD_KEYPAD_BUTTON_MINUS); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L], 0x00,HID_KEYBOARD_BUTTON_V); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R], 0x00,HID_KEYBOARD_BUTTON_B); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_ZL], 0x00,HID_KEYBOARD_BUTTON_SHIFT); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_ZR], 0x00,HID_KEYBOARD_BUTTON_N); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_L], 0x00,HID_KEYBOARD_BUTTON_F); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_R], 0x00,HID_KEYBOARD_BUTTON_TAB); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_A], 0x00,HID_KEYBOARD_BUTTON_E); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_B], 0x00,HID_KEYBOARD_BUTTON_Q); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_X], 0x00,HID_KEYBOARD_BUTTON_SPACE); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_Y], 0x00,HID_KEYBOARD_BUTTON_R); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Normal); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_LEFT], 0x00,HID_KEYBOARD_BUTTON_LEFT); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_RIGHT], 0x00,HID_KEYBOARD_BUTTON_RIGHT); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_DOWN], 0x00,HID_KEYBOARD_BUTTON_DOWN); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_UP], 0x00,HID_KEYBOARD_BUTTON_UP); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_PLUS], 0x00,HID_KEYBOARD_BUTTON_ENTER); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_MINUS], 0x00,HID_KEYBOARD_BUTTON_MINUS); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_L], 0x00,HID_KEYBOARD_BUTTON_V); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_R], 0x00,HID_KEYBOARD_BUTTON_B); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_ZL], 0x00,HID_KEYBOARD_BUTTON_SHIFT); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_ZR], 0x00,HID_KEYBOARD_BUTTON_N); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_L], 0x00,HID_KEYBOARD_BUTTON_F); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_R], 0x00,HID_KEYBOARD_BUTTON_TAB); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_KEYBOARD_BUTTON_A,HID_KEYBOARD_BUTTON_D); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_KEYBOARD_BUTTON_W,HID_KEYBOARD_BUTTON_S); - setConfigValue((u8*)&config_controller[CONTRPD_KEYBOARD][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_KEYBOARD_PAD_COUNT); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_KEYBOARD_KEYPAD_BUTTON_4,HID_KEYBOARD_KEYPAD_BUTTON_6); + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_KEYBOARD_KEYPAD_BUTTON_8,HID_KEYBOARD_KEYPAD_BUTTON_2); + + setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_KEYBOARD_PAD_COUNT); + + /*for(int i = 0;i< gHIDMaxDevices;i++){ + for(int j = 0;j< CONTRPS_MAX_VALUE;j++){ + //log_printf("%d %d %02X%02X\n",i,j,config_controller[i][j][0],config_controller[i][j][1]); + } + //log_print("------------------\n"); + }*/ }else{ - log_print("Config already done!\n"); + if(HID_DEBUG) log_print("Config already done!\n"); } if(!gHIDSetupDone){ HIDSetup(); @@ -374,6 +388,7 @@ void init_config_controller(){ } void deinit_config_controller(){ + if(HID_DEBUG) log_printf("deinit_config_controller! called! \n"); if(gHIDSetupDone){ if(gHIDAttached) HIDDelClient(&gHIDClient); gHIDAttached = 0; @@ -382,45 +397,61 @@ void deinit_config_controller(){ //HIDTeardown(); // seems to result in a creash sometimes log_printf("Exit\n"); } + gButtonRemappingConfigDone = 0; + last_button_hold = 0; + last_emulatedSticks = 0; } +u32 getNextDeviceSlot(){ + if(gHIDRegisteredDevices >= gHIDMaxDevices){ + return 1 << 17; + } + return (1 << (gHIDRegisteredDevices++)); +} #define SWAP16(x) ((x>>8) | ((x&0xFF)<<8)) #define SWAP8(x) ((x>>4) | ((x&0xF)<<4)) int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) { if(attach){ - log_printf("vid %04x\n", SWAP16(p_device->vid)); - log_printf("pid %04x\n", SWAP16(p_device->pid)); - log_printf("interface index %02x\n", p_device->interface_index); - log_printf("sub class %02x\n", p_device->sub_class); - log_printf("protocol %02x\n", p_device->protocol); - log_printf("max packet in %02x\n", p_device->max_packet_size_rx); - log_printf("max packet out %02x\n", p_device->max_packet_size_tx); + log_printf("vid %04x pid %04x connected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); + if(HID_DEBUG) log_printf("interface index %02x\n", p_device->interface_index); + if(HID_DEBUG) log_printf("sub class %02x\n", p_device->sub_class); + if(HID_DEBUG) log_printf("protocol %02x\n", p_device->protocol); + if(HID_DEBUG) log_printf("max packet in %02x\n", p_device->max_packet_size_rx); + if(HID_DEBUG) log_printf("max packet out %02x\n", p_device->max_packet_size_tx); + } + if(!attach){ + log_printf("vid %04x pid %04x disconnected\n", SWAP16(p_device->vid),SWAP16(p_device->pid)); } int device = 0; int deviceSlot = 0; - for(int i = 0;i< CONTRPD_MAX_VALUE;i++){ + for(int i = 0;i< gHIDMaxDevices;i++){ u16 vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1]; u16 pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1]; if(SWAP16(p_device->vid) == vid && SWAP16(p_device->pid) == pid){ device = config_controller_list[i]; deviceSlot = i; + //log_printf("Found device: device: %s slot: %d\n",byte_to_binary(device),deviceSlot); break; } } + if ((p_device->sub_class == 1) && (p_device->protocol == 1)) { //Keyboard - device = HID_LIST_KEYBOARD; - deviceSlot = CONTRPD_KEYBOARD; + device = gHID_LIST_KEYBOARD; + deviceSlot = gHID_SLOT_KEYBOARD; + //log_printf("Found Keyboard: device: %s slot: %d\n",byte_to_binary(device),deviceSlot); }else if ((p_device->sub_class == 1) && (p_device->protocol == 2)){ // MOUSE - device = HID_LIST_MOUSE; + device = gHID_LIST_MOUSE; + deviceSlot = gMouseSlot; + //log_printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device),deviceSlot); } if(device){ if(attach){ int bufSize = 64; - if(device != HID_LIST_MOUSE && config_controller[deviceSlot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){ + if(device != gHID_LIST_MOUSE && config_controller[deviceSlot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){ bufSize = config_controller[deviceSlot][CONTRPS_BUF_SIZE][1]; } unsigned char *buf = memalign(64,bufSize); @@ -431,9 +462,11 @@ int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) usr->transfersize = p_device->max_packet_size_rx; usr->handle = p_device->handle; - if(device != HID_LIST_MOUSE ){ + + memset(&gHID_Devices[deviceSlot],0,sizeof(HID_DEVICE_DATA)); + + if(device != gHID_LIST_MOUSE ){ usr->deviceSlot = deviceSlot; - memset(&gHID_Devices[deviceSlot],0,sizeof(HID_DEVICE_DATA)); gHID_Devices[deviceSlot].user_data = usr; }else{ memset(&gHID_Mouse,0,sizeof(HID_Mouse)); @@ -443,19 +476,22 @@ int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) gHIDAttached |= device; gHIDCurrentDevice |= device; - log_printf("%08X(%d) attached!\n",device,deviceSlot); + if(HID_DEBUG) log_printf("%08X(%d) attached!\n",device,deviceSlot); - if(device == HID_LIST_GC){ // GC PAD + if(device == gHID_LIST_GC){ // GC PAD buf[0] = 0x13; HIDWrite(p_device->handle, usr->buf, 1, my_gc_write_cb, usr); - }else if (device == HID_LIST_MOUSE){ + }else if (device == gHID_LIST_MOUSE){ + HIDSetProtocol(p_device->handle, p_device->interface_index, 0, 0, 0); + //HIDGetDescriptor(p_device->handle,0x22,0x00,0,my_buf,512,my_foo_cb,NULL); + HIDSetIdle(p_device->handle,p_device->interface_index,1,NULL,NULL); gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; HIDRead(p_device->handle, buf, p_device->max_packet_size_rx, my_ms_read_cb, usr); - }else if (device == HID_LIST_KEYBOARD){ + }else if (device == gHID_LIST_KEYBOARD){ HIDSetProtocol(p_device->handle, p_device->interface_index, 1, 0, 0); HIDSetIdle(p_device->handle, p_device->interface_index, 0, 0, 0); HIDRead(p_device->handle, buf, p_device->max_packet_size_rx, my_read_cb, usr); - }else if (device == HID_LIST_DS3){ + }else if (device == gHID_LIST_DS3){ HIDSetProtocol(p_device->handle, p_device->interface_index, 1, 0, 0); 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); @@ -467,7 +503,7 @@ int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) }else{ my_cb_user * user_data = NULL; - if(device == HID_LIST_MOUSE){ + if(device == gHID_LIST_MOUSE){ user_data = (my_cb_user *) gHID_Mouse.user_data; }else{ user_data = (my_cb_user *) gHID_Devices[deviceSlot].user_data; @@ -482,12 +518,13 @@ int my_attach_cb(HIDClient *p_client, HIDDevice *p_device, unsigned int attach) } gHIDAttached &= ~device; gHIDCurrentDevice &= ~device; - if (device == HID_LIST_MOUSE){ + if (device == gHID_LIST_MOUSE){ gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; } - log_printf("%d(%d) detached!\n",device,deviceSlot); + //log_printf("%d(%d) detached!\n",device,deviceSlot); } }else{ + log_print("HID-Device currently not supported!\n"); } return HID_DEVICE_DETACH; @@ -523,23 +560,25 @@ u32 getEmulatedSticks(VPADData * buffer){ } if((buffer->rstick.x > 0.5f) || (buffer->rstick.x > 0.1f && !r_y_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_RIGHT; + emulatedSticks |= VPAD_STICK_R_EMULATION_RIGHT; } if((buffer->rstick.x < -0.5f) || (buffer->rstick.x < -0.1f && !r_y_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_LEFT; + emulatedSticks |= VPAD_STICK_R_EMULATION_LEFT; } if((buffer->rstick.y > 0.5f) || (buffer->rstick.y > 0.1f && !r_x_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_UP; + emulatedSticks |= VPAD_STICK_R_EMULATION_UP; } if((buffer->rstick.y < -0.5f) || (buffer->rstick.y < -0.1f && !r_x_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_DOWN; + emulatedSticks |= VPAD_STICK_R_EMULATION_DOWN; } return emulatedSticks; } -static u32 last_emulatedSticks = 0; - -void setControllerDataFromHID(VPADData * buffer,int hid){ +void setControllerDataFromHID(VPADData * buffer,HID_DEVICE_LIST hid_devices){ + int hid = 0; + if(hid_devices == HID_ALL_CONNECTED_DEVICES){ + hid = gHIDCurrentDevice; + } int size = 0; HID_Data_Struct * data = getHIDDataAll(hid,&size); if(!data || !size || size < 0){ @@ -549,9 +588,20 @@ void setControllerDataFromHID(VPADData * buffer,int hid){ HID_Data_Struct data_cur; HID_Data_Struct data_last; - for(int i = 0;ibtns_r |= (last_emulatedSticks & (~emulatedSticks)); last_emulatedSticks = emulatedSticks; - checkMouseMode(data_cur,data_last); setTouch(data_cur,buffer); setLastData(data_cur,data_last); - if(data_last_ptr){ free(data_last_ptr); data_last_ptr = NULL; } } + + // Caculates a valid stick position + if(size){ + f32 max = 0.0f; + f32 mul = 0.0f; + if((max = (fabs(buffer->lstick.x)) + fabs(buffer->lstick.y)) > 1.414f){ + mul = 1.414f / max; + buffer->lstick.x *= mul; + buffer->lstick.y *= mul; + } + if((max = (fabs(buffer->rstick.x)) + fabs(buffer->rstick.y)) > 1.414f){ + mul = 1.414f / max; + buffer->rstick.x *= mul; + buffer->rstick.y *= mul; + } + if(buffer->lstick.x > 1.0f) buffer->lstick.x = 1.0f; + if(buffer->lstick.y > 1.0f) buffer->lstick.y = 1.0f; + if(buffer->lstick.x < -1.0f) buffer->lstick.x = -1.0f; + if(buffer->lstick.y < -1.0f) buffer->lstick.y = -1.0f; + + if(buffer->rstick.x > 1.0f) buffer->rstick.x = 1.0f; + if(buffer->rstick.y > 1.0f) buffer->rstick.y = 1.0f; + if(buffer->rstick.x < -1.0f) buffer->rstick.x = -1.0f; + if(buffer->rstick.y < -1.0f) buffer->rstick.y = -1.0f; + + } + if(data){ free(data); data = NULL; @@ -608,11 +683,170 @@ void setControllerDataFromHID(VPADData * buffer,int hid){ int current_rumblestatus = !!VPADBASEGetMotorOnRemainingCount(0); setRumble(hid,current_rumblestatus); + //log_printf("hold: %016X down: %016X release: %016X\n",buffer->btns_h,buffer->btns_d,buffer->btns_r); + //log_printf("new || hold: %016X down: %016X release: %016X \n",buffer->btns_h,buffer->btns_d,buffer->btns_r); } +void printButtons(VPADData * buffer){ + if(buffer->btns_d != 0){ + char output[100]; + output[0] = 0; + if((buffer->btns_d & VPAD_BUTTON_A) == VPAD_BUTTON_A){ + strcat(output,"A "); + } + if((buffer->btns_d & VPAD_BUTTON_B) == VPAD_BUTTON_B){ + strcat(output,"B "); + } + if((buffer->btns_d & VPAD_BUTTON_X) == VPAD_BUTTON_X){ + strcat(output,"X "); + } + if((buffer->btns_d & VPAD_BUTTON_Y) == VPAD_BUTTON_Y){ + strcat(output,"Y "); + } + if((buffer->btns_d & VPAD_BUTTON_L) == VPAD_BUTTON_L){ + strcat(output,"L "); + } + if((buffer->btns_d & VPAD_BUTTON_R) == VPAD_BUTTON_R){ + strcat(output,"R "); + } + if((buffer->btns_d & VPAD_BUTTON_ZR) == VPAD_BUTTON_ZR){ + strcat(output,"ZR "); + } + if((buffer->btns_d & VPAD_BUTTON_ZL) == VPAD_BUTTON_ZL){ + strcat(output,"ZL "); + } + if((buffer->btns_d & VPAD_BUTTON_LEFT) == VPAD_BUTTON_LEFT){ + strcat(output,"Left "); + } + if((buffer->btns_d & VPAD_BUTTON_RIGHT) == VPAD_BUTTON_RIGHT){ + strcat(output,"Right "); + } + if((buffer->btns_d & VPAD_BUTTON_UP) == VPAD_BUTTON_UP){ + strcat(output,"Up "); + } + if((buffer->btns_d & VPAD_BUTTON_DOWN) == VPAD_BUTTON_DOWN){ + strcat(output,"Down "); + } + if((buffer->btns_d & VPAD_BUTTON_PLUS) == VPAD_BUTTON_PLUS){ + strcat(output,"+ "); + } + if((buffer->btns_d & VPAD_BUTTON_MINUS) == VPAD_BUTTON_MINUS){ + strcat(output,"- "); + } + if((buffer->btns_d & VPAD_BUTTON_TV) == VPAD_BUTTON_TV){ + strcat(output,"TV "); + } + if((buffer->btns_d & VPAD_BUTTON_HOME) == VPAD_BUTTON_HOME){ + strcat(output,"HOME "); + } + if((buffer->btns_d & VPAD_BUTTON_STICK_L) == VPAD_BUTTON_STICK_L){ + strcat(output,"SL "); + } + if((buffer->btns_d & VPAD_BUTTON_STICK_R) == VPAD_BUTTON_STICK_R){ + strcat(output,"SR "); + } + if((buffer->btns_d & VPAD_STICK_R_EMULATION_LEFT) == VPAD_STICK_R_EMULATION_LEFT){ + strcat(output,"RE_Left "); + } + if((buffer->btns_d & VPAD_STICK_R_EMULATION_RIGHT) == VPAD_STICK_R_EMULATION_RIGHT){ + strcat(output,"RE_Right "); + } + if((buffer->btns_d & VPAD_STICK_R_EMULATION_UP) == VPAD_STICK_R_EMULATION_UP){ + strcat(output,"RE_Up "); + } + if((buffer->btns_d & VPAD_STICK_R_EMULATION_DOWN) == VPAD_STICK_R_EMULATION_DOWN){ + strcat(output,"RE_Down "); + } + if((buffer->btns_d & VPAD_STICK_L_EMULATION_LEFT) == VPAD_STICK_L_EMULATION_LEFT){ + strcat(output,"LE_Left "); + } + if((buffer->btns_d & VPAD_STICK_L_EMULATION_RIGHT) == VPAD_STICK_L_EMULATION_RIGHT){ + strcat(output,"LE_Right "); + } + if((buffer->btns_d & VPAD_STICK_L_EMULATION_UP) == VPAD_STICK_L_EMULATION_UP){ + strcat(output,"LE_Up "); + } + if((buffer->btns_d & VPAD_STICK_L_EMULATION_DOWN) == VPAD_STICK_L_EMULATION_DOWN){ + strcat(output,"LE_Down "); + } + + log_printf("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->lstick.x,buffer->lstick.y,buffer->rstick.x,buffer->rstick.y); + } +} + +void buttonRemapping(VPADData * buffer){ + VPADData new_data; + new_data.btns_h = 0; + + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_A, CONTRPS_VPAD_BUTTON_A); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_B, CONTRPS_VPAD_BUTTON_B); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_X, CONTRPS_VPAD_BUTTON_X); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_Y, CONTRPS_VPAD_BUTTON_Y); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_LEFT, CONTRPS_VPAD_BUTTON_LEFT); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_RIGHT, CONTRPS_VPAD_BUTTON_RIGHT); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_UP, CONTRPS_VPAD_BUTTON_UP); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_DOWN, CONTRPS_VPAD_BUTTON_DOWN); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_ZL, CONTRPS_VPAD_BUTTON_ZL); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_ZR, CONTRPS_VPAD_BUTTON_ZR); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_L, CONTRPS_VPAD_BUTTON_L); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_R, CONTRPS_VPAD_BUTTON_R); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_PLUS, CONTRPS_VPAD_BUTTON_PLUS); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_MINUS, CONTRPS_VPAD_BUTTON_MINUS); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_HOME, CONTRPS_VPAD_BUTTON_HOME); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_SYNC, CONTRPS_VPAD_BUTTON_SYNC); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_STICK_R, CONTRPS_VPAD_BUTTON_STICK_R); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_STICK_L, CONTRPS_VPAD_BUTTON_STICK_L); + setButtonRemappingData(buffer,&new_data,VPAD_BUTTON_TV, CONTRPS_VPAD_BUTTON_TV); + + + //No need to remap the emulated sticks. But we need to keep them + setHoldButtonData(buffer,&new_data,VPAD_STICK_L_EMULATION_LEFT,VPAD_STICK_L_EMULATION_LEFT); + setHoldButtonData(buffer,&new_data,VPAD_STICK_L_EMULATION_RIGHT,VPAD_STICK_L_EMULATION_RIGHT); + setHoldButtonData(buffer,&new_data,VPAD_STICK_L_EMULATION_UP,VPAD_STICK_L_EMULATION_UP); + setHoldButtonData(buffer,&new_data,VPAD_STICK_L_EMULATION_DOWN,VPAD_STICK_L_EMULATION_DOWN); + + setHoldButtonData(buffer,&new_data,VPAD_STICK_R_EMULATION_LEFT,VPAD_STICK_R_EMULATION_LEFT); + setHoldButtonData(buffer,&new_data,VPAD_STICK_R_EMULATION_RIGHT,VPAD_STICK_R_EMULATION_RIGHT); + setHoldButtonData(buffer,&new_data,VPAD_STICK_R_EMULATION_UP,VPAD_STICK_R_EMULATION_UP); + setHoldButtonData(buffer,&new_data,VPAD_STICK_R_EMULATION_DOWN,VPAD_STICK_R_EMULATION_DOWN); + + /* + setButtonRemappingData(buffer,&new_data,VPAD_STICK_R_EMULATION_LEFT, CONTRPS_VPAD_STICK_R_EMULATION_LEFT); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_R_EMULATION_RIGHT, CONTRPS_VPAD_STICK_R_EMULATION_RIGHT); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_R_EMULATION_UP, CONTRPS_VPAD_STICK_R_EMULATION_UP); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_R_EMULATION_DOWN, CONTRPS_VPAD_STICK_R_EMULATION_DOWN); + + setButtonRemappingData(buffer,&new_data,VPAD_STICK_L_EMULATION_LEFT, CONTRPS_VPAD_STICK_L_EMULATION_LEFT); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_L_EMULATION_RIGHT, CONTRPS_VPAD_STICK_L_EMULATION_RIGHT); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_L_EMULATION_UP, CONTRPS_VPAD_STICK_L_EMULATION_UP); + setButtonRemappingData(buffer,&new_data,VPAD_STICK_L_EMULATION_DOWN, CONTRPS_VPAD_STICK_L_EMULATION_DOWN);*/ + + u32 button_hold = new_data.btns_h; + + buffer->btns_h = button_hold; + buffer->btns_d = (button_hold & (~last_button_hold)); + buffer->btns_r = (last_button_hold & (~button_hold)); + + last_button_hold = button_hold; +} + +void setButtonRemappingData(VPADData * buffer, VPADData * new_data,u32 VPADButton, int CONTRPS_Value){ + u32 new_value = VPADButton; + + if(config_controller[gGamePadSlot][CONTRPS_Value][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //using new value! + new_value = gGamePadValues[config_controller[gGamePadSlot][CONTRPS_Value][1]]; + } + setHoldButtonData(buffer,new_data,VPADButton,new_value); +} + +void setHoldButtonData(VPADData * buffer, VPADData * new_data,u32 oldVPADButton,u32 newVPADButton){ + if((buffer->btns_h & oldVPADButton) == oldVPADButton){ + new_data->btns_h |= newVPADButton; + } +} int getDevice(int hid){ - for(int i = 0;i < CONTRPD_MAX_VALUE;i++){ + for(int i = 0;i < gHIDMaxDevices;i++){ if(hid & config_controller_list[i]){ return i; } @@ -625,11 +859,11 @@ int getDevice(int hid){ //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- int getActivePad(int hid){ - if(hid & HID_LIST_GC){ - if (!(((gHID_Devices[CONTRPD_GC].pad_data[0].hid_data[0] & 0x10) == 0) && ((gHID_Devices[CONTRPD_GC].pad_data[0].hid_data[0] & 0x22) != 0x22))) return 0; - if (!(((gHID_Devices[CONTRPD_GC].pad_data[1].hid_data[0] & 0x10) == 0) && ((gHID_Devices[CONTRPD_GC].pad_data[1].hid_data[0] & 0x22) != 0x22))) return 1; - if (!(((gHID_Devices[CONTRPD_GC].pad_data[2].hid_data[0] & 0x10) == 0) && ((gHID_Devices[CONTRPD_GC].pad_data[2].hid_data[0] & 0x22) != 0x22))) return 2; - if (!(((gHID_Devices[CONTRPD_GC].pad_data[3].hid_data[0] & 0x10) == 0) && ((gHID_Devices[CONTRPD_GC].pad_data[3].hid_data[0] & 0x22) != 0x22))) return 3; + if(hid & gHID_LIST_GC){ + if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].hid_data[0] & 0x22) != 0x22))) return 0; + if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].hid_data[0] & 0x22) != 0x22))) return 1; + if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[2].hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[2].hid_data[0] & 0x22) != 0x22))) return 2; + if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[3].hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[3].hid_data[0] & 0x22) != 0x22))) return 3; return -1; } return 0; @@ -646,34 +880,39 @@ void setRumble(int hid,int rumble){ HID_Data_Struct * getHIDDataAll(int hid,int * size){ *size = 0; int bit = 1; - for (int i = 0;i < CONTRPD_MAX_VALUE; i++){ + for (int i = 0;i < gHIDMaxDevices; i++){ *size += (hid & bit)>>i; bit <<= 1; } + //log_printf("Found %d devices! for hid: %s\n",*size,byte_to_binary(hid)); HID_Data_Struct * data = malloc(sizeof(HID_Data_Struct)*(*size)); if(!data) return NULL; int i = 0; //!Mouse always need extra treatment - if(hid & HID_LIST_MOUSE){ - unsigned char * src = (unsigned char *) &(gHID_Mouse.pad_data[getActivePad(HID_LIST_MOUSE)].data[0]); + if(hid & gHID_LIST_MOUSE){ + unsigned char * src = (unsigned char *) &(gHID_Mouse.pad_data[getActivePad(gHID_LIST_MOUSE)].data[0]); data[i].src = src; - data[i].hid = HID_LIST_MOUSE; + data[i].hid = gHID_LIST_MOUSE; i++; } - for(int j = 0;j < CONTRPD_MAX_VALUE;j++){ + for(int j = 0;j < gHIDMaxDevices;j++){ if(hid & config_controller_list[j]){ int pad = getActivePad(config_controller_list[j]); if(pad < 0){ //Not pad connected to adapter (*size)--; + //log_printf("Not active pads! New size %d\n",*size); continue; } data[i].hid = config_controller_list[j]; + //log_printf("data[%d].hid = %s(config_controller_list[%d])!\n",i,byte_to_binary(config_controller_list[j]),j); data[i].src = (u8*)&(((HID_Data *)config_controller_data_ptr[j][pad])->hid_data); + //log_printf("data[%d].src = %08X(config_controller_list[%d])!\n",i,data[i].src,j); if(!data[i].src){ (*size)--; + log_printf("src pointer == NULL!New size %d\n",*size); continue; } i++; @@ -688,17 +927,17 @@ int getPadCount(int hid){ if(config_controller[device][CONTRPS_PAD_COUNT][0] == CONTROLLER_PATCHER_VALUE_SET){ return config_controller[device][CONTRPS_PAD_COUNT][1]; } + log_printf("pad count: 0 for %s\n ",byte_to_binary(hid)); return 0; } - void checkMouseMode(HID_Data_Struct data,HID_Data_Struct data_last){ unsigned char * src = data.src; unsigned char * src_last = data_last.src; int hid = data.hid; - if(hid & HID_LIST_KEYBOARD){ + if(hid & gHID_LIST_KEYBOARD){ if(wasInKeyboard(src,HID_KEYBOARD_BUTTON_F1) && (wasInKeyboard(src,HID_KEYBOARD_BUTTON_F1) != wasInKeyboard(src_last,HID_KEYBOARD_BUTTON_F1))){ if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; @@ -718,22 +957,21 @@ void setLastData(HID_Data_Struct data,HID_Data_Struct data_last){ if(!src || !src_last) return; - if(hid & HID_LIST_MOUSE){ + if(hid & gHID_LIST_MOUSE){ memcpy(src_last,src,sizeof(HID_Mouse_Data)); } memcpy(src_last,src,HID_MAX_DATA_LENGTH_PER_PAD); } - HID_Data_Struct * getLastData(HID_Data_Struct data){ int hid = data.hid; unsigned char * src = data.src; HID_Data_Struct * last_data = malloc(sizeof(HID_Data_Struct)); if(!last_data) return NULL; - if(hid & HID_LIST_MOUSE){ - last_data->hid = HID_LIST_KEYBOARD; + if(hid & gHID_LIST_MOUSE){ + last_data->hid = gHID_LIST_MOUSE; last_data->src = (unsigned char *) &(gHID_Mouse.pad_data[0].data[1]);// further testing return last_data; } @@ -751,7 +989,7 @@ int getButtonPressed(HID_Data_Struct data, int VPADButton){ int hid = data.hid; - if(hid & HID_LIST_MOUSE){ + if(hid & gHID_LIST_MOUSE){ if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ HID_Mouse_Data * ms_data = (HID_Mouse_Data *) src; if(VPADButton == VPAD_BUTTON_TOUCH){ @@ -761,13 +999,18 @@ int getButtonPressed(HID_Data_Struct data, int VPADButton){ } }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ HID_Mouse_Data * ms_data = (HID_Mouse_Data *) src; - if(VPADButton == VPAD_BUTTON_ZR){ - if(ms_data->left_click & 0x01){ + if(config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_LEFT][0] == CONTROLLER_PATCHER_VALUE_SET){ + if(VPADButton == (int)gGamePadValues[config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_LEFT][1]]){ + if(ms_data->left_click & 0x01){ return 1; + } } - }else if(VPADButton == VPAD_BUTTON_R){ - if(ms_data->right_click & 0x01){ + } + if(config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_RIGHT][0] == CONTROLLER_PATCHER_VALUE_SET){ + if(VPADButton == (int)gGamePadValues[config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_RIGHT][1]]){ + if(ms_data->right_click & 0x01){ return 1; + } } } } @@ -857,6 +1100,26 @@ int getButtonPressed(HID_Data_Struct data, int VPADButton){ ((src[dir3_0] & mask) == dir3_1))) return 1; } + }else if(config_controller[device][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values){ + int contrps_value = 0; + if(VPADButton == VPAD_BUTTON_LEFT){ + contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT; + }else if(VPADButton == VPAD_BUTTON_RIGHT){ + contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_RIGHT; + }else if(VPADButton == VPAD_BUTTON_UP){ + contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_UP; + }else if(VPADButton == VPAD_BUTTON_DOWN){ + contrps_value = CONTRPS_VPAD_BUTTON_DPAD_ABS_DOWN; + } + + if(contrps_value != 0){ + int value_byte = CONTROLLER_PATCHER_INVALIDVALUE; + if((value_byte = config_controller[device][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE){ + if(src[config_controller[device][contrps_value][0]] == config_controller[device][contrps_value][1]){ + return 1; + } + } + } } } @@ -873,20 +1136,24 @@ int getButtonPressed(HID_Data_Struct data, int VPADButton){ if(config_controller[device][CONTRPS_DOUBLE_USE][0] == CONTROLLER_PATCHER_VALUE_SET){ if(config_controller[device][CONTRPS_DOUBLE_USE][1] == CONTROLLER_PATCHER_GC_DOUBLE_USE){ - if(src[config_controller[device][CONTRPS_DOUBLE_USE_BUTTON][0]] & config_controller[device][CONTRPS_DOUBLE_USE_BUTTON][1]){ - if(cur_config == CONTRPS_VPAD_BUTTON_PLUS || cur_config == CONTRPS_VPAD_BUTTON_ZL || cur_config == CONTRPS_VPAD_BUTTON_ZR || cur_config == CONTRPS_VPAD_BUTTON_A || cur_config == CONTRPS_VPAD_BUTTON_B){ - return 0; - } + if(src[config_controller[device][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][0]] & config_controller[device][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][1]){ + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED))return 0; }else{ - if(cur_config == CONTRPS_VPAD_BUTTON_MINUS || cur_config == CONTRPS_VPAD_BUTTON_L || cur_config == CONTRPS_VPAD_BUTTON_R || cur_config == CONTRPS_VPAD_BUTTON_STICK_L || cur_config == CONTRPS_VPAD_BUTTON_STICK_R){ - return 0; - } + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED))return 0; + if(checkDoubleUseGC(device,cur_config,CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED))return 0; } } } //log_printf("Check button %08X \n",VPADButton); - if(config_controller[device][cur_config][0] != 0xFF){ //Invalid data - if(hid & HID_LIST_KEYBOARD){ + if(config_controller[device][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //Invalid data + if(hid & gHID_LIST_KEYBOARD){ if(wasInKeyboard(src,config_controller[device][cur_config][1])) return 1; }else{ //log_printf("src[%02X] = %02X & %02X\n",config_controller[device][cur_config][0],src[config_controller[device][cur_config][0]],config_controller[device][cur_config][1]); @@ -896,14 +1163,24 @@ int getButtonPressed(HID_Data_Struct data, int VPADButton){ } } + }else{ + //log_printf("Invalid data! device(slot): %d config: %d\n",device,cur_config); } return 0; } +int checkDoubleUseGC(int device,int cur_config,int cur_CONTRPS_value){ + if(config_controller[device][cur_CONTRPS_value][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(cur_config == config_controller[device][cur_CONTRPS_value][1]) return 1; + } + return 0; +} + +//TODO: remove hard coded values. void setTouch(HID_Data_Struct data,VPADData * buffer){ unsigned char * src = data.src; int hid = data.hid; - if(hid & HID_LIST_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ + if(hid & gHID_LIST_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ if(getButtonPressed(data,VPAD_BUTTON_TOUCH)){ HID_Mouse_Data * ms_data = (HID_Mouse_Data *) src; int x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f)); @@ -941,120 +1218,188 @@ f32 convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 de } } +Vec2D getAnalogValueByButtons(int up, int down, int left, int right, int * changed){ + Vec2D stick; + stick.x = 0.0f; + stick.y = 0.0f; + + if(up){ + if(!down){ + stick.y = 1.0f; + } + if(left || right){ + stick.y = 0.707f; + if(left) stick.x = -0.707f; + if(right) stick.x = 0.707f; + } + if(changed != NULL) *changed = 1; + }else if(down){ + if(!up){ + stick.y = -1.0f; + } + if(left || right){ + stick.y = -0.707f; + if(left) stick.x = -0.707f; + if(right) stick.x = 0.707f; + } + if(changed != NULL) *changed = 1; + }else{ + if(left){ + if(!right){ + stick.x = -1.0f; + if(changed != NULL) *changed = 1; + } + + }else if(right){ + if(!down){ + stick.x = 1.0f; + if(changed != NULL) *changed = 1; + } + } + } + return stick; +} + void convertAnalogSticks(HID_Data_Struct data, VPADData * buffer){ unsigned char * src = data.src; int hid = data.hid; int changed = 0; - if (hid & HID_LIST_MOUSE){ + + + if (hid & gHID_LIST_MOUSE){ if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values HID_Mouse_Data * ms_data = (HID_Mouse_Data *) src; - buffer->rstick.x += ms_data->deltaX/10.0f; - buffer->rstick.y += -1.0f*(ms_data->deltaY/10.0f); + + f32 x_value = ms_data->deltaX/10.0f; + f32 y_value = -1.0f*(ms_data->deltaY/10.0f); + + if(config_controller[gMouseSlot][CONTRPS_MOUSE_STICK][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(config_controller[gMouseSlot][CONTRPS_MOUSE_STICK][1] == DEF_L_STICK){ + buffer->lstick.x += x_value; + buffer->lstick.y += y_value; + return; + } + } + + buffer->rstick.x += x_value; + buffer->rstick.y += y_value; + changed = 1; } }else{ int device = getDevice(hid); if(device == -1) return; - if (hid & HID_LIST_KEYBOARD){ + if (hid & gHID_LIST_KEYBOARD){ + int w = 0; + int s = 0; + int a = 0; + int d = 0; - int w,s,a,d; - w = wasInKeyboard(src,HID_KEYBOARD_BUTTON_W); - s = wasInKeyboard(src,HID_KEYBOARD_BUTTON_S); - a = wasInKeyboard(src,HID_KEYBOARD_BUTTON_A); - d = wasInKeyboard(src,HID_KEYBOARD_BUTTON_D); - - if(w){ - if(!s){ - buffer->lstick.y = 1.0f; - } - if(a || d){ - buffer->lstick.y = 0.75f; - if(a) buffer->lstick.x = -0.75f; - if(d) buffer->lstick.x = 0.75f; - } - changed = 1; - }else if(s){ - if(!w){ - buffer->lstick.y = -1.0f; - } - if(a || d){ - buffer->lstick.y = -0.75f; - if(a) buffer->lstick.x = -0.75f; - if(d) buffer->lstick.x = 0.75f; - } - changed = 1; - }else{ - if(a){ - if(!d){ - buffer->lstick.x = -1.0f; - changed = 1; - } - - }else if(d){ - if(!s){ - buffer->lstick.x = 1.0f; - changed = 1; - } - } + //Left Stick + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + a = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0]); } + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][1] != CONTROLLER_PATCHER_INVALIDVALUE){ + d = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][1]); + } + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + w = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]); + } + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][1] != CONTROLLER_PATCHER_INVALIDVALUE){ + s = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][1]); + } + + Vec2D stick = getAnalogValueByButtons(w,s,a,d,&changed); + buffer->lstick.x += stick.x; + buffer->lstick.y += stick.y; + + w = 0; s = 0; a = 0; d = 0; + + //Right Stick + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + a = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0]); + } + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][1] != CONTROLLER_PATCHER_INVALIDVALUE){ + d = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][1]); + } + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + w = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]); + } + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][1] != CONTROLLER_PATCHER_INVALIDVALUE){ + s = wasInKeyboard(src,config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][1]); + } + + stick = getAnalogValueByButtons(w,s,a,d,&changed); + buffer->rstick.x += stick.x; + buffer->rstick.y += stick.y; }else{ int deadzone = 0; - if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][1]; + + if( config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ + deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][1]; + } + + buffer->lstick.x += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][1], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][0], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][1], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT][1], + deadzone); + changed = 1; } - buffer->lstick.x += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][1], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][0], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][1], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT][1], - deadzone); - deadzone = 0; - if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][1]; - } - buffer->lstick.y += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][1], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][0], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][1], - config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT][1], - deadzone); - deadzone = 0; - if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][1]; - } - buffer->rstick.x += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][1], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][0], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][1], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT][1], - deadzone); - deadzone = 0; - if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][1]; - } + if( config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + deadzone = 0; + if(config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ + deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][1]; + } + buffer->lstick.y += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][1], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][0], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][1], + config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT][1], + deadzone); + changed = 1; + } + + if( config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + deadzone = 0; + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ + deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][1]; + } + + buffer->rstick.x += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][1], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][0], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][1], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT][1], + deadzone); + changed = 1; + } + + if( config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + deadzone = 0; + if(config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ + deadzone = config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][1]; + } + + buffer->rstick.y += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][1], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][0], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][1], + config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT][1], + deadzone); + changed = 1; + } - buffer->rstick.y += convertAnalogValue(src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][1], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][0], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][1], - config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT][1], - deadzone); - changed = 1; /*log_printf("LX %f(%02X) LY %f(%02X) RX %f(%02X) RY %f(%02X)\n",buffer->lstick.x,src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], buffer->lstick.y,src[config_controller[device][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], buffer->rstick.x,src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], buffer->rstick.y,src[config_controller[device][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]]);*/ } } - if(changed){ - if(buffer->rstick.x > 1.0f) buffer->rstick.x = 1.0f; - if(buffer->rstick.y > 1.0f) buffer->rstick.y = 1.0f; - if(buffer->rstick.x < -1.0f) buffer->rstick.x = -1.0f; - if(buffer->rstick.y < -1.0f) buffer->rstick.y = -1.0f; - } - } int wasInKeyboard(unsigned char * src,int key){ @@ -1080,44 +1425,18 @@ void my_ms_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned { if(error == 0) { - //log_printf("%02X %02X %02X %02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered); - int type = MOUSE_XY_TYPE_A; - int click_offset = 0; - int xy_offset = 1; + //log_printf("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered); - if(bytes_transfered == 5){ - type = MOUSE_XY_TYPE_B; - click_offset = 0; - xy_offset = 1; - }else if(bytes_transfered == 6){ - type = MOUSE_XY_TYPE_A; - xy_offset = 2; - click_offset = 1; - }else if(bytes_transfered == 7){ - type = MOUSE_XY_TYPE_B; - xy_offset = 2; - click_offset = 1; - }else if(bytes_transfered == 8){ - type = MOUSE_XY_TYPE_B; - xy_offset = 3; - click_offset = 1; - } - my_cb_user *usr = (my_cb_user*)p_user; - - gHID_Mouse.pad_data[0].data[0].left_click = buf[click_offset]; - gHID_Mouse.pad_data[0].data[0].right_click = buf[click_offset]>>1; + if(buf[0] == 2 && bytes_transfered > 3){ // using the other mouse mode + buf +=1; + } s8 x_value = 0; s8 y_value = 0; - if(type == MOUSE_XY_TYPE_A){ - x_value = buf[xy_offset]; - y_value = buf[xy_offset+1]; - }else if(type == MOUSE_XY_TYPE_B){ - x_value = buf[xy_offset]; - y_value = ((buf[xy_offset+1] & 0xF0) >>4) | ((buf[xy_offset+2] & 0x0F) <<4); - } + x_value = buf[1]; + y_value = buf[2]; gHID_Mouse.pad_data[0].data[0].X += x_value; gHID_Mouse.pad_data[0].data[0].deltaX = x_value; @@ -1125,6 +1444,8 @@ void my_ms_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned gHID_Mouse.pad_data[0].data[0].Y += y_value; gHID_Mouse.pad_data[0].data[0].deltaY = y_value; + gHID_Mouse.pad_data[0].data[0].left_click = buf[0]; + gHID_Mouse.pad_data[0].data[0].right_click = buf[0]>>1; if(gHID_Mouse.pad_data[0].data[0].X < 0) gHID_Mouse.pad_data[0].data[0].X = 0; if(gHID_Mouse.pad_data[0].data[0].X > 1280) gHID_Mouse.pad_data[0].data[0].X = 1280; @@ -1132,8 +1453,10 @@ void my_ms_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned if(gHID_Mouse.pad_data[0].data[0].Y < 0) gHID_Mouse.pad_data[0].data[0].Y = 0; if(gHID_Mouse.pad_data[0].data[0].Y > 720) gHID_Mouse.pad_data[0].data[0].Y = 720; - //log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value); + gHID_Mouse.pad_data[0].data[0].valuedChanged = 1; + //log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value); + my_cb_user *usr = (my_cb_user*)p_user; HIDRead(handle, usr->buf, bytes_transfered, my_ms_read_cb, usr); } } @@ -1149,11 +1472,11 @@ void my_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned int { my_cb_user *usr = (my_cb_user*)p_user; - if(usr->hid == HID_LIST_GC){ - memcpy(&(((HID_Data *)config_controller_data_ptr[CONTRPD_GC][0])->hid_data),&buf[1],9); - memcpy(&(((HID_Data *)config_controller_data_ptr[CONTRPD_GC][1])->hid_data),&buf[10],9); - memcpy(&(((HID_Data *)config_controller_data_ptr[CONTRPD_GC][2])->hid_data),&buf[19],9); - memcpy(&(((HID_Data *)config_controller_data_ptr[CONTRPD_GC][3])->hid_data),&buf[28],9); + if(usr->hid == gHID_LIST_GC){ + memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][0])->hid_data),&buf[1],9); + memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][1])->hid_data),&buf[10],9); + memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][2])->hid_data),&buf[19],9); + memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][3])->hid_data),&buf[28],9); /* @@ -1164,13 +1487,13 @@ void my_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned int log_printf("GC4: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n",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],buf[i*9+9]);*/ HIDRead(handle, usr->buf, bytes_transfered, my_read_cb, usr); - int pad = getActivePad(HID_LIST_GC); + int pad = getActivePad(gHID_LIST_GC); - //log_printf("Pad attached: %02X \n",getActivePad(HID_LIST_GC)); + //log_printf("Pad attached: %02X \n",getActivePad(gHID_LIST_GC)); - if((pad >= 0) && (((HID_Data *)config_controller_data_ptr[CONTRPD_GC][pad])->rumbleActive != usr->rumblestatus[pad])) + if((pad >= 0) && (((HID_Data *)config_controller_data_ptr[usr->deviceSlot][pad])->rumbleActive != usr->rumblestatus[pad])) { - usr->rumblestatus[pad] = ((HID_Data *)config_controller_data_ptr[CONTRPD_GC][pad])->rumbleActive; + usr->rumblestatus[pad] = ((HID_Data *)config_controller_data_ptr[usr->deviceSlot][pad])->rumbleActive; HIDGCRumble(handle,usr,usr->rumblestatus[pad],pad); } else @@ -1179,11 +1502,20 @@ void my_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned int } }else if(usr->hid != 0){ // + int size = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD; - memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][0])->hid_data),&buf[0],size); - usleep(5000); //DS4 is way tooo fast (need to check the other pads) - if(usr->hid == HID_LIST_POKKEN){ - log_printf("HID %02X %02X %02X %02X %02X %02X %02X %02X \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); //<-- only debug the pokken controller + int skip = 0; + if(config_controller[usr->deviceSlot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){ + if(buf[config_controller[usr->deviceSlot][CONTRPS_INPUT_FILTER][0]] != config_controller[usr->deviceSlot][CONTRPS_INPUT_FILTER][1]){ + skip = 1; + } + } + + if(!skip){ + memcpy(&(((HID_Data *)config_controller_data_ptr[usr->deviceSlot][0])->hid_data),&buf[0],size); + usleep(5000); //DS4 is way tooo fast (need to check the other pads) + //log_printf("HID %02X %02X %02X %02X %02X %02X %02X %02X \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); //<-- only debug the pokken controller + } HIDRead(handle, usr->buf, bytes_transfered, my_read_cb, usr); } diff --git a/controller_patcher.h b/controller_patcher.h index 2782684..f83ca84 100644 --- a/controller_patcher.h +++ b/controller_patcher.h @@ -1,3 +1,20 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ + #ifndef _CONTROLLER_PATCHER_H_ #define _CONTROLLER_PATCHER_H_ @@ -11,33 +28,30 @@ extern "C" { #include "dynamic_libs/syshid_functions.h" #include "dynamic_libs/vpad_functions.h" +#define HID_DEBUG 0 + +typedef int HID_DEVICE_LIST; +#define HID_ALL_CONNECTED_DEVICES 0x10 + +#define HID_INIT_DONE 1 +#define HID_SDCARD_READ 2 //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Don't forget to change this data! //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -enum Controller_Patcher_Devices +enum Controller_Stick_Defines { - CONTRPD_GC, - CONTRPD_DS3, - CONTRPD_DS4, - CONTRPD_SP2600, - CONTRPD_KEYBOARD, - CONTRPD_PS2_ADAPTER, - CONTRPD_POKKEN, - CONTRPD_PS2, - CONTRPD_MAX_VALUE + STICK_CONF_MAGIC_VERSION, + STICK_CONF_BYTE, + STICK_CONF_DEFAULT, + STICK_CONF_DEADZONE, + STICK_CONF_INVERT, + STICK_CONF_MIN, + STICK_CONF_MAX, + STICK_CONF_ENUM_MAXVALUE }; -#define HID_LIST_GC 0x001 -#define HID_LIST_KEYBOARD 0x002 -#define HID_LIST_MOUSE 0x004 -#define HID_LIST_DS3 0x008 -#define HID_LIST_DS4 0x010 -#define HID_LIST_SP2600 0x020 -#define HID_LIST_PS2_ADAPTER 0x040 -#define HID_LIST_POKKEN 0x080 -#define HID_LIST_PS2 0x100 +#define STICK_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!! //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! End @@ -56,7 +70,7 @@ enum Controller_Patcher_Settings { CONTRPS_VID, //! pid: 0x451d would be 0x45,0x1d CONTRPS_PID, //! vid: 0x488d would be 0x48,0x8d - CONTRPS_BUF_SIZE, //! To invert: CONTROLLER_PATCHER_VALUE_SET, BUF_SIZE (default is 64) + CONTRPS_BUF_SIZE, //! To set: CONTROLLER_PATCHER_VALUE_SET, BUF_SIZE (default is 64) CONTRPS_VPAD_BUTTON_A, CONTRPS_VPAD_BUTTON_B, CONTRPS_VPAD_BUTTON_X, @@ -78,6 +92,11 @@ enum Controller_Patcher_Settings CONTRPS_VPAD_BUTTON_DPAD_W, CONTRPS_VPAD_BUTTON_DPAD_NW, CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL, + /* DPAD Absolute mode */ + CONTRPS_VPAD_BUTTON_DPAD_ABS_UP, + CONTRPS_VPAD_BUTTON_DPAD_ABS_DOWN, + CONTRPS_VPAD_BUTTON_DPAD_ABS_LEFT, + CONTRPS_VPAD_BUTTON_DPAD_ABS_RIGHT, /* */ CONTRPS_VPAD_BUTTON_ZL, CONTRPS_VPAD_BUTTON_ZR, @@ -89,6 +108,20 @@ enum Controller_Patcher_Settings CONTRPS_VPAD_BUTTON_SYNC, CONTRPS_VPAD_BUTTON_STICK_R, CONTRPS_VPAD_BUTTON_STICK_L, + + /* + Currently not needed + + CONTRPS_VPAD_STICK_R_EMULATION_LEFT, + CONTRPS_VPAD_STICK_R_EMULATION_RIGHT, + CONTRPS_VPAD_STICK_R_EMULATION_UP, + CONTRPS_VPAD_STICK_R_EMULATION_DOWN, + CONTRPS_VPAD_STICK_L_EMULATION_LEFT, + CONTRPS_VPAD_STICK_L_EMULATION_RIGHT, + CONTRPS_VPAD_STICK_L_EMULATION_UP, + CONTRPS_VPAD_STICK_L_EMULATION_DOWN, + + */ CONTRPS_VPAD_BUTTON_L_STICK_X, //! byte, default value CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT, //! To invert: CONTROLLER_PATCHER_VALUE_SET, 0x01 CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE, //! Deadzone @@ -107,15 +140,33 @@ enum Controller_Patcher_Settings CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX, //! min,max CONTRPS_VPAD_BUTTON_TV, CONTRPS_DOUBLE_USE, //!When used: e.g. CONTROLLER_PATCHER_VALUE_SET, CONTROLLER_PATCHER_GC_DOUBLE_USE - CONTRPS_DOUBLE_USE_BUTTON, + CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR, + CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED, + CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED, + CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED, + CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED, + CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED, + CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED, + CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED, + CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED, + CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED, + CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED, CONTRPS_PAD_COUNT, //! + CONTRPS_INPUT_FILTER, //! + CONTRPS_MOUSE_STICK, CONTRPS_MAX_VALUE }; enum Controller_Patcher_DPAD_MODE { CONTRPDM_Normal, - CONTRPDM_Hat + CONTRPDM_Hat, + CONTRPDM_Absolute_2Values, +}; +enum Controller_Patcher_DPAD_Settings +{ + CONTRDPAD_MODE, + CONTRDPAD_MASK, }; #define CONTROLLER_PATCHER_VALUE_SET 0x01 @@ -145,33 +196,42 @@ typedef struct _HID_Data_Struct{ void setConfigValue(u8 * dest , u8 first, u8 second); void init_config_controller(); +void init_button_remapping(); void deinit_config_controller(); +u32 getNextDeviceSlot(); +void printButtons(VPADData * buffer); +void buttonRemapping(VPADData * buffer); +void setButtonRemappingData(VPADData * buffer, VPADData * new_data,u32 VPADButton, int CONTRPS_Value); +void setHoldButtonData(VPADData * buffer, VPADData * new_data,u32 oldVPADButton,u32 newVPADButton); void setControllerReleasePressData(HID_Data_Struct data_cur, HID_Data_Struct data_last,VPADData * buffer,int VPADButton); -void setControllerDataFromHID(VPADData * buffer,int hid); +void setControllerDataFromHID(VPADData * buffer,HID_DEVICE_LIST hid_devices); +int checkDoubleUseGC(); void checkMouseMode(HID_Data_Struct data, HID_Data_Struct data_last); void my_read_cb(unsigned int handle, int error, unsigned char *buf, unsigned int bytes_transfered, void *p_user); int wasInKeyboard(unsigned char * src,int key); +const char *byte_to_binary(int x); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! GC-Adapter //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//A config would be cleaner, but no motivation atm :P -#define HID_GC_BUTTON_A 0x01 -#define HID_GC_BUTTON_B 0x02 -#define HID_GC_BUTTON_X 0x04 -#define HID_GC_BUTTON_Y 0x08 -#define HID_GC_BUTTON_LEFT 0x10 -#define HID_GC_BUTTON_RIGHT 0x20 -#define HID_GC_BUTTON_DOWN 0x40 -#define HID_GC_BUTTON_UP 0x80 -#define HID_GC_BUTTON_START 0x01 -#define HID_GC_BUTTON_L 0x80 -#define HID_GC_BUTTON_R 0x80 -#define HID_GC_BUTTON_Z 0x02 +#define HID_GC_BUTTON_A_VALUE 0x01 +#define HID_GC_BUTTON_B_VALUE 0x02 +#define HID_GC_BUTTON_X_VALUE 0x04 +#define HID_GC_BUTTON_Y_VALUE 0x08 +#define HID_GC_BUTTON_LEFT_VALUE 0x10 +#define HID_GC_BUTTON_RIGHT_VALUE 0x20 +#define HID_GC_BUTTON_DOWN_VALUE 0x40 +#define HID_GC_BUTTON_UP_VALUE 0x80 + +#define HID_GC_BUTTON_START_VALUE 0x01 +#define HID_GC_BUTTON_L_VALUE 0x80 +#define HID_GC_BUTTON_R_VALUE 0x80 +#define HID_GC_BUTTON_Z_VALUE 0x02 #define HID_GC_PAD_COUNT 4 @@ -191,24 +251,25 @@ void my_gc_write_cb(unsigned int handle, int error, unsigned char *buf, unsigned #define PS3_01_REPORT_ID 0x01 #define PS3_F5_REPORT_ID 0xF5 -#define HID_DS3_BUTTON_CROSS 0x40 // 3 -#define HID_DS3_BUTTON_CIRCLE 0x20 // 3 -#define HID_DS3_BUTTON_SQUARE 0x80 // 3 -#define HID_DS3_BUTTON_TRIANGLE 0x10 // 3 -#define HID_DS3_BUTTON_L1 0x04 // 3 -#define HID_DS3_BUTTON_L2 0x01 // 3 -#define HID_DS3_BUTTON_R1 0x08 // 3 -#define HID_DS3_BUTTON_R2 0x02 // 3 +#define HID_DS3_BUTTON_CROSS_VALUE 0x40 // 3 +#define HID_DS3_BUTTON_CIRCLE_VALUE 0x20 // 3 +#define HID_DS3_BUTTON_SQUARE_VALUE 0x80 // 3 +#define HID_DS3_BUTTON_TRIANGLE_VALUE 0x10 // 3 +#define HID_DS3_BUTTON_L1_VALUE 0x04 // 3 +#define HID_DS3_BUTTON_L2_VALUE 0x01 // 3 +#define HID_DS3_BUTTON_R1_VALUE 0x08 // 3 +#define HID_DS3_BUTTON_R2_VALUE 0x02 // 3 + +#define HID_DS3_BUTTON_L3_VALUE 0x02 // 2 +#define HID_DS3_BUTTON_R3_VALUE 0x04 // 2 +#define HID_DS3_BUTTON_SELECT_VALUE 0x01 // 2 +#define HID_DS3_BUTTON_START_VALUE 0x08 // 2 +#define HID_DS3_BUTTON_LEFT_VALUE 0x80 // 2 +#define HID_DS3_BUTTON_RIGHT_VALUE 0x20 // 2 +#define HID_DS3_BUTTON_UP_VALUE 0x10 // 2 +#define HID_DS3_BUTTON_DOWN_VALUE 0x40 // 2 +#define HID_DS3_BUTTON_GUIDE_VALUE 0x01 // 4 -#define HID_DS3_BUTTON_L3 0x02 // 2 -#define HID_DS3_BUTTON_R3 0x04 // 2 -#define HID_DS3_BUTTON_SELECT 0x01 // 2 -#define HID_DS3_BUTTON_START 0x08 // 2 -#define HID_DS3_BUTTON_LEFT 0x80 // 2 -#define HID_DS3_BUTTON_RIGHT 0x20 // 2 -#define HID_DS3_BUTTON_UP 0x10 // 2 -#define HID_DS3_BUTTON_DOWN 0x40 // 2 -#define HID_DS3_BUTTON_GUIDE 0x01 // 4 #define HID_DS3_PAD_COUNT 1 @@ -216,149 +277,41 @@ void my_gc_write_cb(unsigned int handle, int error, unsigned char *buf, unsigned //! DS4 //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -#define HID_DS4_BUTTON_CROSS 0x20 // 5 -#define HID_DS4_BUTTON_SQUARE 0x10 // 5 -#define HID_DS4_BUTTON_CIRCLE 0x40 // 5 -#define HID_DS4_BUTTON_TRIANGLE 0x80 // 5 -#define HID_DS4_BUTTON_L1 0x01 // 6 -#define HID_DS4_BUTTON_L2 0x04 // 6 -#define HID_DS4_BUTTON_L3 0x40 // 6 -#define HID_DS4_BUTTON_R1 0x02 // 6 -#define HID_DS4_BUTTON_R2 0x08 // 6 -#define HID_DS4_BUTTON_R3 0x80 // 6 -#define HID_DS4_BUTTON_SHARE 0x10 // 6 -#define HID_DS4_BUTTON_OPTIONS 0x20 // 6 -#define HID_DS4_BUTTON_DPAD_N 0x00 // 5 -#define HID_DS4_BUTTON_DPAD_NE 0x01 // 5 -#define HID_DS4_BUTTON_DPAD_E 0x02 // 5 -#define HID_DS4_BUTTON_DPAD_SE 0x03 // 5 -#define HID_DS4_BUTTON_DPAD_S 0x04 // 5 -#define HID_DS4_BUTTON_DPAD_SW 0x05 // 5 -#define HID_DS4_BUTTON_DPAD_W 0x06 // 5 -#define HID_DS4_BUTTON_DPAD_NW 0x07 // 5 -#define HID_DS4_BUTTON_DPAD_NEUTRAL 0x08 // 5 -#define HID_DS4_BUTTON_GUIDE 0x01 // 7 -#define HID_DS4_BUTTON_T_PAD_CLICK 0x02 // 7 +#define HID_DS4_BUTTON_CROSS_VALUE 0x20 // 5 +#define HID_DS4_BUTTON_SQUARE_VALUE 0x10 // 5 +#define HID_DS4_BUTTON_CIRCLE_VALUE 0x40 // 5 +#define HID_DS4_BUTTON_TRIANGLE_VALUE 0x80 // 5 +#define HID_DS4_BUTTON_L1_VALUE 0x01 // 6 +#define HID_DS4_BUTTON_L2_VALUE 0x04 // 6 +#define HID_DS4_BUTTON_L3_VALUE 0x40 // 6 +#define HID_DS4_BUTTON_R1_VALUE 0x02 // 6 +#define HID_DS4_BUTTON_R2_VALUE 0x08 // 6 +#define HID_DS4_BUTTON_R3_VALUE 0x80 // 6 +#define HID_DS4_BUTTON_SHARE_VALUE 0x10 // 6 +#define HID_DS4_BUTTON_OPTIONS_VALUE 0x20 // 6 + +#define HID_DS4_BUTTON_DPAD_MASK_VALUE 0x0F + +#define HID_DS4_BUTTON_DPAD_N_VALUE 0x00 // 5 +#define HID_DS4_BUTTON_DPAD_NE_VALUE 0x01 // 5 +#define HID_DS4_BUTTON_DPAD_E_VALUE 0x02 // 5 +#define HID_DS4_BUTTON_DPAD_SE_VALUE 0x03 // 5 +#define HID_DS4_BUTTON_DPAD_S_VALUE 0x04 // 5 +#define HID_DS4_BUTTON_DPAD_SW_VALUE 0x05 // 5 +#define HID_DS4_BUTTON_DPAD_W_VALUE 0x06 // 5 +#define HID_DS4_BUTTON_DPAD_NW_VALUE 0x07 // 5 +#define HID_DS4_BUTTON_DPAD_NEUTRAL_VALUE 0x08 // 5 + +#define HID_DS4_BUTTON_GUIDE_VALUE 0x01 // 7 +#define HID_DS4_BUTTON_T_PAD_CLICK_VALUE 0x02 // 7 #define HID_DS4_PAD_COUNT 1 //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! PS2 Adapter +//! Keyboard (Full list is on: http://www.freebsddiary.org/APC/usb_hid_usages.php) //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -#define HID_PS2_ADAPTER_BUTTON_CROSS 0x40 // 5 -#define HID_PS2_ADAPTER_BUTTON_CIRCLE 0x20 // 5 -#define HID_PS2_ADAPTER_BUTTON_SQUARE 0x80 // 5 -#define HID_PS2_ADAPTER_BUTTON_TRIANGLE 0x10 // 5 - -#define HID_PS2_ADAPTER_BUTTON_DPAD_N 0x00 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_NE 0x01 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_E 0x02 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_SE 0x03 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_S 0x04 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_SW 0x05 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_W 0x06 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_NW 0x07 // 5 -#define HID_PS2_ADAPTER_BUTTON_DPAD_NEUTRAL 0x0F // 5 - -#define HID_PS2_ADAPTER_BUTTON_L1 0x04 // 6 -#define HID_PS2_ADAPTER_BUTTON_L2 0x01 // 6 -#define HID_PS2_ADAPTER_BUTTON_R1 0x08 // 6 -#define HID_PS2_ADAPTER_BUTTON_R2 0x02 // 6 -#define HID_PS2_ADAPTER_BUTTON_START 0x20 // 6 -#define HID_PS2_ADAPTER_BUTTON_SELECT 0x10 // 6 - -#define HID_PS2_ADAPTER_PAD_COUNT 1 - - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! PS2 -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -#define HID_PS2_BUTTON_CROSS 0x20 // 5 -#define HID_PS2_BUTTON_SQUARE 0x40 // 5 -#define HID_PS2_BUTTON_CIRCLE 0x10 // 5 -#define HID_PS2_BUTTON_TRIANGLE 0x80 // 5 - -#define HID_PS2_BUTTON_DPAD_N 0x00 // 5 -#define HID_PS2_BUTTON_DPAD_NE 0x01 // 5 -#define HID_PS2_BUTTON_DPAD_E 0x02 // 5 -#define HID_PS2_BUTTON_DPAD_SE 0x03 // 5 -#define HID_PS2_BUTTON_DPAD_S 0x04 // 5 -#define HID_PS2_BUTTON_DPAD_SW 0x05 // 5 -#define HID_PS2_BUTTON_DPAD_W 0x06 // 5 -#define HID_PS2_BUTTON_DPAD_NW 0x07 // 5 -#define HID_PS2_BUTTON_DPAD_NEUTRAL 0x0F // 5 - -#define HID_PS2_BUTTON_L1 0x04 // 6 -#define HID_PS2_BUTTON_L2 0x01 // 6 -#define HID_PS2_BUTTON_R1 0x08 // 6 -#define HID_PS2_BUTTON_R2 0x02 // 6 -#define HID_PS2_BUTTON_START 0x20 // 6 -#define HID_PS2_BUTTON_SELECT 0x10 // 6 - -#define HID_PS2_PAD_COUNT 1 - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Saitek P2600 -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -#define HID_SP2600_BUTTON_1 0x01 // 5 -#define HID_SP2600_BUTTON_2 0x02 // 5 -#define HID_SP2600_BUTTON_3 0x04 // 5 -#define HID_SP2600_BUTTON_4 0x08 // 5 - -#define HID_SP2600_BUTTON_DPAD_N 0x00 // 5 -#define HID_SP2600_BUTTON_DPAD_NE 0x10 // 5 -#define HID_SP2600_BUTTON_DPAD_E 0x20 // 5 -#define HID_SP2600_BUTTON_DPAD_SE 0x30 // 5 -#define HID_SP2600_BUTTON_DPAD_S 0x40 // 5 -#define HID_SP2600_BUTTON_DPAD_SW 0x50 // 5 -#define HID_SP2600_BUTTON_DPAD_W 0x60 // 5 -#define HID_SP2600_BUTTON_DPAD_NW 0x70 // 5 -#define HID_SP2600_BUTTON_DPAD_NEUTRAL 0xF0 // 5 - -#define HID_SP2600_BUTTON_5 0x10 // 5 //L upper -#define HID_SP2600_BUTTON_6 0x20 // 5 //R upper -#define HID_SP2600_BUTTON_7 0x40 // 5 //L lower -#define HID_SP2600_BUTTON_8 0x80 // 5 //R lower -#define HID_SP2600_BUTTON_BLACK 0x01 // 6 -#define HID_SP2600_BUTTON_WHITE 0x02 // 6 -#define HID_SP2600_BUTTON_FPS 0x04 // 6 -#define HID_SP2600_BUTTON_Analog 0x08 // 6 - -#define HID_SP2600_PAD_COUNT 1 - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! POKKEN -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -#define HID_POKKEN_BUTTON_1 0x01 -#define HID_POKKEN_BUTTON_2 0x02 -#define HID_POKKEN_BUTTON_3 0x04 -#define HID_POKKEN_BUTTON_4 0x08 -#define HID_POKKEN_BUTTON_5 0x10 -#define HID_POKKEN_BUTTON_6 0x20 -#define HID_POKKEN_BUTTON_7 0x40 -#define HID_POKKEN_BUTTON_8 0x80 -#define HID_POKKEN_BUTTON_9 0x80 -#define HID_POKKEN_BUTTON_10 0x80 - -#define HID_POKKEN_BUTTON_DPAD_N 0x00 -#define HID_POKKEN_BUTTON_DPAD_NE 0x10 -#define HID_POKKEN_BUTTON_DPAD_E 0x20 -#define HID_POKKEN_BUTTON_DPAD_SE 0x30 -#define HID_POKKEN_BUTTON_DPAD_S 0x40 -#define HID_POKKEN_BUTTON_DPAD_SW 0x50 -#define HID_POKKEN_BUTTON_DPAD_W 0x60 -#define HID_POKKEN_BUTTON_DPAD_NW 0x70 -#define HID_POKKEN_BUTTON_DPAD_NEUTRAL 0xF0 - -#define HID_POKKEN_PAD_COUNT 1 - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Keyboard -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +#define HID_KEYBOARD_BUTTON_SHIFT 0x02 #define HID_KEYBOARD_BUTTON_A 0x04 #define HID_KEYBOARD_BUTTON_B 0x05 @@ -398,16 +351,56 @@ void my_gc_write_cb(unsigned int handle, int error, unsigned char *buf, unsigned #define HID_KEYBOARD_BUTTON_F10 0x43 #define HID_KEYBOARD_BUTTON_F11 0x44 #define HID_KEYBOARD_BUTTON_F12 0x45 +#define HID_KEYBOARD_BUTTON_1 0x1E +#define HID_KEYBOARD_BUTTON_2 0x1F +#define HID_KEYBOARD_BUTTON_3 0x20 +#define HID_KEYBOARD_BUTTON_4 0x21 +#define HID_KEYBOARD_BUTTON_5 0x22 +#define HID_KEYBOARD_BUTTON_6 0x23 +#define HID_KEYBOARD_BUTTON_7 0x24 +#define HID_KEYBOARD_BUTTON_8 0x25 +#define HID_KEYBOARD_BUTTON_9 0x26 +#define HID_KEYBOARD_BUTTON_0 0x27 + +#define HID_KEYBOARD_BUTTON_RETURN 0x28 +#define HID_KEYBOARD_BUTTON_ESCAPE 0x29 +#define HID_KEYBOARD_BUTTON_DELETE 0x2A +#define HID_KEYBOARD_BUTTON_TAB 0x2B +#define HID_KEYBOARD_BUTTON_SPACEBAR 0x2C +#define HID_KEYBOARD_BUTTON_CAPSLOCK 0x39 +#define HID_KEYBOARD_BUTTON_PRINTSCREEN 0x46 +#define HID_KEYBOARD_BUTTON_SCROLLLOCK 0x47 +#define HID_KEYBOARD_BUTTON_PAUSE 0x48 +#define HID_KEYBOARD_BUTTON_INSERT 0x49 +#define HID_KEYBOARD_BUTTON_HOME 0x4A +#define HID_KEYBOARD_BUTTON_PAGEUP 0x4B +#define HID_KEYBOARD_BUTTON_PAGEDOWN 0x4E +#define HID_KEYBOARD_BUTTON_DELETEFORWARD 0x4C +#define HID_KEYBOARD_BUTTON_END 0x4D +#define HID_KEYBOARD_BUTTON_LEFT_CONTROL 0xE0 +#define HID_KEYBOARD_BUTTON_LEFT_ALT 0xE2 +#define HID_KEYBOARD_BUTTON_RIGHT_CONTROL 0xE4 +#define HID_KEYBOARD_BUTTON_RIGHT_SHIFT 0xE5 +#define HID_KEYBOARD_BUTTON_RIGHT_ALT 0xE6 + #define HID_KEYBOARD_BUTTON_LEFT 0x50 #define HID_KEYBOARD_BUTTON_RIGHT 0x4f #define HID_KEYBOARD_BUTTON_DOWN 0x51 #define HID_KEYBOARD_BUTTON_UP 0x52 -#define HID_KEYBOARD_BUTTON_ENTER 0x28 -#define HID_KEYBOARD_BUTTON_MINUS 0x56 -#define HID_KEYBOARD_BUTTON_PLUS 0x57 -#define HID_KEYBOARD_BUTTON_SPACE 0x2C -#define HID_KEYBOARD_BUTTON_SHIFT 0x02 -#define HID_KEYBOARD_BUTTON_TAB 0x2B + +#define HID_KEYBOARD_KEYPAD_BUTTON_1 0x59 +#define HID_KEYBOARD_KEYPAD_BUTTON_2 0x5A +#define HID_KEYBOARD_KEYPAD_BUTTON_3 0x5B +#define HID_KEYBOARD_KEYPAD_BUTTON_4 0x5C +#define HID_KEYBOARD_KEYPAD_BUTTON_5 0x5D +#define HID_KEYBOARD_KEYPAD_BUTTON_6 0x5E +#define HID_KEYBOARD_KEYPAD_BUTTON_7 0x5F +#define HID_KEYBOARD_KEYPAD_BUTTON_8 0x60 +#define HID_KEYBOARD_KEYPAD_BUTTON_9 0x61 +#define HID_KEYBOARD_KEYPAD_BUTTON_0 0x62 +#define HID_KEYBOARD_KEYPAD_BUTTON_NUMLOCK 0x53 +#define HID_KEYBOARD_KEYPAD_BUTTON_MINUS 0x56 +#define HID_KEYBOARD_KEYPAD_BUTTON_PLUS 0x57 #define HID_KEYBOARD_PAD_COUNT 1 #define HID_KEYBOARD_DATA_LENGTH 8 @@ -432,6 +425,7 @@ struct _HID_Mouse_Data { s16 Y; s16 deltaX; s16 deltaY; + u8 valuedChanged; } __attribute__ ((packed)); typedef struct _HID_Mouse_Data HID_Mouse_Data; diff --git a/cp_retain_vars.c b/cp_retain_vars.c index 734cd9d..fc2e3c1 100644 --- a/cp_retain_vars.c +++ b/cp_retain_vars.c @@ -1,21 +1,53 @@ -#include -#include "dynamic_libs/syshid_functions.h" -#include "controller_patcher/controller_patcher.h" +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ -u8 config_done __attribute__((section(".data"))) = 0; +#include +#include "controller_patcher.h" +#include "cp_retain_vars.h" + +u8 gConfig_done __attribute__((section(".data"))) = 0; +u8 gButtonRemappingConfigDone __attribute__((section(".data"))) = 0; u8 gHIDSetupDone __attribute__((section(".data"))) = 0; u16 gHIDAttached __attribute__((section(".data"))) = 0; u16 gHIDCurrentDevice __attribute__((section(".data"))) = 0; +u16 gHIDRegisteredDevices __attribute__((section(".data"))) = 0; + HIDClient gHIDClient __attribute__((section(".data"))); -HID_DEVICE_DATA gHID_Devices[CONTRPD_MAX_VALUE] __attribute__((section(".data"))); +HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices] __attribute__((section(".data"))); HID_Mouse gHID_Mouse __attribute__((section(".data"))); u8 gHID_Mouse_Mode __attribute__((section(".data"))) = HID_MOUSE_MODE_TOUCH; -u8 config_controller[CONTRPD_MAX_VALUE][CONTRPS_MAX_VALUE][2] __attribute__((section(".data"))); -u16 config_controller_list[CONTRPD_MAX_VALUE] __attribute__((section(".data"))); -u32 config_controller_data_ptr[CONTRPD_MAX_VALUE][4] __attribute__((section(".data"))); +u32 gGamePadValues[CONTRPS_MAX_VALUE] __attribute__((section(".data"))); + +u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2] __attribute__((section(".data"))); +u16 config_controller_list[gHIDMaxDevices] __attribute__((section(".data"))); +u32 config_controller_data_ptr[gHIDMaxDevices][HID_MAX_PADS_COUNT] __attribute__((section(".data"))); + +u16 gHID_LIST_GC __attribute__((section(".data"))) = 0; +u16 gHID_LIST_DS3 __attribute__((section(".data"))) = 0; +u16 gHID_LIST_KEYBOARD __attribute__((section(".data"))) = 0; +u16 gHID_LIST_MOUSE __attribute__((section(".data"))) = 0; + +u16 gGamePadSlot __attribute__((section(".data"))) = 0; +u16 gHID_SLOT_GC __attribute__((section(".data"))) = 0; +u16 gHID_SLOT_KEYBOARD __attribute__((section(".data"))) = 0; +u16 gMouseSlot __attribute__((section(".data"))) = 0; diff --git a/cp_retain_vars.h b/cp_retain_vars.h index 941a99d..76adbaa 100644 --- a/cp_retain_vars.h +++ b/cp_retain_vars.h @@ -1,24 +1,58 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ #ifndef CP_RETAINS_VARS_H_ #define CP_RETAINS_VARS_H_ #include "dynamic_libs/syshid_functions.h" #include "controller_patcher/controller_patcher.h" -extern u8 config_done; +extern u8 gConfig_done; +extern u8 gButtonRemappingConfigDone; extern u8 gHIDSetupDone; extern u16 gHIDAttached; extern u16 gHIDCurrentDevice; extern HIDClient gHIDClient; -extern HID_DEVICE_DATA gHID_Devices[CONTRPD_MAX_VALUE]; +#define gHIDMaxDevices 16 +#define HID_INVALID_SLOT 0xFFFF + +extern u16 gHIDRegisteredDevices; + +extern HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices]; extern HID_Mouse gHID_Mouse; extern u8 gHID_Mouse_Mode; -extern u8 config_controller[CONTRPD_MAX_VALUE][CONTRPS_MAX_VALUE][2]; -extern u16 config_controller_list[CONTRPD_MAX_VALUE]; -extern u32 config_controller_data_ptr[CONTRPD_MAX_VALUE][4]; //currently max per device +extern u32 gGamePadValues[CONTRPS_MAX_VALUE]; + +extern u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2]; +extern u16 config_controller_list[gHIDMaxDevices]; +extern u32 config_controller_data_ptr[gHIDMaxDevices][4]; //currently max per device + +extern u16 gHID_LIST_GC; +extern u16 gHID_LIST_DS3; +extern u16 gHID_LIST_KEYBOARD; +extern u16 gHID_LIST_MOUSE; +extern u16 gGamePadSlot; + +extern u16 gHID_SLOT_GC; +extern u16 gHID_SLOT_KEYBOARD; +extern u16 gMouseSlot; #endif // CP_RETAINS_VARS_H_ diff --git a/pad_const.c b/pad_const.c new file mode 100644 index 0000000..3edec95 --- /dev/null +++ b/pad_const.c @@ -0,0 +1,217 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ + +#include "pad_const.h" + +const u8 DEF_L_STICK_UP = 201; +const u8 DEF_L_STICK_DOWN = 202; +const u8 DEF_L_STICK_LEFT = 203; +const u8 DEF_L_STICK_RIGHT = 204; + +const u8 DEF_R_STICK_UP = 205; +const u8 DEF_R_STICK_DOWN = 206; +const u8 DEF_R_STICK_LEFT = 207; +const u8 DEF_R_STICK_RIGHT = 208; + +const u8 DEF_R_STICK = 220; +const u8 DEF_L_STICK = 221; + +const u8 DEF_STICK_OFFSET_INVERT = CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT - CONTRPS_VPAD_BUTTON_L_STICK_X; +const u8 DEF_STICK_OFFSET_DEADZONE = CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE - CONTRPS_VPAD_BUTTON_L_STICK_X; +const u8 DEF_STICK_OFFSET_MINMAX = CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX - CONTRPS_VPAD_BUTTON_L_STICK_X; + + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! GC-Adapter +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +const u8 HID_GC_BUTTON_A[] = { 0x01,HID_GC_BUTTON_A_VALUE}; +const u8 HID_GC_BUTTON_B[] = { 0x01,HID_GC_BUTTON_B_VALUE}; +const u8 HID_GC_BUTTON_X[] = { 0x01,HID_GC_BUTTON_X_VALUE}; +const u8 HID_GC_BUTTON_Y[] = { 0x01,HID_GC_BUTTON_Y_VALUE}; +const u8 HID_GC_BUTTON_LEFT[] = { 0x01,HID_GC_BUTTON_LEFT_VALUE}; +const u8 HID_GC_BUTTON_RIGHT[] = { 0x01,HID_GC_BUTTON_RIGHT_VALUE}; +const u8 HID_GC_BUTTON_DOWN[] = { 0x01,HID_GC_BUTTON_DOWN_VALUE}; +const u8 HID_GC_BUTTON_UP[] = { 0x01,HID_GC_BUTTON_UP_VALUE}; + +const u8 HID_GC_BUTTON_START[] = { 0x02,HID_GC_BUTTON_START_VALUE}; +const u8 HID_GC_BUTTON_Z[] = { 0x02,HID_GC_BUTTON_Z_VALUE}; + +const u8 HID_GC_BUTTON_L[] = { 0x07,HID_GC_BUTTON_L_VALUE}; +const u8 HID_GC_BUTTON_R[] = { 0x08,HID_GC_BUTTON_R_VALUE}; + +const u8 HID_GC_BUTTON_DPAD_TYPE[] = { CONTRPDM_Normal,0x00}; + +const u8 HID_GC_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x03, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x1E, //STICK_CONF_MIN, + 0xE5};//STICK_CONF_MAX, + +const u8 HID_GC_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x04, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x18, //STICK_CONF_MIN, + 0xE1};//STICK_CONF_MAX, + +const u8 HID_GC_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x05, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x26, //STICK_CONF_MIN, + 0xE1};//STICK_CONF_MAX, + +const u8 HID_GC_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x06, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x1A, //STICK_CONF_MIN, + 0xDB};//STICK_CONF_MAX, + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! DS3 +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +const u8 HID_DS3_BUTTON_CROSS[] = { 0x03,HID_DS3_BUTTON_CROSS_VALUE}; +const u8 HID_DS3_BUTTON_CIRCLE[] = { 0x03,HID_DS3_BUTTON_CIRCLE_VALUE}; +const u8 HID_DS3_BUTTON_SQUARE [] = { 0x03,HID_DS3_BUTTON_SQUARE_VALUE}; +const u8 HID_DS3_BUTTON_TRIANGLE[] = { 0x03,HID_DS3_BUTTON_TRIANGLE_VALUE}; + +const u8 HID_DS3_BUTTON_L1[] = { 0x03,HID_DS3_BUTTON_L1_VALUE}; +const u8 HID_DS3_BUTTON_L2[] = { 0x03,HID_DS3_BUTTON_L2_VALUE}; +const u8 HID_DS3_BUTTON_R1[] = { 0x03,HID_DS3_BUTTON_R1_VALUE}; +const u8 HID_DS3_BUTTON_R2[] = { 0x03,HID_DS3_BUTTON_R2_VALUE}; + +const u8 HID_DS3_BUTTON_L3[] = { 0x02,HID_DS3_BUTTON_L3_VALUE}; +const u8 HID_DS3_BUTTON_R3[] = { 0x02,HID_DS3_BUTTON_R3_VALUE}; +const u8 HID_DS3_BUTTON_SELECT[] = { 0x02,HID_DS3_BUTTON_SELECT_VALUE}; +const u8 HID_DS3_BUTTON_START[] = { 0x02,HID_DS3_BUTTON_START_VALUE}; +const u8 HID_DS3_BUTTON_LEFT[] = { 0x02,HID_DS3_BUTTON_LEFT_VALUE}; +const u8 HID_DS3_BUTTON_RIGHT[] = { 0x02,HID_DS3_BUTTON_RIGHT_VALUE}; +const u8 HID_DS3_BUTTON_UP[] = { 0x02,HID_DS3_BUTTON_UP_VALUE}; +const u8 HID_DS3_BUTTON_DOWN[] = { 0x02,HID_DS3_BUTTON_DOWN_VALUE}; + +const u8 HID_DS3_BUTTON_GUIDE[] = { 0x04,HID_DS3_BUTTON_GUIDE_VALUE}; + +const u8 HID_DS3_BUTTON_DPAD_TYPE[] = { CONTRPDM_Normal,0x00}; + +const u8 HID_DS3_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x06, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS3_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x07, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS3_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x08, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS3_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x09, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! DS4 +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +const u8 HID_DS4_BUTTON_CROSS[] = { 0x05,HID_DS4_BUTTON_CROSS_VALUE}; +const u8 HID_DS4_BUTTON_CIRCLE[] = { 0x05,HID_DS4_BUTTON_CIRCLE_VALUE}; +const u8 HID_DS4_BUTTON_SQUARE [] = { 0x05,HID_DS4_BUTTON_SQUARE_VALUE}; +const u8 HID_DS4_BUTTON_TRIANGLE[] = { 0x05,HID_DS4_BUTTON_TRIANGLE_VALUE}; + +const u8 HID_DS4_BUTTON_L1[] = { 0x06,HID_DS4_BUTTON_L1_VALUE}; +const u8 HID_DS4_BUTTON_L2[] = { 0x06,HID_DS4_BUTTON_L2_VALUE}; +const u8 HID_DS4_BUTTON_L3[] = { 0x06,HID_DS4_BUTTON_L3_VALUE}; + +const u8 HID_DS4_BUTTON_R1[] = { 0x06,HID_DS4_BUTTON_R1_VALUE}; +const u8 HID_DS4_BUTTON_R2[] = { 0x06,HID_DS4_BUTTON_R2_VALUE}; +const u8 HID_DS4_BUTTON_R3[] = { 0x06,HID_DS4_BUTTON_R3_VALUE}; + +const u8 HID_DS4_BUTTON_SHARE[] = { 0x06,HID_DS4_BUTTON_SHARE_VALUE}; +const u8 HID_DS4_BUTTON_OPTIONS[] = { 0x06,HID_DS4_BUTTON_OPTIONS_VALUE}; + + +const u8 HID_DS4_BUTTON_DPAD_TYPE[] = { CONTRPDM_Hat,HID_DS4_BUTTON_DPAD_MASK_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_N[] = { 0x05,HID_DS4_BUTTON_DPAD_N_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_NE[] = { 0x05,HID_DS4_BUTTON_DPAD_NE_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_E[] = { 0x05,HID_DS4_BUTTON_DPAD_E_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_SE[] = { 0x05,HID_DS4_BUTTON_DPAD_SE_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_S[] = { 0x05,HID_DS4_BUTTON_DPAD_S_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_SW[] = { 0x05,HID_DS4_BUTTON_DPAD_SW_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_W[] = { 0x05,HID_DS4_BUTTON_DPAD_W_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_NW[] = { 0x05,HID_DS4_BUTTON_DPAD_NW_VALUE}; +const u8 HID_DS4_BUTTON_DPAD_NEUTRAL[] = { 0x05,HID_DS4_BUTTON_DPAD_NEUTRAL_VALUE}; + +const u8 HID_DS4_BUTTON_GUIDE[] = { 0x07,HID_DS4_BUTTON_GUIDE_VALUE}; +const u8 HID_DS4_BUTTON_T_PAD_CLICK[] = { 0x07,HID_DS4_BUTTON_T_PAD_CLICK_VALUE}; + +const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x01, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x06, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x02, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x05, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x03, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x07, //STICK_CONF_DEADZONE, + 0x00, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + +const u8 HID_DS4_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION + 0x04, //STICK_CONF_BYTE, + 0x80, //STICK_CONF_DEFAULT, + 0x09, //STICK_CONF_DEADZONE, + 0x01, //STICK_CONF_INVERT, + 0x00, //STICK_CONF_MIN, + 0xFF};//STICK_CONF_MAX, + + diff --git a/pad_const.h b/pad_const.h new file mode 100644 index 0000000..33f3e09 --- /dev/null +++ b/pad_const.h @@ -0,0 +1,146 @@ +/**************************************************************************** + * Copyright (C) 2016 Maschell + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ****************************************************************************/ + +#ifndef _PAD_CONST_H_ +#define _PAD_CONST_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "controller_patcher.h" + +extern const u8 DEF_L_STICK_UP; +extern const u8 DEF_L_STICK_DOWN; +extern const u8 DEF_L_STICK_LEFT; +extern const u8 DEF_L_STICK_RIGHT; + +extern const u8 DEF_R_STICK_UP; +extern const u8 DEF_R_STICK_DOWN; +extern const u8 DEF_R_STICK_LEFT; +extern const u8 DEF_R_STICK_RIGHT; + +extern const u8 DEF_R_STICK; +extern const u8 DEF_L_STICK; + +extern const u8 DEF_STICK_OFFSET_INVERT; +extern const u8 DEF_STICK_OFFSET_DEADZONE; +extern const u8 DEF_STICK_OFFSET_MINMAX; + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! GC_Adapter +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +extern const u8 HID_GC_BUTTON_A[]; +extern const u8 HID_GC_BUTTON_B[]; +extern const u8 HID_GC_BUTTON_X[]; +extern const u8 HID_GC_BUTTON_Y[]; +extern const u8 HID_GC_BUTTON_LEFT[]; +extern const u8 HID_GC_BUTTON_RIGHT[]; +extern const u8 HID_GC_BUTTON_DOWN[]; +extern const u8 HID_GC_BUTTON_UP[]; + +extern const u8 HID_GC_BUTTON_START[]; +extern const u8 HID_GC_BUTTON_Z[]; + +extern const u8 HID_GC_BUTTON_L[]; +extern const u8 HID_GC_BUTTON_R[]; + +extern const u8 HID_GC_BUTTON_DPAD_TYPE[]; + +extern const u8 HID_GC_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_GC_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_GC_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_GC_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; + + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! DS3 +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +extern const u8 HID_DS3_BUTTON_CROSS[]; +extern const u8 HID_DS3_BUTTON_CIRCLE[]; +extern const u8 HID_DS3_BUTTON_SQUARE []; +extern const u8 HID_DS3_BUTTON_TRIANGLE[]; + +extern const u8 HID_DS3_BUTTON_L1[]; +extern const u8 HID_DS3_BUTTON_L2[]; +extern const u8 HID_DS3_BUTTON_R1[]; +extern const u8 HID_DS3_BUTTON_R2[]; + +extern const u8 HID_DS3_BUTTON_L3[]; +extern const u8 HID_DS3_BUTTON_R3[]; +extern const u8 HID_DS3_BUTTON_SELECT[]; +extern const u8 HID_DS3_BUTTON_START[]; +extern const u8 HID_DS3_BUTTON_LEFT[]; +extern const u8 HID_DS3_BUTTON_RIGHT[]; +extern const u8 HID_DS3_BUTTON_UP[]; +extern const u8 HID_DS3_BUTTON_DOWN[]; + +extern const u8 HID_DS3_BUTTON_GUIDE[]; + +extern const u8 HID_DS3_BUTTON_DPAD_TYPE[]; + +extern const u8 HID_DS3_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS3_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS3_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS3_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; + +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +//! DS4 +//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +extern const u8 HID_DS4_BUTTON_CROSS[]; +extern const u8 HID_DS4_BUTTON_CIRCLE[]; +extern const u8 HID_DS4_BUTTON_SQUARE []; +extern const u8 HID_DS4_BUTTON_TRIANGLE[]; + +extern const u8 HID_DS4_BUTTON_L1[]; +extern const u8 HID_DS4_BUTTON_L2[]; +extern const u8 HID_DS4_BUTTON_L3[]; +extern const u8 HID_DS4_BUTTON_R1[]; +extern const u8 HID_DS4_BUTTON_R2[]; +extern const u8 HID_DS4_BUTTON_R3[]; + +extern const u8 HID_DS4_BUTTON_SHARE[]; +extern const u8 HID_DS4_BUTTON_OPTIONS[]; + +extern const u8 HID_DS4_BUTTON_DPAD_TYPE[]; +extern const u8 HID_DS4_BUTTON_DPAD_N[]; +extern const u8 HID_DS4_BUTTON_DPAD_NE[]; +extern const u8 HID_DS4_BUTTON_DPAD_E[]; +extern const u8 HID_DS4_BUTTON_DPAD_SE[]; +extern const u8 HID_DS4_BUTTON_DPAD_S[]; +extern const u8 HID_DS4_BUTTON_DPAD_SW[]; +extern const u8 HID_DS4_BUTTON_DPAD_W[]; +extern const u8 HID_DS4_BUTTON_DPAD_NW[]; +extern const u8 HID_DS4_BUTTON_DPAD_NEUTRAL[]; + +extern const u8 HID_DS4_BUTTON_GUIDE[]; +extern const u8 HID_DS4_BUTTON_T_PAD_CLICK[]; + +extern const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; +extern const u8 HID_DS4_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; + +#ifdef __cplusplus +} +#endif + +#endif /* _PAD_CONST_H_ */ diff --git a/string_tools.cpp b/string_tools.cpp new file mode 100644 index 0000000..a844f09 --- /dev/null +++ b/string_tools.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include +#include +#include +#include "string_tools.hpp" + +bool EndsWith(const std::string& a, const std::string& b) { + if (b.size() > a.size()) return false; + return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); +} + +std::vector MyStringSplit(const std::string & inValue, const std::string & splitter) +{ + std::string value = inValue; + std::vector result; + while (true) { + unsigned int index = value.find(splitter); + if (index == std::string::npos) { + result.push_back(value); + break; + } + std::string first = value.substr(0, index); + result.push_back(first); + if (index + splitter.size() == value.length()) { + result.push_back(""); + break; + } + if(index + splitter.size() > value.length()) { + break; + } + value = value.substr(index + splitter.size(), value.length()); + } + return result; +} + + +extern "C" const char *byte_to_binary(int x) +{ + static char b[9]; + b[0] = '\0'; + + int z; + for (z = 128; z > 0; z >>= 1) + { + strcat(b, ((x & z) == z) ? "1" : "0"); + } + + return b; +} diff --git a/string_tools.hpp b/string_tools.hpp new file mode 100644 index 0000000..07f51a2 --- /dev/null +++ b/string_tools.hpp @@ -0,0 +1,19 @@ +#ifndef _STRING_TOOLS_H_ +#define _STRING_TOOLS_H_ + +bool EndsWith(const std::string& a, const std::string& b); +std::vector MyStringSplit(const std::string & inValue, const std::string & splitter); + +/* Main */ +#ifdef __cplusplus +extern "C" { +#endif + +//! C wrapper for our C++ functions +const char *byte_to_binary(int x); + +#ifdef __cplusplus +} +#endif + +#endif /* _STRING_TOOLS_H_ */