From e80d99dbae6856c579af3e67714c3df1e6e83926 Mon Sep 17 00:00:00 2001 From: Nathan Strong Date: Thu, 30 Nov 2017 23:37:20 -0800 Subject: [PATCH 01/26] Delete controller_patcher; start on proper HID driver == DETAILS We discovered that the controller_patcher code was causing the WiiU to intermittently crash when switching ROMs. Changes: - Completely extricates the controller_patcher code - Create a skeleton wiiu_hid driver - Wire up the build system to build/link it successfully == TESTING Has not been tested. Probably doesn't crash, since the skeleton driver is just a copy of the null driver. --- .gitignore | 4 +- Makefile.wiiu | 4 +- frontend/drivers/platform_wiiu.c | 10 - input/drivers_hid/wiiu_hid.c | 103 ++ input/drivers_joypad/wiiu_joypad.c | 78 +- input/input_driver.c | 3 + input/input_driver.h | 1 + wiiu/controller_patcher/ConfigReader.cpp | 158 --- wiiu/controller_patcher/ConfigReader.hpp | 74 -- wiiu/controller_patcher/ControllerPatcher.cpp | 1088 ----------------- wiiu/controller_patcher/ControllerPatcher.hpp | 251 ---- .../ControllerPatcherWrapper.cpp | 39 - .../ControllerPatcherWrapper.h | 23 - .../config/ConfigParser.cpp | 349 ------ .../config/ConfigParser.hpp | 74 -- .../config/ConfigValues.cpp | 121 -- .../config/ConfigValues.hpp | 569 --------- .../network/ControllerPatcherNet.cpp | 50 - .../network/ControllerPatcherNet.hpp | 17 - wiiu/controller_patcher/network/TCPServer.cpp | 371 ------ wiiu/controller_patcher/network/TCPServer.hpp | 94 -- wiiu/controller_patcher/network/UDPClient.cpp | 58 - wiiu/controller_patcher/network/UDPClient.hpp | 67 - wiiu/controller_patcher/network/UDPServer.cpp | 168 --- wiiu/controller_patcher/network/UDPServer.hpp | 57 - .../patcher/ControllerPatcherDefs.h | 710 ----------- .../patcher/ControllerPatcherHID.cpp | 713 ----------- .../patcher/ControllerPatcherHID.hpp | 74 -- .../patcher/ControllerPatcherUtils.cpp | 935 -------------- .../patcher/ControllerPatcherUtils.hpp | 320 ----- .../controller_patcher/utils/CPRetainVars.cpp | 73 -- .../controller_patcher/utils/CPRetainVars.hpp | 76 -- .../utils/CPStringTools.cpp | 85 -- .../utils/CPStringTools.hpp | 17 - .../utils/ControllerPatcherThread.hpp | 119 -- wiiu/controller_patcher/utils/FSHelper.c | 78 -- wiiu/controller_patcher/utils/FSHelper.h | 17 - wiiu/controller_patcher/utils/PadConst.cpp | 341 ------ wiiu/controller_patcher/utils/PadConst.hpp | 211 ---- 39 files changed, 118 insertions(+), 7482 deletions(-) create mode 100644 input/drivers_hid/wiiu_hid.c delete mode 100644 wiiu/controller_patcher/ConfigReader.cpp delete mode 100644 wiiu/controller_patcher/ConfigReader.hpp delete mode 100644 wiiu/controller_patcher/ControllerPatcher.cpp delete mode 100644 wiiu/controller_patcher/ControllerPatcher.hpp delete mode 100644 wiiu/controller_patcher/ControllerPatcherWrapper.cpp delete mode 100644 wiiu/controller_patcher/ControllerPatcherWrapper.h delete mode 100644 wiiu/controller_patcher/config/ConfigParser.cpp delete mode 100644 wiiu/controller_patcher/config/ConfigParser.hpp delete mode 100644 wiiu/controller_patcher/config/ConfigValues.cpp delete mode 100644 wiiu/controller_patcher/config/ConfigValues.hpp delete mode 100644 wiiu/controller_patcher/network/ControllerPatcherNet.cpp delete mode 100644 wiiu/controller_patcher/network/ControllerPatcherNet.hpp delete mode 100644 wiiu/controller_patcher/network/TCPServer.cpp delete mode 100644 wiiu/controller_patcher/network/TCPServer.hpp delete mode 100644 wiiu/controller_patcher/network/UDPClient.cpp delete mode 100644 wiiu/controller_patcher/network/UDPClient.hpp delete mode 100644 wiiu/controller_patcher/network/UDPServer.cpp delete mode 100644 wiiu/controller_patcher/network/UDPServer.hpp delete mode 100644 wiiu/controller_patcher/patcher/ControllerPatcherDefs.h delete mode 100644 wiiu/controller_patcher/patcher/ControllerPatcherHID.cpp delete mode 100644 wiiu/controller_patcher/patcher/ControllerPatcherHID.hpp delete mode 100644 wiiu/controller_patcher/patcher/ControllerPatcherUtils.cpp delete mode 100644 wiiu/controller_patcher/patcher/ControllerPatcherUtils.hpp delete mode 100644 wiiu/controller_patcher/utils/CPRetainVars.cpp delete mode 100644 wiiu/controller_patcher/utils/CPRetainVars.hpp delete mode 100644 wiiu/controller_patcher/utils/CPStringTools.cpp delete mode 100644 wiiu/controller_patcher/utils/CPStringTools.hpp delete mode 100644 wiiu/controller_patcher/utils/ControllerPatcherThread.hpp delete mode 100644 wiiu/controller_patcher/utils/FSHelper.c delete mode 100644 wiiu/controller_patcher/utils/FSHelper.h delete mode 100644 wiiu/controller_patcher/utils/PadConst.cpp delete mode 100644 wiiu/controller_patcher/utils/PadConst.hpp diff --git a/.gitignore b/.gitignore index 918fe5bd01..5ca1b6a8ea 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,9 @@ wiiu/wut/elf2rpl/elf2rpl /.lst *.3dsx *.smdh +/pkg/wiiu/retroarch +/pkg/wiiu/wiiu +/pkg/wiiu/rpx # Ctags /tags @@ -115,6 +118,5 @@ obj-unix/ /pkg/msvc/msvc-2010/Release Cg/*.obj /pkg/msvc/msvc-2010/Release Cg/*.res /pkg/msvc/msvc-2010/Release Cg/*.pdb - retroarch.cfg Makefile.local diff --git a/Makefile.wiiu b/Makefile.wiiu index 18337b520e..cd2bdad24e 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -1,9 +1,10 @@ TARGET := retroarch_wiiu BUILD_HBL_ELF = 1 -BUILD_RPX = 1 +BUILD_RPX = 1 DEBUG = 0 GRIFFIN_BUILD = 0 WHOLE_ARCHIVE_LINK = 0 +HAVE_HID = 1 ifneq ($(V), 1) Q := @ @@ -13,6 +14,7 @@ PC_DEVELOPMENT_IP_ADDRESS ?= PC_DEVELOPMENT_TCP_PORT ?= OBJ := +OBJ += input/drivers_hid/wiiu_hid.o OBJ += wiiu/system/memory.o OBJ += wiiu/system/exception_handler.o OBJ += wiiu/system/missing_libc_functions.o diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index c616caf268..a188ebb3f0 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -58,10 +58,6 @@ #include #include -#if defined(ENABLE_CONTROLLER_PATCHER) - #include "wiiu/controller_patcher/ControllerPatcherWrapper.h" -#endif - #include #include #include "wiiu_dbg.h" @@ -432,9 +428,6 @@ int main(int argc, char **argv) KPADInit(); #endif verbosity_enable(); -#if !defined(IS_SALAMANDER) && defined(ENABLE_CONTROLLER_PATCHER) - ControllerPatcherInit(); -#endif fflush(stdout); DEBUG_VAR(ARGV_PTR); if(ARGV_PTR && ((u32)ARGV_PTR < 0x01000000)) @@ -494,9 +487,6 @@ int main(int argc, char **argv) } while (1); -#if !defined(IS_SALAMANDER) && defined(ENABLE_CONTROLLER_PATCHER) - ControllerPatcherDeInit(); -#endif main_exit(NULL); #endif #endif diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c new file mode 100644 index 0000000000..a6cafe552b --- /dev/null +++ b/input/drivers_hid/wiiu_hid.c @@ -0,0 +1,103 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2013-2014 - Jason Fetters + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +#include + +#include "../input_defines.h" +#include "../input_driver.h" + +typedef struct wiiu_hid +{ + void *empty; +} wiiu_hid_t; + +static bool wiiu_hid_joypad_query(void *data, unsigned pad) +{ + return pad < MAX_USERS; +} + +static const char *wiiu_hid_joypad_name(void *data, unsigned pad) +{ + return NULL; +} + +static uint64_t wiiu_hid_joypad_get_buttons(void *data, unsigned port) +{ + (void)data; + (void)port; + + return 0; +} + +static bool wiiu_hid_joypad_button(void *data, unsigned port, uint16_t joykey) +{ + (void)data; + (void)port; + (void)joykey; + + return false; +} + +static bool wiiu_hid_joypad_rumble(void *data, unsigned pad, + enum retro_rumble_effect effect, uint16_t strength) +{ + (void)data; + (void)pad; + (void)effect; + (void)strength; + + return false; +} + +static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) +{ + (void)data; + (void)port; + (void)joyaxis; + + return 0; +} + +static void *wiiu_hid_init(void) +{ + return (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t)); +} + +static void wiiu_hid_free(void *data) +{ + wiiu_hid_t *hid_wiiu = (wiiu_hid_t*)data; + + if (hid_wiiu) + free(hid_wiiu); +} + +static void wiiu_hid_poll(void *data) +{ + (void)data; +} + +hid_driver_t wiiu_hid = { + wiiu_hid_init, + wiiu_hid_joypad_query, + wiiu_hid_free, + wiiu_hid_joypad_button, + wiiu_hid_joypad_get_buttons, + wiiu_hid_joypad_axis, + wiiu_hid_poll, + wiiu_hid_joypad_rumble, + wiiu_hid_joypad_name, + "wiiu", +}; diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index b7c46b995f..4fb667c34d 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -21,10 +21,6 @@ #include #include -#if defined(ENABLE_CONTROLLER_PATCHER) - #include "wiiu/controller_patcher/ControllerPatcherWrapper.h" -#endif - #include "../input_driver.h" #include "../../tasks/tasks_internal.h" @@ -35,12 +31,8 @@ #include "wiiu_dbg.h" -#if !defined(MAX_PADS) - #if defined(ENABLE_CONTROLLER_PATCHER) - #define MAX_PADS 16 - #else - #define MAX_PADS 5 - #endif +#ifndef MAX_PADS +#define MAX_PADS 5 #endif #define WIIUINPUT_TYPE_WIIMOTE 0x00 @@ -49,24 +41,10 @@ #define WIIUINPUT_TYPE_PRO_CONTROLLER 0x1F #define WIIUINPUT_TYPE_NONE 0xFD -#define GAMEPAD_COUNT 1 -#define KPAD_COUNT 4 #define GAMEPAD_OFFSET 0 -#define KPAD_OFFSET (GAMEPAD_OFFSET + GAMEPAD_COUNT) - -#if defined(ENABLE_CONTROLLER_PATCHER) - #define HID_COUNT (MAX_PADS - GAMEPAD_COUNT - KPAD_COUNT) - #define HID_OFFSET (KPAD_OFFSET + KPAD_COUNT) -#endif static uint64_t pad_state[MAX_PADS]; -static uint8_t pad_type[KPAD_COUNT] = {WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE}; - -#if defined(ENABLE_CONTROLLER_PATCHER) -static uint8_t hid_status[HID_COUNT]; -static InputData hid_data[HID_COUNT]; -static char hidName[HID_COUNT][255]; -#endif +static uint8_t pad_type[MAX_PADS-1] = {WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE}; /* 3 axis - one for touch/future IR support? */ static int16_t analog_state[MAX_PADS][3][2]; @@ -79,10 +57,9 @@ static const char* wiiu_joypad_name(unsigned pad) if (pad == GAMEPAD_OFFSET) return "WIIU Gamepad"; - if (pad >= KPAD_OFFSET && pad < KPAD_OFFSET + KPAD_COUNT) + if (pad < MAX_PADS) { - int i = pad - KPAD_OFFSET; - switch (pad_type[i]) + switch (pad_type[pad-1]) { case WIIUINPUT_TYPE_PRO_CONTROLLER: return "WIIU Pro Controller"; @@ -102,15 +79,6 @@ static const char* wiiu_joypad_name(unsigned pad) } } - #if defined(ENABLE_CONTROLLER_PATCHER) - if (pad >= HID_OFFSET && pad < HID_OFFSET + HID_COUNT) - { - s32 hid_index = pad - HID_OFFSET; - sprintf(hidName[hid_index], "HID %04X/%04X(%02X)", hid_data[hid_index].device_info.vidpid.vid, hid_data[hid_index].device_info.vidpid.pid, hid_data[hid_index].pad); - return hidName[hid_index]; - } - #endif //defined(ENABLE_CONTROLLER_PATCHER) - return "unknown"; } @@ -327,48 +295,12 @@ static void wiiu_joypad_poll(void) break; } } - - #if defined(ENABLE_CONTROLLER_PATCHER) - memset(hid_data,0,sizeof(hid_data)); - result = gettingInputAllDevices(hid_data,HID_COUNT); - - if (result + HID_OFFSET > MAX_PADS) - result = MAX_PADS - HID_OFFSET; - - for(i = HID_OFFSET;i < result + HID_OFFSET; i++) - { - int hid_index = i-HID_OFFSET; - uint8_t old_status = hid_status[hid_index]; - uint8_t new_status = hid_data[hid_index].status;/* TODO: defines for the status. */ - - if (old_status == 1 || new_status == 1) - { - hid_status[hid_index] = new_status; - if (old_status == 0 && new_status == 1) /* Pad was attached */ - wiiu_joypad_autodetect_add(i); - else if (old_status == 1 && new_status == 0) /* Pad was detached */ - input_autoconfigure_disconnect(i, wiiu_joypad.ident); - else if (old_status == 1 && new_status == 1) /* Pad still connected */ - { - pad_state[i] = hid_data[hid_index].button_data.hold & ~0x7F800000; /* clear out emulated analog sticks */ - analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = hid_data[hid_index].stick_data.leftStickX * 0x7FF0; - analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = hid_data[hid_index].stick_data.leftStickY * 0x7FF0; - analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = hid_data[hid_index].stick_data.rightStickX * 0x7FF0; - analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = hid_data[hid_index].stick_data.rightStickY * 0x7FF0; - } - } - } - #endif //defined(ENABLE_CONTROLLER_PATCHER) } static bool wiiu_joypad_init(void* data) { wiiu_joypad_autodetect_add(0); - #if defined(ENABLE_CONTROLLER_PATCHER) - memset(hid_status,0,sizeof(hid_status)); - #endif - wiiu_joypad_poll(); wiiu_pad_inited = true; (void)data; diff --git a/input/input_driver.c b/input/input_driver.c index a0bd3a3fa7..6dc5d6908d 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -196,6 +196,9 @@ static hid_driver_t *hid_drivers[] = { #endif #ifdef HW_RVL &wiiusb_hid, +#endif +#ifdef WIIU + &wiiu_hid, #endif &null_hid, NULL, diff --git a/input/input_driver.h b/input/input_driver.h index d8fb72648e..dcc7c0df2b 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -825,6 +825,7 @@ extern hid_driver_t iohidmanager_hid; extern hid_driver_t btstack_hid; extern hid_driver_t libusb_hid; extern hid_driver_t wiiusb_hid; +extern hid_driver_t wiiu_hid; extern hid_driver_t null_hid; #endif diff --git a/wiiu/controller_patcher/ConfigReader.cpp b/wiiu/controller_patcher/ConfigReader.cpp deleted file mode 100644 index bc51064f5b..0000000000 --- a/wiiu/controller_patcher/ConfigReader.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "./ConfigReader.hpp" - -#include -#include -#include -#include - -#include "wiiu/fs.h" -#include "wiiu/controller_patcher/utils/FSHelper.h" - -#define FS_MOUNT_SOURCE_SIZE 0x300 -#define FS_MAX_MOUNTPATH_SIZE 12 - -#define FS_CLIENT_SIZE 0x1700 -#define FS_CMD_BLOCK_SIZE 0xA80 - -#define FS_SOURCETYPE_EXTERNAL 0 -#define FS_SOURCETYPE_HFIO 1 - -s32 ConfigReader::numberValidFiles = 0; -ConfigReader *ConfigReader::instance = NULL; - -ConfigReader::ConfigReader(){ -} - -void ConfigReader::ReadAllConfigs(){ - std::vector fileList = ScanFolder(); - if(fileList.size() > 0){ - if(HID_DEBUG){ printf("ConfigReader::ConfigReader(line %d): Found %d config files\n",__LINE__,fileList.size()); } - processFileList(fileList); - } -} - - -ConfigReader::~ConfigReader(){ - if(HID_DEBUG){ printf("ConfigReader::~ConfigReader(line %d): ~ConfigReader\n",__LINE__); } - freeFSHandles(); -} - -void ConfigReader::freeFSHandles(){ - if(this->pClient != NULL){ - FSDelClient((FSClient *)this->pClient,-1); - free(this->pClient); - this->pClient = NULL; - } - if(this->pCmd != NULL){ - free(this->pCmd); - this->pCmd = NULL; - } -} - - -// Mounting the sdcard without any external lib to be portable (Currently broken) -s32 ConfigReader::InitSDCard(){ - if(HID_DEBUG){ printf("ConfigReader::InitSDCard(line %d): InitSDCard\n",__LINE__); } - - int result = -1; - - // get command and client - this->pClient = malloc(sizeof(FSClient)); - this->pCmd = malloc(sizeof(FSCmdBlock)); - - if(!pClient || !pCmd) { - // just in case free if not 0 - if(pClient) - free(pClient); - if(pCmd) - free(pCmd); - return -2; - } - - FSInit(); - FSInitCmdBlock((FSCmdBlock*)pCmd); - FSAddClient((FSClient*)pClient, -1); - - char *mountPath = NULL; - - if((result = FS_Helper_MountFS(pClient, pCmd, &mountPath)) == 0) { - //free(mountPath); - } - - return result; -} - -std::vector ConfigReader::ScanFolder(){ - std::string path = CONTROLLER_PATCHER_PATH; - s32 dirhandle = 0; - if(HID_DEBUG){ printf("ConfigReader::ScanFolder(line %d): Opening %s\n",__LINE__,path.c_str()); } - std::vector config_files; - if (this->pClient && this->pCmd){ - s32 status = 0; - if((status = FSOpenDir((FSClient*)this->pClient,(FSCmdBlock*)this->pCmd,path.c_str(),(FSDirectoryHandle *)&dirhandle,-1)) == FS_STATUS_OK){ - FSDirectoryEntry dir_entry; - while (FSReadDir((FSClient*)this->pClient,(FSCmdBlock*)this->pCmd, dirhandle, &dir_entry, -1) == FS_STATUS_OK){ - std::string full_path = path + "/" + dir_entry.name; - if((dir_entry.info.flags&FS_STAT_DIRECTORY) != FS_STAT_DIRECTORY){ - if(CPStringTools::EndsWith(std::string(dir_entry.name),".ini")){ - config_files.push_back(full_path); - if(HID_DEBUG){ printf("ConfigReader::ScanFolder(line %d): %s \n",__LINE__,full_path.c_str()); } - } - } - } - FSCloseDir((FSClient*)this->pClient,(FSCmdBlock*)this->pCmd,dirhandle,-1); - }else{ - printf("ConfigReader::ScanFolder(line %d): Failed to open %s!\n",__LINE__,path.c_str()); - } - } - return config_files; -} - -void ConfigReader::processFileList(std::vector path){ - - for(std::vector::iterator it = path.begin(); it != path.end(); ++it) { - printf("ConfigReader::processFileList(line %d): Reading %s\n",__LINE__,it->c_str()); - std::string result = loadFileToString(*it); - - ConfigParser parser(result); - parser.parseIni(); - } -} - -std::string ConfigReader::loadFileToString(std::string path){ - FSFileHandle handle = 0; - s32 status = 0; - std::string strBuffer; - char * result = NULL; - if(FS_Helper_GetFile(this->pClient,this->pCmd,path.c_str(), &result) == 0){ - if(result != NULL){ - strBuffer = std::string((char *)result); - free(result); - result = NULL; - - //! remove all windows crap signs - strBuffer = CPStringTools::removeCharFromString(strBuffer,'\r'); - strBuffer = CPStringTools::removeCharFromString(strBuffer,' '); - strBuffer = CPStringTools::removeCharFromString(strBuffer,'\t'); - } - }else{ - printf("ConfigReader::loadFileToString(line %d): Failed to load %s\n",__LINE__,path.c_str()); - } - return strBuffer; -} diff --git a/wiiu/controller_patcher/ConfigReader.hpp b/wiiu/controller_patcher/ConfigReader.hpp deleted file mode 100644 index 7a6906ce64..0000000000 --- a/wiiu/controller_patcher/ConfigReader.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "./ControllerPatcher.hpp" - -#define CONTROLLER_PATCHER_PATH "/vol/external01/wiiu/controller"; - -class ConfigReader{ - friend class ControllerPatcher; - friend class ConfigParser; - private: - static ConfigReader *getInstance() { - if(!instance){ - instance = new ConfigReader(); - } - return instance; - } - - static void destroyInstance() { - if(instance){ - delete instance; - instance = NULL; - } - } - - static s32 getNumberOfLoadedFiles(){ - return ConfigReader::numberValidFiles; - } - - static void increaseNumberOfLoadedFiles(){ - ConfigReader::numberValidFiles++; - } - void ReadAllConfigs(); - static s32 numberValidFiles; - - //!Constructor - ConfigReader(); - //!Destructor - ~ConfigReader(); - - s32 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/wiiu/controller_patcher/ControllerPatcher.cpp b/wiiu/controller_patcher/ControllerPatcher.cpp deleted file mode 100644 index 67c9833729..0000000000 --- a/wiiu/controller_patcher/ControllerPatcher.cpp +++ /dev/null @@ -1,1088 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "ControllerPatcher.hpp" -#include -#include - -#include -#include -#include - -#include "wiiu/sysapp.h" -#include "wiiu/syshid.h" -#include "sys/socket.h" -#include "wiiu/kpad.h" - -#include "utils/CPRetainVars.hpp" - -// This stores the holded buttons for the gamepad after the button remapping. -static u32 buttonRemapping_lastButtonsHold = 0; - -/* To set the controls of an Pro Controler, we first get the result for an Gamepad and convert them later. This way both can share the same functions.*/ - -// This arrays stores the last hold buttons of the Pro Controllers. One u32 for each channel of the controllers -static u32 last_button_hold[4] = {0,0,0,0}; -// This arrays stores the VPADStatus that will be used to get the HID Data for the Pro Controllers. One for each channel. -static VPADStatus myVPADBuffer[4]; - -void ControllerPatcher::InitButtonMapping(){ - if(HID_DEBUG){ printf("ControllerPatcher::InitButtonMapping(line %d): Init called \n",__LINE__); } - if(!gButtonRemappingConfigDone){ - if(HID_DEBUG){ printf("ControllerPatcher::InitButtonMapping(line %d): Remapping is running! \n",__LINE__); } - 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; - - 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 ControllerPatcher::ResetConfig(){ - memset(connectionOrderHelper,0,sizeof(connectionOrderHelper)); - memset(&gControllerMapping,0,sizeof(gControllerMapping)); // Init / Invalid everything - memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // Init / Invalid everything - memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); // Init / Invalid everything - memset(gNetworkController,0,sizeof(gNetworkController)); // Init / Invalid everything - memset(gHID_Devices,0,sizeof(gHID_Devices)); // Init / Invalid everything - - memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback)); - memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback)); - memset(gExtensionCallback,0,sizeof(gExtensionCallback)); - gCallbackCooldown = 0; - - gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; - gHID_LIST_GC = 0; - gHID_LIST_DS3 = 0; - gHID_LIST_DS4 = 0; - gHID_LIST_KEYBOARD = 0; - gHID_LIST_MOUSE = 0; - gGamePadSlot = 0; - gHID_SLOT_GC = 0; - gHID_SLOT_KEYBOARD = 0; - gMouseSlot = 0; - - HIDSlotData slotdata; - gHIDRegisteredDevices = 0; - ControllerPatcherUtils::getNextSlotData(&slotdata); - gGamePadSlot = slotdata.deviceslot; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register Gamepad-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(slotdata.hidmask),gGamePadSlot); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - gMouseSlot = slotdata.deviceslot; - gHID_LIST_MOUSE = slotdata.hidmask; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register Mouse-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_MOUSE),gMouseSlot); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 keyboard_slot = slotdata.deviceslot; - u32 keyboard_hid = slotdata.hidmask; - gHID_LIST_KEYBOARD = keyboard_hid; - gHID_SLOT_KEYBOARD = keyboard_slot; - - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register Keyboard-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_KEYBOARD),gHID_SLOT_KEYBOARD); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 gc_slot = slotdata.deviceslot; - u32 gc_hid = slotdata.hidmask; - gHID_LIST_GC = gc_hid; - gHID_SLOT_GC = gc_slot; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register GC-Adapter-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_GC),gHID_SLOT_GC); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 ds3_slot = slotdata.deviceslot; - u32 ds3_hid = slotdata.hidmask; - gHID_LIST_DS3 = ds3_hid; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register DS3-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_DS3),ds3_slot); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 ds4_slot = slotdata.deviceslot; - u32 ds4_hid = slotdata.hidmask; - gHID_LIST_DS4 = ds4_hid; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register DS4-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(ds4_hid),ds4_slot); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 xinput_slot = slotdata.deviceslot; - u32 xinput_hid = slotdata.hidmask; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register XInput-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(xinput_hid),xinput_slot); } - - ControllerPatcherUtils::getNextSlotData(&slotdata); - u32 switch_pro_slot = slotdata.deviceslot; - gHID_LIST_SWITCH_PRO = slotdata.hidmask; - if(HID_DEBUG){ printf("ControllerPatcher::ResetConfig(line %d): Register Switch-Pro-Config. HID-Mask %s Device-Slot: %d\n",__LINE__,CPStringTools::byte_to_binary(gHID_LIST_SWITCH_PRO),switch_pro_slot); } - - - config_controller_hidmask[gc_slot] = gHID_LIST_GC; - config_controller_hidmask[ds3_slot] = gHID_LIST_DS3; - config_controller_hidmask[keyboard_slot] = gHID_LIST_KEYBOARD; - config_controller_hidmask[gMouseSlot] = gHID_LIST_MOUSE; - config_controller_hidmask[ds4_slot] = gHID_LIST_DS4; - config_controller_hidmask[xinput_slot] = xinput_hid; - config_controller_hidmask[switch_pro_slot] = gHID_LIST_SWITCH_PRO; - - /* We need to give the GamePad, Mouse and Keyboard a unique VID/PID to find the right slots.*/ - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! GamePad - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_VID], 0xAF,0xFE); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gGamePadSlot][CONTRPS_PID], 0xAA,0xAA); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Switch Pro Controller - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VID], (HID_SWITCH_PRO_VID>>8)&0xFF, HID_SWITCH_PRO_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_PID], (HID_SWITCH_PRO_PID>>8)&0xFF, HID_SWITCH_PRO_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_A], HID_SWITCH_PRO_BT_BUTTON_A[0], HID_SWITCH_PRO_BT_BUTTON_A[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_B], HID_SWITCH_PRO_BT_BUTTON_B[0], HID_SWITCH_PRO_BT_BUTTON_B[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_X], HID_SWITCH_PRO_BT_BUTTON_X[0], HID_SWITCH_PRO_BT_BUTTON_X[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_Y], HID_SWITCH_PRO_BT_BUTTON_Y[0], HID_SWITCH_PRO_BT_BUTTON_Y[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_N], HID_SWITCH_PRO_BT_BUTTON_DPAD_N[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_N[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NE], HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_E], HID_SWITCH_PRO_BT_BUTTON_DPAD_E[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_E[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_SE], HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_S], HID_SWITCH_PRO_BT_BUTTON_DPAD_S[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_S[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_SW], HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_W], HID_SWITCH_PRO_BT_BUTTON_DPAD_W[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_W[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NW], HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[0], HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_SWITCH_PRO_BT_BUTTON_PLUS[0], HID_SWITCH_PRO_BT_BUTTON_PLUS[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_SWITCH_PRO_BT_BUTTON_MINUS[0], HID_SWITCH_PRO_BT_BUTTON_MINUS[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L], HID_SWITCH_PRO_BT_BUTTON_L[0], HID_SWITCH_PRO_BT_BUTTON_L[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R], HID_SWITCH_PRO_BT_BUTTON_R[0], HID_SWITCH_PRO_BT_BUTTON_R[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_ZL], HID_SWITCH_PRO_BT_BUTTON_ZL[0], HID_SWITCH_PRO_BT_BUTTON_ZL[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_ZR], HID_SWITCH_PRO_BT_BUTTON_ZR[0], HID_SWITCH_PRO_BT_BUTTON_ZR[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_SWITCH_PRO_BT_BUTTON_STICK_L[0], HID_SWITCH_PRO_BT_BUTTON_STICK_L[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_SWITCH_PRO_BT_BUTTON_STICK_R[0], HID_SWITCH_PRO_BT_BUTTON_STICK_R[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_HOME], HID_SWITCH_PRO_BT_BUTTON_HOME[0], HID_SWITCH_PRO_BT_BUTTON_HOME[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_PAD_COUNT); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_BYTE], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_MIN], HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[switch_pro_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_INVERT]); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Mouse - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VID], (HID_MOUSE_VID>>8)&0xFF, HID_MOUSE_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_PID], (HID_MOUSE_PID>>8)&0xFF, HID_MOUSE_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_LEFT], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZR); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_VPAD_BUTTON_RIGHT], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_R); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gMouseSlot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_MOUSE_PAD_COUNT); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Keyboard - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VID], (HID_KEYBOARD_VID>>8)&0xFF, HID_KEYBOARD_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_PID], (HID_KEYBOARD_PID>>8)&0xFF, HID_KEYBOARD_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_A], 0x00, HID_KEYBOARD_BUTTON_E); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_B], 0x00, HID_KEYBOARD_BUTTON_Q); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_X], 0x00, HID_KEYBOARD_BUTTON_SPACEBAR); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_Y], 0x00, HID_KEYBOARD_BUTTON_R); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET,CONTRPDM_Normal); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_LEFT], 0x00, HID_KEYBOARD_BUTTON_LEFT); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_RIGHT], 0x00, HID_KEYBOARD_BUTTON_RIGHT); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_DOWN], 0x00, HID_KEYBOARD_BUTTON_DOWN); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_UP], 0x00, HID_KEYBOARD_BUTTON_UP); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_PLUS], 0x00, HID_KEYBOARD_BUTTON_RETURN); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_MINUS], 0x00, HID_KEYBOARD_KEYPAD_BUTTON_MINUS); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L], 0x00, HID_KEYBOARD_BUTTON_V); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R], 0x00, HID_KEYBOARD_BUTTON_B); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_ZL], 0x00, HID_KEYBOARD_BUTTON_SHIFT); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_ZR], 0x00, HID_KEYBOARD_BUTTON_N); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_L], 0x00, HID_KEYBOARD_BUTTON_F); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_STICK_R], 0x00, HID_KEYBOARD_BUTTON_TAB); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_UP], 0x00, HID_KEYBOARD_BUTTON_W); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_DOWN], 0x00, HID_KEYBOARD_BUTTON_S); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_LEFT], 0x00, HID_KEYBOARD_BUTTON_A); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_L_STICK_RIGHT], 0x00, HID_KEYBOARD_BUTTON_D); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_UP], 0x00, HID_KEYBOARD_KEYPAD_BUTTON_8); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_DOWN], 0x00, HID_KEYBOARD_KEYPAD_BUTTON_2); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_LEFT], 0x00, HID_KEYBOARD_KEYPAD_BUTTON_4); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_VPAD_BUTTON_R_STICK_RIGHT], 0x00, HID_KEYBOARD_KEYPAD_BUTTON_6); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_KEYBOARD][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET,HID_KEYBOARD_PAD_COUNT); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! GC-Adapter - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VID], (HID_GC_VID>>8)&0xFF, HID_GC_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_PID], (HID_GC_PID>>8)&0xFF, HID_GC_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_A], HID_GC_BUTTON_A[0], HID_GC_BUTTON_A[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_B], HID_GC_BUTTON_B[0], HID_GC_BUTTON_B[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_X], HID_GC_BUTTON_X[0], HID_GC_BUTTON_X[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_Y], HID_GC_BUTTON_Y[0], HID_GC_BUTTON_Y[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_GC_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_GC_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_LEFT], HID_GC_BUTTON_LEFT[0], HID_GC_BUTTON_LEFT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_RIGHT], HID_GC_BUTTON_RIGHT[0], HID_GC_BUTTON_RIGHT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_DOWN], HID_GC_BUTTON_DOWN[0], HID_GC_BUTTON_DOWN[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_UP], HID_GC_BUTTON_UP[0], HID_GC_BUTTON_UP[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_MINUS], HID_GC_BUTTON_START[0], HID_GC_BUTTON_START[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L], HID_GC_BUTTON_L[0], HID_GC_BUTTON_L[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R], HID_GC_BUTTON_R[0], HID_GC_BUTTON_R[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_PLUS], HID_GC_BUTTON_START[0], HID_GC_BUTTON_START[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_ZL], HID_GC_BUTTON_L[0], HID_GC_BUTTON_L[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_ZR], HID_GC_BUTTON_R[0], HID_GC_BUTTON_R[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_STICK_L], HID_GC_BUTTON_A[0], HID_GC_BUTTON_A[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_STICK_R], HID_GC_BUTTON_B[0], HID_GC_BUTTON_B[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE], CONTROLLER_PATCHER_VALUE_SET, CONTROLLER_PATCHER_GC_DOUBLE_USE); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR], HID_GC_BUTTON_Z[0], HID_GC_BUTTON_Z[1]); - - //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is pressed - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_MINUS); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_L); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_R); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_L); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_STICK_R); - - //Buttons that will be ignored when the CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR is released - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_PLUS); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZL); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_ZR); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_A); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED], CONTROLLER_PATCHER_VALUE_SET, CONTRPS_VPAD_BUTTON_B); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_GC_PAD_COUNT); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_L_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_L_Y[STICK_CONF_INVERT]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_R_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[gHID_SLOT_GC][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_GC_STICK_R_Y[STICK_CONF_INVERT]); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! DS3 - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VID], (HID_DS3_VID>>8)&0xFF, HID_DS3_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_PID], (HID_DS3_PID>>8)&0xFF, HID_DS3_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET, 128); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_A], HID_DS3_BUTTON_CIRCLE[0], HID_DS3_BUTTON_CIRCLE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_B], HID_DS3_BUTTON_CROSS[0], HID_DS3_BUTTON_CROSS[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_X], HID_DS3_BUTTON_TRIANGLE[0], HID_DS3_BUTTON_TRIANGLE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_Y], HID_DS3_BUTTON_SQUARE[0], HID_DS3_BUTTON_SQUARE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_LEFT], HID_DS3_BUTTON_LEFT[0], HID_DS3_BUTTON_LEFT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_RIGHT], HID_DS3_BUTTON_RIGHT[0], HID_DS3_BUTTON_RIGHT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_DOWN], HID_DS3_BUTTON_DOWN[0], HID_DS3_BUTTON_DOWN[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_UP], HID_DS3_BUTTON_UP[0], HID_DS3_BUTTON_UP[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_DS3_BUTTON_START[0], HID_DS3_BUTTON_START[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_DS3_BUTTON_SELECT[0], HID_DS3_BUTTON_SELECT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L], HID_DS3_BUTTON_L1[0], HID_DS3_BUTTON_L1[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R], HID_DS3_BUTTON_R1[0], HID_DS3_BUTTON_R1[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_ZL], HID_DS3_BUTTON_L2[0], HID_DS3_BUTTON_L2[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_ZR], HID_DS3_BUTTON_R2[0], HID_DS3_BUTTON_R2[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_DS3_BUTTON_L3[0], HID_DS3_BUTTON_L3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_DS3_BUTTON_R3[0], HID_DS3_BUTTON_R3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS3_BUTTON_GUIDE[0], HID_DS3_BUTTON_GUIDE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_PAD_COUNT); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_L_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_DS3_STICK_L_Y[STICK_CONF_BYTE], HID_DS3_STICK_L_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_L_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_DS3_STICK_L_Y[STICK_CONF_MIN], HID_DS3_STICK_L_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::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]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds3_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_DS3_STICK_R_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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 - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VID], (HID_DS4_VID>>8)&0xFF, HID_DS4_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PID], (HID_DS4_PID>>8)&0xFF, HID_DS4_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET, 128); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_A], HID_DS4_BUTTON_CIRCLE[0], HID_DS4_BUTTON_CIRCLE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_B], HID_DS4_BUTTON_CROSS[0], HID_DS4_BUTTON_CROSS[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_X], HID_DS4_BUTTON_TRIANGLE[0], HID_DS4_BUTTON_TRIANGLE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_Y], HID_DS4_BUTTON_SQUARE[0], HID_DS4_BUTTON_SQUARE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_N], HID_DS4_BUTTON_DPAD_N[0], HID_DS4_BUTTON_DPAD_N[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NE], HID_DS4_BUTTON_DPAD_NE[0], HID_DS4_BUTTON_DPAD_NE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_E], HID_DS4_BUTTON_DPAD_E[0], HID_DS4_BUTTON_DPAD_E[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_SE], HID_DS4_BUTTON_DPAD_SE[0], HID_DS4_BUTTON_DPAD_SE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_S], HID_DS4_BUTTON_DPAD_S[0], HID_DS4_BUTTON_DPAD_S[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_SW], HID_DS4_BUTTON_DPAD_SW[0], HID_DS4_BUTTON_DPAD_SW[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_W], HID_DS4_BUTTON_DPAD_W[0], HID_DS4_BUTTON_DPAD_W[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NW], HID_DS4_BUTTON_DPAD_NW[0], HID_DS4_BUTTON_DPAD_NW[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL], HID_DS4_BUTTON_DPAD_NEUTRAL[0], HID_DS4_BUTTON_DPAD_NEUTRAL[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_DS4_BUTTON_OPTIONS[0], HID_DS4_BUTTON_OPTIONS[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_DS4_BUTTON_SHARE[0], HID_DS4_BUTTON_SHARE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L], HID_DS4_BUTTON_L1[0], HID_DS4_BUTTON_L1[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R], HID_DS4_BUTTON_R1[0], HID_DS4_BUTTON_R1[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_ZL], HID_DS4_BUTTON_L2[0], HID_DS4_BUTTON_L2[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_ZR], HID_DS4_BUTTON_R2[0], HID_DS4_BUTTON_R2[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_DS4_BUTTON_L3[0], HID_DS4_BUTTON_L3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_DS4_BUTTON_R3[0], HID_DS4_BUTTON_R3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS4_BUTTON_GUIDE[0], HID_DS4_BUTTON_GUIDE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_PAD_COUNT); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_DS4_STICK_L_Y[STICK_CONF_BYTE], HID_DS4_STICK_L_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_DS4_STICK_L_Y[STICK_CONF_MIN], HID_DS4_STICK_L_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::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]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_R_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - ControllerPatcherUtils::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]); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! XInput - //!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VID], (HID_XINPUT_VID>>8)&0xFF, HID_XINPUT_VID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_PID], (HID_XINPUT_PID>>8)&0xFF, HID_XINPUT_PID&0xFF); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_BUF_SIZE], CONTROLLER_PATCHER_VALUE_SET, 128); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_A], HID_XINPUT_BUTTON_B[0], HID_XINPUT_BUTTON_B[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_B], HID_XINPUT_BUTTON_A[0], HID_XINPUT_BUTTON_A[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_X], HID_XINPUT_BUTTON_Y[0], HID_XINPUT_BUTTON_Y[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_Y], HID_XINPUT_BUTTON_X[0], HID_XINPUT_BUTTON_X[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_DPAD_MODE], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_BUTTON_DPAD_TYPE[CONTRDPAD_MODE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_DPAD_MASK], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_BUTTON_DPAD_TYPE[CONTRDPAD_MASK]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_UP], HID_XINPUT_BUTTON_UP[0], HID_XINPUT_BUTTON_UP[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_DOWN], HID_XINPUT_BUTTON_DOWN[0], HID_XINPUT_BUTTON_DOWN[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_LEFT], HID_XINPUT_BUTTON_LEFT[0], HID_XINPUT_BUTTON_LEFT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_RIGHT], HID_XINPUT_BUTTON_RIGHT[0], HID_XINPUT_BUTTON_RIGHT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_PLUS], HID_XINPUT_BUTTON_START[0], HID_XINPUT_BUTTON_START[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_MINUS], HID_XINPUT_BUTTON_BACK[0], HID_XINPUT_BUTTON_BACK[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L], HID_XINPUT_BUTTON_LB[0], HID_XINPUT_BUTTON_LB[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R], HID_XINPUT_BUTTON_RB[0], HID_XINPUT_BUTTON_RB[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_ZL], HID_XINPUT_BUTTON_LT[0], HID_XINPUT_BUTTON_LT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_ZR], HID_XINPUT_BUTTON_RT[0], HID_XINPUT_BUTTON_RT[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_STICK_L], HID_XINPUT_BUTTON_L3[0], HID_XINPUT_BUTTON_L3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_STICK_R], HID_XINPUT_BUTTON_R3[0], HID_XINPUT_BUTTON_R3[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_HOME], HID_XINPUT_BUTTON_GUIDE[0], HID_XINPUT_BUTTON_GUIDE[1]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_PAD_COUNT); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_XINPUT_STICK_L_X[STICK_CONF_BYTE], HID_XINPUT_STICK_L_X[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_L_X[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_XINPUT_STICK_L_X[STICK_CONF_MIN], HID_XINPUT_STICK_L_X[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_L_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y], HID_XINPUT_STICK_L_Y[STICK_CONF_BYTE], HID_XINPUT_STICK_L_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_L_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX], HID_XINPUT_STICK_L_Y[STICK_CONF_MIN], HID_XINPUT_STICK_L_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_L_Y[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_X], HID_XINPUT_STICK_R_X[STICK_CONF_BYTE], HID_XINPUT_STICK_R_X[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_R_X[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX], HID_XINPUT_STICK_R_X[STICK_CONF_MIN], HID_XINPUT_STICK_R_X[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_R_X[STICK_CONF_INVERT]); - - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y], HID_XINPUT_STICK_R_Y[STICK_CONF_BYTE], HID_XINPUT_STICK_R_Y[STICK_CONF_DEFAULT]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_R_Y[STICK_CONF_DEADZONE]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX], HID_XINPUT_STICK_R_Y[STICK_CONF_MIN], HID_XINPUT_STICK_R_Y[STICK_CONF_MAX]); - ControllerPatcherUtils::setConfigValue((u8*)&config_controller[xinput_slot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT], CONTROLLER_PATCHER_VALUE_SET, HID_XINPUT_STICK_R_Y[STICK_CONF_INVERT]); -} - -bool ControllerPatcher::Init(){ - /* - InitOSFunctionPointers(); - InitSocketFunctionPointers(); - InitSysHIDFunctionPointers(); - InitVPadFunctionPointers(); - InitPadScoreFunctionPointers();*/ - - OSDynLoadModule padscore_handle = 0; - OSDynLoad_Acquire("padscore.rpl", &padscore_handle); - void(*KPADRead_test)(); - OSDynLoad_FindExport(padscore_handle, 0, "KPADRead", (void**)&KPADRead_test); - printf("ControllerPatcher::Init(line %d): Found the KPADRead at %08X \n",__LINE__,KPADRead_test); - - gSamplingCallback = (wpad_sampling_callback_t)((u32)KPADRead_test + 0x1F0); - if(*(u32*)gSamplingCallback != FIRST_INSTRUCTION_IN_SAMPLING_CALLBACK){ - gSamplingCallback = NULL; - //In Firmware <= 5.1.2 the offset changes - gSamplingCallback = (wpad_sampling_callback_t)((u32)KPADRead_test + 0x1F8); - if(*(u32*)gSamplingCallback != FIRST_INSTRUCTION_IN_SAMPLING_CALLBACK){ - //Should never happen. I looked into the padscore.rpl of ALL firmwares. - gSamplingCallback = NULL; - } - } - printf("ControllerPatcher::Init(line %d): Found the gSamplingCallback at %08X \n",__LINE__,gSamplingCallback); - - if(HID_DEBUG){ printf("ControllerPatcher::Init(line %d): Init called! \n",__LINE__); } - - /* if(syshid_handle == 0){ - printf("ControllerPatcher::Init(line %d): Failed to load the HID API \n",__LINE__); - return false; - }*/ - - if(gConfig_done == HID_INIT_NOT_DONE){ - if(HID_DEBUG){ printf("ControllerPatcher::Init(line %d): First time calling the Init\n",__LINE__); } - gConfig_done = HID_INIT_DONE; - ControllerPatcher::ResetConfig(); - }else{ - if(HID_DEBUG){ printf("ControllerPatcher::Init(line %d): ControllerPatcher::Init(): Config already done!\n",__LINE__); } - } - - //Broken - if(gConfig_done != HID_SDCARD_READ){ - printf("ControllerPatcher::Init(line %d): Reading config files from SD Card\n",__LINE__); - ConfigReader* reader = ConfigReader::getInstance(); - s32 status = 0; - if((status = reader->InitSDCard()) == 0){ - if(HID_DEBUG){ printf("ControllerPatcher::Init(line %d): SD Card mounted for controller config!\n",__LINE__); } - reader->ReadAllConfigs(); - printf("ControllerPatcher::Init(line %d): Done with reading config files from SD Card\n",__LINE__); - gConfig_done = HID_SDCARD_READ; - }else{ - printf("ControllerPatcher::Init(line %d): SD mounting failed! %d\n",__LINE__,status); - } - ConfigReader::destroyInstance(); - } - - printf("ControllerPatcher::Init(line %d): Initializing the data for button remapping\n",__LINE__); - InitButtonMapping(); - - if(!gHIDAttached){ - HIDAddClient(&gHIDClient, ControllerPatcherHID::myAttachDetachCallback); - } - - return true; -} - -void ControllerPatcher::startNetworkServer(){ - UDPServer::getInstance(); - TCPServer::getInstance(); -} - -void ControllerPatcher::stopNetworkServer(){ - UDPServer::destroyInstance(); - UDPClient::destroyInstance(); - TCPServer::destroyInstance(); -} - -void ControllerPatcher::DeInit(){ - if(HID_DEBUG){ printf("ControllerPatcher::DeInit(line %d) called! \n",__LINE__); } - - if(gHIDAttached) HIDDelClient(&gHIDClient); - - //Resetting the state of the last pressed data. - buttonRemapping_lastButtonsHold = 0; - memset(last_button_hold,0,sizeof(last_button_hold)); - memset(myVPADBuffer,0,sizeof(myVPADBuffer)); - memset(&gControllerMapping,0,sizeof(gControllerMapping)); - memset(&gHIDClient,0,sizeof(gHIDClient)); - memset(gHID_Devices,0,sizeof(gHID_Devices)); - memset(gGamePadValues,0,sizeof(gGamePadValues)); - memset(config_controller,0,sizeof(config_controller)); - memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); - memset(gNetworkController,0,sizeof(gNetworkController)); - memset(connectionOrderHelper,0,sizeof(connectionOrderHelper)); - - memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback)); - memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback)); - memset(gExtensionCallback,0,sizeof(gExtensionCallback)); - gCallbackCooldown = 0; - - gConfig_done = HID_INIT_NOT_DONE; - gButtonRemappingConfigDone = 0; - gHIDAttached = 0; - gHIDCurrentDevice = 0; - gHIDRegisteredDevices = 0; - gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; - gHID_LIST_GC = 0; - gHID_LIST_DS3 = 0; - gHID_LIST_DS4 = 0; - gHID_LIST_KEYBOARD = 0; - gHID_LIST_MOUSE = 0; - gHID_LIST_SWITCH_PRO = 0; - - gGamePadSlot = 0; - gHID_SLOT_GC = 0; - gHID_SLOT_KEYBOARD = 0; - gMouseSlot = 0; - - gOriginalDimState = 0; - gOriginalAPDState = 0; - - gHIDNetworkClientID = 0; - - destroyConfigHelper(); -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::enableControllerMapping(){ - gControllerMapping.gamepad.useAll = 0; - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableControllerMapping(){ - gControllerMapping.gamepad.useAll = 1; - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::disableWiiUEnergySetting(){ - s32 res; - if(IMIsDimEnabled(&res) == 0){ - if(res == 1){ - if(HID_DEBUG){ printf("ControllerPatcher::disableWiiUEnergySetting(): Dim was orignally enabled!\n"); } - gOriginalDimState = 1; - } - } - - if(IMIsAPDEnabled(&res) == 0){ - if(res == 1){ - if(HID_DEBUG){ printf("ControllerPatcher::disableWiiUEnergySetting(): Auto power down was orignally enabled!\n"); } - gOriginalAPDState = 1; - } - } - - IMDisableDim(); - IMDisableAPD(); - printf("ControllerPatcher::disableWiiUEnergySetting(): Disable Energy savers\n"); - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::restoreWiiUEnergySetting(){ - - //Check if we need to enable Auto Power down again on exiting - if(gOriginalAPDState == 1){ - printf("ControllerPatcher::restoreWiiUEnergySetting(): Auto shutdown was on before using HID to VPAD. Setting it to on again.\n"); - IMEnableAPD(); - } - if(gOriginalDimState == 1){ - printf("ControllerPatcher::restoreWiiUEnergySetting(): Burn-in reduction was on before using HID to VPAD. Setting it to on again.\n"); - IMEnableDim(); - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::resetControllerMapping(UController_Type type){ - ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - - if(cm_map_pad == NULL){return CONTROLLER_PATCHER_ERROR_NULL_POINTER;} - memset(cm_map_pad,0,sizeof(*cm_map_pad)); - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::addControllerMapping(UController_Type type,ControllerMappingPADInfo config){ - ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - - s32 result = 0; - - for(s32 i=0;ipad_infos[i]); - if(info != NULL && !info->active){ - info->active = 1; - info->pad = config.pad; - info->type = config.type; - info->vidpid.vid = config.vidpid.vid; - info->vidpid.pid = config.vidpid.pid; - - result = 1; - break; - } - } - if(result == 0){ - //No free slot. - return -1; - } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -s32 ControllerPatcher::getActiveMappingSlot(UController_Type type){ - ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - - if(cm_map_pad == NULL){return -1;} - - s32 connected = -1; - for(s32 i =0;ipad_infos[i].active || cm_map_pad->pad_infos[i].type == CM_Type_RealController){ - connected = i; - break; - } - } - - return connected; -} - -bool ControllerPatcher::isControllerConnectedAndActive(UController_Type type,s32 mapping_slot){ - ControllerMappingPADInfo * padinfo = getControllerMappingInfo(type,mapping_slot); - if(!padinfo){ - return false; - } - if(padinfo->active){ - DeviceInfo device_info; - - memset(&device_info,0,sizeof(device_info)); - - device_info.vidpid = padinfo->vidpid; - - s32 res; - if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ - return false; - } - - u32 hidmask = device_info.slotdata.hidmask; - u32 pad = padinfo->pad; - - HID_Data * data_cur; - - if((res = ControllerPatcherHID::getHIDData(hidmask,pad,&data_cur)) < 0) { - return false; - } - - return true; - } - return false; -} - -ControllerMappingPADInfo * ControllerPatcher::getControllerMappingInfo(UController_Type type,s32 mapping_slot){ - ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - - if(cm_map_pad == NULL){return NULL;} - - if(mapping_slot < 0 || mapping_slot > HID_MAX_DEVICES_PER_SLOT-1){ return NULL;} - - return &(cm_map_pad->pad_infos[mapping_slot]); -} - -HID_Mouse_Data * ControllerPatcher::getMouseData(){ - ControllerMappingPAD * CMPAD = ControllerPatcherUtils::getControllerMappingByType(UController_Type_Gamepad); - - if(CMPAD == NULL){ - return NULL; - } - - HID_Mouse_Data * result = NULL; - - for(s32 i;ipad_infos[i]); - if(!padinfo->active){ - break; - } - if(padinfo->type == CM_Type_Mouse){ - result = &(gHID_Devices[gMouseSlot].pad_data[padinfo->pad].data_union.mouse.cur_mouse_data); - } - } - return result; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type type,u32 status){ - ControllerMappingPAD * cm_map_pad = ControllerPatcherUtils::getControllerMappingByType(type); - if(cm_map_pad == NULL){return -1;} - cm_map_pad->rumble = !!status; //to make sure it's only 0 or 1. - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){ - HID_Data * data_cur; - VPADStatus pad_buffer; - VPADStatus * buffer = &pad_buffer; - s32 result = CONTROLLER_PATCHER_ERROR_NONE; - std::map pad_count; - //printf("fill in data\n"); - for(s32 i = 0;i < gHIDMaxDevices;i++){ - u8 * status = &output[result].status; - *status = 0; - if(connectionOrderHelper[i].usr != NULL){ - *status = 1; - - my_cb_user * usr = connectionOrderHelper[i].usr; - pad_count[usr] = pad_count[usr] +1; - s32 hid = usr->slotdata.hidmask; - - s32 realpad = connectionOrderHelper[i].pad_slot; - - //printf("result[%d] usr: %08X hid: %08X realpad: %08X\n",result,usr,hid,realpad); - - output[result].pad = realpad; - output[result].device_info.pad_count = usr->pads_per_device; - output[result].device_info.slotdata = usr->slotdata; - output[result].device_info.vidpid = usr->vidpid; - - InputButtonData * buttondata = &output[result].button_data; - InputStickData * stickdata = &output[result].stick_data; - - s32 buttons_hold = 0; - buttondata->hold = 0; - buttondata->trigger = 0; - buttondata->release = 0; - - s32 res; - if((res = ControllerPatcherHID::getHIDData(hid,realpad,&data_cur)) == 0){ - res = ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_A); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_B); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_X); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_Y); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_LEFT); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_RIGHT); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_DOWN); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_UP); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_MINUS); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_L); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_R); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_PLUS); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_ZL); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_ZR); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_HOME); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_L); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_R); - - buttondata->hold |= buttons_hold; - buttondata->trigger |= (buttons_hold & (~(data_cur->last_buttons))); - buttondata->release |= ((data_cur->last_buttons) & (~buttons_hold)); - - buffer->leftStick.x = 0.0f; - buffer->leftStick.y = 0.0f; - buffer->rightStick.x = 0.0f; - buffer->rightStick.y = 0.0f; - - ControllerPatcherUtils::convertAnalogSticks(data_cur,buffer); - ControllerPatcherUtils::normalizeStickValues(&(buffer->leftStick)); - ControllerPatcherUtils::normalizeStickValues(&(buffer->rightStick)); - - stickdata->leftStickX = buffer->leftStick.x; - stickdata->leftStickY = buffer->leftStick.y; - stickdata->rightStickX = buffer->rightStick.x; - stickdata->rightStickY = buffer->rightStick.y; - - //printf("result[%d] buttons %08X\n",result,buttons_hold); - - data_cur->last_buttons = buttons_hold; - } - } - - result++; - if(result >= array_size){ - break; - } - } - - return result; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setProControllerDataFromHID(void * data,s32 chan, s32 mode){ - if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(chan < 0 || chan > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; - //if(gControllerMapping.proController[chan].enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED; - - VPADStatus * vpad_buffer = &myVPADBuffer[chan]; - memset(vpad_buffer,0,sizeof(*vpad_buffer)); - - std::vector data_list; - - for(s32 i = 0;i::iterator it = data_list.begin(); it != data_list.end(); ++it) { - HID_Data * cur_ptr = *it; - cur_ptr->rumbleActive = !!gControllerMapping.proController[chan].rumble; - } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setControllerDataFromHID(VPADStatus * buffer){ - if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - //if(gControllerMapping.gamepad.enabled == 0) return CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED; - - s32 hidmask = 0; - s32 pad = 0; - - ControllerMappingPAD cm_map_pad = gControllerMapping.gamepad; - std::vector data_list; - - if (cm_map_pad.useAll == 1) { - data_list = ControllerPatcherHID::getHIDDataAll(); - }else{ - for(s32 i = 0;irumbleActive = !!gControllerMapping.gamepad.rumble; - } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::printVPADButtons(VPADStatus * buffer){ - return CONTROLLER_PATCHER_ERROR_NONE; - /* BROKEN on transitions.*/ - if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(buffer->trigger != 0x00000000){ - char output[250]; - - output[0] = 0; //null terminate it. just in case. - - if((buffer->trigger & VPAD_BUTTON_A) == VPAD_BUTTON_A) strcat(output,"A "); - if((buffer->trigger & VPAD_BUTTON_B) == VPAD_BUTTON_B) strcat(output,"B "); - if((buffer->trigger & VPAD_BUTTON_X) == VPAD_BUTTON_X) strcat(output,"X "); - if((buffer->trigger & VPAD_BUTTON_Y) == VPAD_BUTTON_Y) strcat(output,"Y "); - if((buffer->trigger & VPAD_BUTTON_L) == VPAD_BUTTON_L) strcat(output,"L "); - if((buffer->trigger & VPAD_BUTTON_R) == VPAD_BUTTON_R) strcat(output,"R "); - if((buffer->trigger & VPAD_BUTTON_ZR) == VPAD_BUTTON_ZR) strcat(output,"ZR "); - if((buffer->trigger & VPAD_BUTTON_ZL) == VPAD_BUTTON_ZL) strcat(output,"ZL "); - if((buffer->trigger & VPAD_BUTTON_LEFT) == VPAD_BUTTON_LEFT) strcat(output,"Left "); - if((buffer->trigger & VPAD_BUTTON_RIGHT) == VPAD_BUTTON_RIGHT) strcat(output,"Right "); - if((buffer->trigger & VPAD_BUTTON_UP) == VPAD_BUTTON_UP) strcat(output,"Up "); - if((buffer->trigger & VPAD_BUTTON_DOWN) == VPAD_BUTTON_DOWN) strcat(output,"Down "); - if((buffer->trigger & VPAD_BUTTON_PLUS) == VPAD_BUTTON_PLUS) strcat(output,"+ "); - if((buffer->trigger & VPAD_BUTTON_MINUS) == VPAD_BUTTON_MINUS) strcat(output,"- "); - if((buffer->trigger & VPAD_BUTTON_TV) == VPAD_BUTTON_TV) strcat(output,"TV "); - if((buffer->trigger & VPAD_BUTTON_HOME) == VPAD_BUTTON_HOME) strcat(output,"HOME "); - if((buffer->trigger & VPAD_BUTTON_STICK_L) == VPAD_BUTTON_STICK_L) strcat(output,"SL "); - if((buffer->trigger & VPAD_BUTTON_STICK_R) == VPAD_BUTTON_STICK_R) strcat(output,"SR "); - if((buffer->trigger & VPAD_STICK_R_EMULATION_LEFT) == VPAD_STICK_R_EMULATION_LEFT) strcat(output,"RE_Left "); - if((buffer->trigger & VPAD_STICK_R_EMULATION_RIGHT) == VPAD_STICK_R_EMULATION_RIGHT) strcat(output,"RE_Right "); - if((buffer->trigger & VPAD_STICK_R_EMULATION_UP) == VPAD_STICK_R_EMULATION_UP) strcat(output,"RE_Up "); - if((buffer->trigger & VPAD_STICK_R_EMULATION_DOWN) == VPAD_STICK_R_EMULATION_DOWN) strcat(output,"RE_Down "); - if((buffer->trigger & VPAD_STICK_L_EMULATION_LEFT) == VPAD_STICK_L_EMULATION_LEFT) strcat(output,"LE_Left "); - if((buffer->trigger & VPAD_STICK_L_EMULATION_RIGHT) == VPAD_STICK_L_EMULATION_RIGHT) strcat(output,"LE_Right "); - if((buffer->trigger & VPAD_STICK_L_EMULATION_UP) == VPAD_STICK_L_EMULATION_UP) strcat(output,"LE_Up "); - if((buffer->trigger & VPAD_STICK_L_EMULATION_DOWN) == VPAD_STICK_L_EMULATION_DOWN) strcat(output,"LE_Down "); - - printf("%spressed Sticks: LX %f LY %f RX %f RY %f\n",output,buffer->leftStick.x,buffer->leftStick.y,buffer->rightStick.x,buffer->rightStick.y); - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::buttonRemapping(VPADStatus * buffer,s32 buffer_count){ - if(!gButtonRemappingConfigDone) return CONTROLLER_PATCHER_ERROR_CONFIG_NOT_DONE; - if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - for(s32 i = 0;i < buffer_count;i++){ - VPADStatus new_data; - memset(&new_data,0,sizeof(new_data)); - - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_A, CONTRPS_VPAD_BUTTON_A); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_B, CONTRPS_VPAD_BUTTON_B); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_X, CONTRPS_VPAD_BUTTON_X); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_Y, CONTRPS_VPAD_BUTTON_Y); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_LEFT, CONTRPS_VPAD_BUTTON_LEFT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_RIGHT, CONTRPS_VPAD_BUTTON_RIGHT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_UP, CONTRPS_VPAD_BUTTON_UP); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_DOWN, CONTRPS_VPAD_BUTTON_DOWN); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_ZL, CONTRPS_VPAD_BUTTON_ZL); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_ZR, CONTRPS_VPAD_BUTTON_ZR); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_L, CONTRPS_VPAD_BUTTON_L); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_R, CONTRPS_VPAD_BUTTON_R); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_PLUS, CONTRPS_VPAD_BUTTON_PLUS); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_MINUS, CONTRPS_VPAD_BUTTON_MINUS); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_HOME, CONTRPS_VPAD_BUTTON_HOME); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_SYNC, CONTRPS_VPAD_BUTTON_SYNC); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_STICK_R, CONTRPS_VPAD_BUTTON_STICK_R); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_STICK_L, CONTRPS_VPAD_BUTTON_STICK_L); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_BUTTON_TV, CONTRPS_VPAD_BUTTON_TV); - - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_LEFT, CONTRPS_VPAD_STICK_R_EMULATION_LEFT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_RIGHT, CONTRPS_VPAD_STICK_R_EMULATION_RIGHT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_UP, CONTRPS_VPAD_STICK_R_EMULATION_UP); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_DOWN, CONTRPS_VPAD_STICK_R_EMULATION_DOWN); - - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_LEFT, CONTRPS_VPAD_STICK_L_EMULATION_LEFT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_RIGHT, CONTRPS_VPAD_STICK_L_EMULATION_RIGHT); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_UP, CONTRPS_VPAD_STICK_L_EMULATION_UP); - ControllerPatcherUtils::setButtonRemappingData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_DOWN, CONTRPS_VPAD_STICK_L_EMULATION_DOWN); - - //Even when you remap any Stick Emulation to a button, we still want to keep the emulated stick data. Some games like New Super Mario Bros. only work with the emulated stick data. - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_LEFT, VPAD_STICK_L_EMULATION_LEFT); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_RIGHT, VPAD_STICK_L_EMULATION_RIGHT); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_UP, VPAD_STICK_L_EMULATION_UP); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_L_EMULATION_DOWN, VPAD_STICK_L_EMULATION_DOWN); - - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_LEFT, VPAD_STICK_R_EMULATION_LEFT); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_RIGHT, VPAD_STICK_R_EMULATION_RIGHT); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_UP, VPAD_STICK_R_EMULATION_UP); - ControllerPatcherUtils::setButtonData(&buffer[i],&new_data,VPAD_STICK_R_EMULATION_DOWN, VPAD_STICK_R_EMULATION_DOWN); - - buffer[i].hold = new_data.hold; - buffer[i].trigger = new_data.trigger; - buffer[i].release = new_data.release; - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -std::string ControllerPatcher::getIdentifierByVIDPID(u16 vid,u16 pid){ - return ConfigValues::getStringByVIDPID(vid,pid); -} - -void ControllerPatcher::destroyConfigHelper(){ - ConfigReader::destroyInstance(); - ConfigValues::destroyInstance(); -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::doSamplingForDeviceSlot(u16 device_slot){ - return ControllerPatcherUtils::doSampling(device_slot,0,true); -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumbleActivated(bool value){ - gGlobalRumbleActivated = value; - return CONTROLLER_PATCHER_ERROR_NONE; -} - -bool ControllerPatcher::isRumbleActivated(){ - return gGlobalRumbleActivated; -} - diff --git a/wiiu/controller_patcher/ControllerPatcher.hpp b/wiiu/controller_patcher/ControllerPatcher.hpp deleted file mode 100644 index 58aaa65c9d..0000000000 --- a/wiiu/controller_patcher/ControllerPatcher.hpp +++ /dev/null @@ -1,251 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 . - ****************************************************************************/ - - /** - * @file ControllerPatcher.hpp - * @author Maschell - * @date 30 Mar 2017 - * \brief This files contain all public accessible functions of the controller patcher engine - * - * @see https://github.com/Maschell/controller_patcher - */ - -#ifndef _CONTROLLER_PATCHER_H_ -#define _CONTROLLER_PATCHER_H_ - -#include - -#include "./patcher/ControllerPatcherDefs.h" -#include "./utils/ControllerPatcherThread.hpp" -#include "./utils/CPRetainVars.hpp" -#include "./utils/PadConst.hpp" -#include "./utils/CPStringTools.hpp" - -#include "./patcher/ControllerPatcherHID.hpp" -#include "./patcher/ControllerPatcherUtils.hpp" - -#include "./config/ConfigValues.hpp" -#include "./config/ConfigParser.hpp" - -#include "./network/ControllerPatcherNet.hpp" -#include "./network/TCPServer.hpp" -#include "./network/UDPServer.hpp" -#include "./network/UDPClient.hpp" -#include "./ConfigReader.hpp" - -#include "wiiu/vpad.h" - -#define BUS_SPEED 248625000 -#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4)) -#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000) -#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000) - -#define wiiu_os_usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs)) - -#define HID_DEBUG 0 - -class ControllerPatcher{ - public: - /*----------------------------------------------------------------------------------------------------------------------------------- - * Initialization - *----------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Resets the data thats used by the controller configuration - **/ - static void ResetConfig(); - /** - \brief Initializes the libraries, functions, values and arrays. Need to be called on each start of an Application. Returns false on errors. - **/ - static bool Init(); - - /** - \brief De-Initialises the controller_patcher - **/ - static void DeInit(); - /** - Initialises the button remapping - **/ - static void InitButtonMapping(); - - /** - Starts the network server - **/ - static void startNetworkServer(); - - /** - Stops the network server - **/ - static void stopNetworkServer(); - - /*----------------------------------------------------------------------------------------------------------------------------------- - * Initialization - *----------------------------------------------------------------------------------------------------------------------------------*/ - - /** - Sets the data in a given data from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array int slot 1-4 (counting starts at 0, which is the gamepad). The \p - chan provides the information of the channel from which the data will be used. The mode sets the type of the buffer. - - @param buffer: A pointer to the struct where the result will be stored. - @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. - @param mode: Sets the type of the buffer. PRO_CONTROLLER_MODE_KPADDATA or PRO_CONTROLLER_MODE_WPADReadData - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - - static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,s32 chan,s32 mode = PRO_CONTROLLER_MODE_KPADDATA); - - - /** - Sets the data in a given VPADStatus from HID Devices. The information about which HID Device will be used is stored in the gControllerMapping array in slot 0. - - @param buffer: A pointer to an KPADData struct where the result will be stored. - @param chan: Indicates the channel from which slot the information about the mapped HID Device will be used. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - - static CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * buffer); - - /*----------------------------------------------------------------------------------------------------------------------------------- - * Useful functions - *----------------------------------------------------------------------------------------------------------------------------------*/ - - /** - Enable the Controller mapping. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR enableControllerMapping(); - - /** - Disbale the Controller mapping. Afterwards all connected controllers will be used for the gamepad. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR disableControllerMapping(); - - /** - Disables the energy settings for the WiiU. Settings can be restored via restoreWiiUEnergySetting. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR disableWiiUEnergySetting(); - - /** - Restores the WiiU Energy Settings. - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR restoreWiiUEnergySetting(); - - /** - Resets the controller mapping for a given controller type. - - @param type: The type of the controller. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR resetControllerMapping(UController_Type type); - - - /** - Adds a controller mapping - - @param type: The type of the controller. - @param config: information about the added controller. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR addControllerMapping(UController_Type type,ControllerMappingPADInfo config); - - - /** - - @return The first active mapping slot for the given controller type will be returned. If the controller type is not set active, -1 will be returned. - **/ - static s32 getActiveMappingSlot(UController_Type type); - - /** - @param type: The type of the controller. - @param mapping_slot: information about the added controller. - @return When the functions failed result < 0 is returned. Otherwise a pointer to a ControllerMappingPADInfo is returned. - **/ - static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,s32 mapping_slot); - - /** - Checks if a emulated controller is connected for the given controller type / mapping slot. - - @param type: The type of the controller. - @param mapping_slot: Slot of the controller mapped to this controller type (usually 0) - - @return - **/ - static bool isControllerConnectedAndActive(UController_Type type,s32 mapping_slot = 0); - - /** - Search for a connected mouse and returns a pointer to it's data. - @return A pointer to the first connected mouse that is found. NULL if no mouse is connected. - **/ - static HID_Mouse_Data * getMouseData(); - - /** - Sets a rumble status for a controller. - - @param type: The type of the controller. - @param status: status of the rumble. 0 for off, 1 for on. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumble(UController_Type type,u32 status); - - /** - Reads the input of all connected HID devices. Each attached controller will write his date into given array until it's full. - - @param output: A pointer to an InputData array where the result will be stored. (Make sure to reset the array before using this function). - @param array_size: Size of the given InputData array. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. If the result is > 0 the number of stored sets in the array is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size); - - /** - Remaps the buttons in the given \p VPADStatus pointer. InitButtonMapping() needs to be called before calling this. The information about the remapping is stored in the config_controller array. - One easy way to set it is using the a config file on the SD Card. - - @param buffer: A pointer to the buffer where the input will be read from and the result will be stored. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADStatus * buffer, s32 buffer_count); - - /** - Prints the current pressed down buttons of the given \p VPADStatus pointer. Uses the utils/logger.c UDP logger.. - - @param buffer: A pointer to the buffer where the input will be read from. - - @return When the functions failed result < 0 is returned. If the result is == 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR printVPADButtons(VPADStatus * buffer); - - static std::string getIdentifierByVIDPID(u16 vid,u16 pid); - - static void destroyConfigHelper(); - - static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingForDeviceSlot(u16 device_slot); - - static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumbleActivated(bool value); - - static bool isRumbleActivated(); -}; - -#endif /* _CONTROLLER_PATCHER_H_ */ diff --git a/wiiu/controller_patcher/ControllerPatcherWrapper.cpp b/wiiu/controller_patcher/ControllerPatcherWrapper.cpp deleted file mode 100644 index 795dc13a60..0000000000 --- a/wiiu/controller_patcher/ControllerPatcherWrapper.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "controller_patcher/ControllerPatcher.hpp" - #include "controller_patcher/ControllerPatcherWrapper.h" - -extern "C" void ControllerPatcherInit(void){ - ControllerPatcher::Init(); - ControllerPatcher::disableControllerMapping(); - ControllerPatcher::startNetworkServer(); - ControllerPatcher::disableWiiUEnergySetting(); -} - -extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data){ - ControllerPatcher::setControllerDataFromHID(data); -} - -extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size){ - ControllerPatcher::gettingInputAllDevices(output,array_size); -} - -extern "C" void ControllerPatcherDeInit(void){ - ControllerPatcher::restoreWiiUEnergySetting(); - ControllerPatcher::stopNetworkServer(); - ControllerPatcher::DeInit(); -} diff --git a/wiiu/controller_patcher/ControllerPatcherWrapper.h b/wiiu/controller_patcher/ControllerPatcherWrapper.h deleted file mode 100644 index 106d2aa1e7..0000000000 --- a/wiiu/controller_patcher/ControllerPatcherWrapper.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _CONTROLLER_PATCHER_WRAPPER_H_ -#define _CONTROLLER_PATCHER_WRAPPER_H_ - -#include "wiiu/vpad.h" - -/* Main */ -#ifdef __cplusplus -extern "C" { -#endif - -#include "./patcher/ControllerPatcherDefs.h" - -//! C wrapper for our C++ functions -void ControllerPatcherInit(void); -void ControllerPatcherDeInit(void); -CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data); -CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/wiiu/controller_patcher/config/ConfigParser.cpp b/wiiu/controller_patcher/config/ConfigParser.cpp deleted file mode 100644 index 7e5c2d34c3..0000000000 --- a/wiiu/controller_patcher/config/ConfigParser.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "./ConfigParser.hpp" -#include -#include -#include -#include - -ConfigParser::ConfigParser(std::string configData){ - this->content = configData; - this->contentLines = CPStringTools::StringSplit(content, "\n"); - - if(contentLines.empty()){ - return; - } - - //remove the comments and make everything uppercase - for(u32 i = 0; i < contentLines.size(); i++){ - std::vector comments = CPStringTools::StringSplit(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(){ - if(contentLines.size() == 0){ - printf("ConfigParser::Init(line %d): File seems to be empty. Make sure to have a proper header\n",__LINE__); - return false; - } - const char * line = contentLines[0].c_str(); - s32 len = strlen(line); - if(len <= 4){ - printf("ConfigParser::Init(line %d): Header is too short.\n",__LINE__); - return false; - } - std::string identify; - if(line[0] == '[' && line[len-1] == ']'){ - identify = contentLines[0].substr(1,len-2); - }else{ - printf("ConfigParser::Init((line %d): Not a proper config file!\n",__LINE__); - return false; - } - - if(identify.compare("GAMEPAD") == 0){ - printf("ConfigParser::Init((line %d): Its a gamepad config file!\n",__LINE__); - setSlot(gGamePadSlot); - setType(PARSE_GAMEPAD); - }else if(identify.compare("MOUSE") == 0){ - printf("ConfigParser::Init((line %d): Its a mouse config file!\n",__LINE__); - setSlot(gMouseSlot); - setType(PARSE_MOUSE); - this->vid = HID_MOUSE_VID; - this->pid = HID_MOUSE_PID; - }else if(identify.compare("KEYBOARD") == 0){ - printf("ConfigParser::Init((line %d): Its a keyboard config file!\n",__LINE__); - setSlot(gHID_SLOT_KEYBOARD); - setType(PARSE_KEYBOARD); - this->vid = HID_KEYBOARD_VID; - this->pid = HID_KEYBOARD_PID; - }else{ - printf("ConfigParser::Init((line %d): Its a controller config file!\n",__LINE__); - - setSlot(getSlotController(identify)); - setType(PARSE_CONTROLLER); - } - - if(getSlot() == HID_INVALID_SLOT){ - return false; - } - - ConfigReader::increaseNumberOfLoadedFiles(); - - return true; -} - -void ConfigParser::parseSingleLine(std::string line){ - if(line.empty()){printf("ConfigParser::parseSingleLine(line %d): Can't parse line. it's empty\n",__LINE__); return;} - std::vector cur_values = CPStringTools::StringSplit(line,"="); - if(cur_values.size() != 2){ - if(HID_DEBUG || cur_values.size() > 2){ printf("ConfigParser::parseSingleLine(line %d): Not a valid key=pair line %s\n",__LINE__,line.c_str()); } - return; - }else{ - u16 hid_slot = getSlot(); - - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): leftpart = \"%s\" \n",__LINE__,cur_values[0].c_str()); } - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): rightpart = \"%s\" \n",__LINE__,cur_values[1].c_str()); } - s32 keyslot = -1; - - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Checking single value\n",__LINE__); } - 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){ printf("ConfigParser::parseSingleLine(line %d): Its a single value\n",__LINE__); } - 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){ printf("ConfigParser::parseSingleLine(line %d): Settings preset DPAD MODE and Mask\n",__LINE__); } - 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){ printf("ConfigParser::parseSingleLine(line %d): Used pre-defined Keyboard! \"%s\" is %d\n",__LINE__,cur_values[1].c_str(),rightValue);} - }else{ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str()); } - char * ptr; - rightValue = strtol(cur_values[1].c_str(),&ptr,16); - } - }else{ - rightValue = ConfigValues::getPresetValue(cur_values[1]); - - if(getType() == PARSE_MOUSE){ //No parsing for the mouse - if(rightValue == -1){ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Invalid mouse value, lets skip it %s\n",__LINE__,cur_values[1].c_str()); } - return; - } - }else{ - if(rightValue == -1){ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): I need to parse %s\n",__LINE__,cur_values[1].c_str()); } - char * ptr; - rightValue = strtol(cur_values[1].c_str(),&ptr,16); - } - } - } - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Setting value to %d\n",__LINE__,rightValue); } - - config_controller[hid_slot][keyslot][0] = CONTROLLER_PATCHER_VALUE_SET; - config_controller[hid_slot][keyslot][1] = rightValue; - } - }else{ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Check pair value\n",__LINE__); } - keyslot = ConfigValues::getKeySlotDefaultPairedValue(cur_values[0]); - if(keyslot != -1){ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Its a pair value\n",__LINE__); } - - if(!ConfigValues::getInstance()->setIfValueIsAControllerPreset(cur_values[1],getSlot(),keyslot)){ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): And its no preset\n",__LINE__); } - std::vector rightvalues = CPStringTools::StringSplit(cur_values[1],","); - - if(rightvalues.size() != 2){ - printf("ConfigParser::parseSingleLine(line %d): %d instead of 2 key=values pairs in line\n",__LINE__,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){ printf("ConfigParser::parseSingleLine(line %d): Set %02X,%02X\n",__LINE__,firstValue,secondValue); } - }else{ - if(HID_DEBUG){ printf("ConfigParser::parseSingleLine(line %d): Found preset value!!\n",__LINE__); } - } - }else{ - printf("ConfigParser::parseSingleLine(line %d): The setting \"%s\" is unknown!\n",__LINE__,cur_values[0].c_str()); - } - } - } -} - -bool ConfigParser::resetConfig(){ - s32 slot = getSlot(); - if((slot == HID_INVALID_SLOT) || (slot >= gHIDMaxDevices)) return false; - for(s32 j = (CONTRPS_PID+1);j< CONTRPS_MAX_VALUE;j++){ - config_controller[slot][j][0] = CONTROLLER_PATCHER_INVALIDVALUE; - config_controller[slot][j][1] = CONTROLLER_PATCHER_INVALIDVALUE; - } - return true; -} - -s32 ConfigParser::getSlotController(std::string identify){ - if(HID_DEBUG){ printf("ConfigParser::getSlotController(line %d): Getting Controller Slot\n",__LINE__); } - - std::vector values = CPStringTools::StringSplit(identify,","); - - if(values.size() != 2){ - printf("ConfigParser::getSlotController(line %d): You need to provide a VID and PID. e.g. \"[vid=0x451,pid=0x152]\". (%s)\n",__LINE__,identify.c_str()); - return HID_INVALID_SLOT; - } - - s32 vid = getValueFromKeyValue(values[0],"VID","="); - if(vid < 0){ - return HID_INVALID_SLOT; - } - s32 pid = getValueFromKeyValue(values[1],"PID","="); - if(pid < 0){ - return HID_INVALID_SLOT; - } - printf("ConfigParser::getSlotController(line %d): VID: %04x PID: %04x\n",__LINE__,vid,pid); - - this->vid = vid; - this->pid = pid; - DeviceInfo deviceinfo; - memset(&deviceinfo,0,sizeof(deviceinfo)); - deviceinfo.vidpid.vid = vid; - deviceinfo.vidpid.pid = pid; - s32 result = ControllerPatcherUtils::getDeviceInfoFromVidPid(&deviceinfo); - s32 slot = deviceinfo.slotdata.deviceslot; - s32 hid = 0; - if(result < 0){ - if(HID_DEBUG){ printf("ConfigParser::getSlotController(line %d): Its a new controller, lets save it\n",__LINE__); } - - HIDSlotData slotdata; - ControllerPatcherUtils::getNextSlotData(&slotdata); - - slot = slotdata.deviceslot; - hid = slotdata.hidmask; - - if(slot >= gHIDMaxDevices){ - printf("ConfigParser::getSlotController(line %d): ConfigParser::getSlotController: We don't a space for a new controller, please delete .inis\n",__LINE__); - return HID_INVALID_SLOT; - } - if(HID_DEBUG){ printf("ConfigParser::getSlotController(line %d): Got new slot! slot: %d hid %s .. Lets registrate it!\n",__LINE__,slot,CPStringTools::byte_to_binary(hid)); } - config_controller[slot][CONTRPS_VID][0] = (vid & 0xFF00) >> 8; - config_controller[slot][CONTRPS_VID][1] = (vid & 0x00FF); - config_controller[slot][CONTRPS_PID][0] = (pid & 0xFF00) >> 8; - config_controller[slot][CONTRPS_PID][1] = (pid & 0x00FF); - - if(HID_DEBUG){ - printf("ConfigParser::getSlotController(line %d): Saved vid: %04X pid: %04X\n",__LINE__, - config_controller[slot][CONTRPS_VID][0] * 0x100 + config_controller[slot][CONTRPS_VID][1], - config_controller[slot][CONTRPS_PID][0] * 0x100 + config_controller[slot][CONTRPS_PID][1]); } - - config_controller_hidmask[slot] = hid; - if(HID_DEBUG){ printf("ConfigParser::getSlotController(line %d): Saved the hid\n",__LINE__); } - - }else{ - if(slot < gHIDMaxDevices){ - hid = config_controller_hidmask[slot]; - if(HID_DEBUG){ printf("ConfigParser::getSlotController(line %d): >>>>>> found slot %d (hid:%s). Modifing existing data <<<<<<<<\n",__LINE__,slot,CPStringTools::byte_to_binary(hid)); } - printf("ConfigParser::getSlotController(line %d): We already have data of this controller, lets modify it\n",__LINE__); - }else{ - printf("ConfigParser::getSlotController(line %d): Something really odd happend to the slots. %d is bigger then max (%d)\n",__LINE__,slot,gHIDMaxDevices); - return HID_INVALID_SLOT; - } - } - - printf("ConfigParser::getSlotController(line %d): using slot: %d hid %08X\n",__LINE__,slot,hid); - return slot; -} - -bool ConfigParser::parseIni(){ - if(getSlot() == HID_INVALID_SLOT){ - printf("ConfigParser::parseIni(line %d): Couldn't parse file. Not a valid slot. Probably broken config. Or you tried to have more than %d devices\n",__LINE__,getType(),gHIDMaxDevices); - return false; - } - - if(HID_DEBUG){ printf("ConfigParser::parseIni(line %d): Parsing content, type %d\n",__LINE__,getType()); } - - s32 start = 1; - if(contentLines.size() <= 1){ - printf("ConfigParser::parseIni(line %d): File only contains a header.\n",__LINE__); - return false; - } - - if(contentLines[1].compare("[IGNOREDEFAULT]") == 0){ - resetConfig(); - printf("ConfigParser::parseIni(line %d): Ignoring existing settings of this device\n",__LINE__); - start++; - } - - for(u32 i = start; i < contentLines.size(); i++){ - if(HID_DEBUG){ printf("ConfigParser::parseIni(line %d): line %d: \"%s\" \n",__LINE__,(i+1),contentLines[i].c_str()); } - parseSingleLine(contentLines[i]); - } - - if(HID_DEBUG){ printf("ConfigParser::parseIni(line %d): Parsing of the file is done.\n",__LINE__); } - return true; -} - -s32 ConfigParser::getValueFromKeyValue(std::string value_pair,std::string expectedKey,std::string delimiter){ - std::vector string_value = CPStringTools::StringSplit(value_pair,delimiter); - if(string_value.size() != 2){ - if(HID_DEBUG || string_value.size() > 2){ printf("ConfigParser::getValueFromKeyValue(line %d): Not a valid key=pair line %s\n",__LINE__,value_pair.c_str()); } - return -1; - } - if(string_value[0].compare(expectedKey) != 0){ - printf("ConfigParser::getValueFromKeyValue(line %d): Key part not %s, its %s",__LINE__,expectedKey.c_str(),string_value[0].c_str()); - return -1; - } - char * ptr; - s32 value = strtol(string_value[1].c_str(),&ptr,16); - - return value; -} diff --git a/wiiu/controller_patcher/config/ConfigParser.hpp b/wiiu/controller_patcher/config/ConfigParser.hpp deleted file mode 100644 index d00a77ee7f..0000000000 --- a/wiiu/controller_patcher/config/ConfigParser.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "../ControllerPatcher.hpp" - -enum PARSE_TYPE{ - PARSE_CONTROLLER, - PARSE_GAMEPAD, - PARSE_MOUSE, - PARSE_KEYBOARD -}; - -class ConfigParser{ - friend class ConfigReader; - friend class ControllerPatcher; -private: - //!Constructor - ConfigParser(std::string configData); - //!Destructor - ~ConfigParser(); - - PARSE_TYPE getType(); - void setType(PARSE_TYPE newType); - - u16 getSlot(); - void setSlot(u16 newSlot); - - bool parseIni(); - - bool Init(); - - bool parseConfigString(std::string content); - - s32 getSlotController(std::string identify); - - s32 checkExistingController(s32 vid, s32 pid); - - s32 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; - - u16 vid; - u16 pid; - - std::string content; - std::vector contentLines; -}; -#endif diff --git a/wiiu/controller_patcher/config/ConfigValues.cpp b/wiiu/controller_patcher/config/ConfigValues.cpp deleted file mode 100644 index 57de6e3b8b..0000000000 --- a/wiiu/controller_patcher/config/ConfigValues.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "./ConfigValues.hpp" -#include -#include -#include - -ConfigValues *ConfigValues::instance = NULL; - -ConfigValues::ConfigValues(){ - InitValues(); -} - -ConfigValues::~ConfigValues(){ - if(HID_DEBUG){ printf("ConfigValues::~ConfigValues(line %d){\n",__LINE__);} -} - -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,s32 slot,s32 keyslot){ - if(setIfValueIsPreset(presetGCValues,value,slot,keyslot)) return true; - if(setIfValueIsPreset(presetDS3Values,value,slot,keyslot)) return true; - if(setIfValueIsPreset(presetDS4Values,value,slot,keyslot)) return true; - if(setIfValueIsPreset(presetXInputValues,value,slot,keyslot)) return true; - if(setIfValueIsPreset(presetSwitchProValues,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,s32 slot,s32 keyslot){ - if(slot > gHIDMaxDevices || slot < 0 || keyslot < 0 || keyslot >= CONTRPS_MAX_VALUE){ - return false; - } - const u8 * values_ = NULL; - if( keyslot == CONTRPS_VPAD_BUTTON_L_STICK_X || - keyslot == CONTRPS_VPAD_BUTTON_L_STICK_Y || - keyslot == CONTRPS_VPAD_BUTTON_R_STICK_X || - keyslot == CONTRPS_VPAD_BUTTON_R_STICK_Y){ - if(HID_DEBUG){ printf("ConfigValues::setIfValueIsPreset(line %d): This may be a predefined stick %s\n",__LINE__,possibleValue.c_str());} - if((values_ = ConfigValues::getValuesStickPreset(possibleValue)) != NULL){ - if(HID_DEBUG){ printf("ConfigValues::setIfValueIsPreset(line %d): Found predefined stick!\n",__LINE__);} - 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; -} - - -s32 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; -} - -s32 ConfigValues::getPresetValueEx(std::string possibleString){ - s32 rightValue = -1; - if((rightValue = getValueFromMap(gGamePadValuesToCONTRPSString,possibleString))!= -1){ - if(HID_DEBUG){ printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined VPAD_VALUE! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue); } - }else if((rightValue = getValueFromMap(presetValues,possibleString))!= -1){ - if(HID_DEBUG){ printf("ConfigValues::getPresetValueEx(line %d): Used pre-defined value! \"%s\" is %d\n",__LINE__,possibleString.c_str(),rightValue); } - } - return rightValue; -} - - void ConfigValues::addDeviceNameEx(u16 vid,u16 pid,std::string value){ - deviceNames[CPStringTools::strfmt("%04X%04X",vid,pid).c_str()] = value; - } - -std::string ConfigValues::getStringByVIDPIDEx(u16 vid,u16 pid){ - std::string result = ""; - std::map::iterator it; - - it = deviceNames.find(CPStringTools::strfmt("%04X%04X",vid,pid)); - if (it != deviceNames.end()){ - result = it->second; - }else{ - result = CPStringTools::strfmt("VID: 0x%04X\nPID: 0x%04X",vid,pid); - } - return result; -} diff --git a/wiiu/controller_patcher/config/ConfigValues.hpp b/wiiu/controller_patcher/config/ConfigValues.hpp deleted file mode 100644 index 27a835cf40..0000000000 --- a/wiiu/controller_patcher/config/ConfigValues.hpp +++ /dev/null @@ -1,569 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "../ControllerPatcher.hpp" - -class ConfigValues -{ -friend class ConfigParser; -friend class ControllerPatcher; -private: - static ConfigValues *getInstance() { - if(instance == NULL){ - printf("ConfigValues: We need a new instance!!!\n"); - instance = new ConfigValues(); - } - return instance; - } - - static void destroyInstance() { - if(instance){ - delete instance; - instance = NULL; - } - } - - /** - Returns NULL if not 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 s32 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 s32 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 s32 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 s32 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 s32 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 s32 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 s32 setIfValueIsAControllerPreset(std::string value,s32 slot,s32 keyslot) - { - ConfigValues * cur_instance = getInstance(); - if(cur_instance == NULL) return -1; - return cur_instance->setIfValueIsAControllerPresetEx(value,slot,keyslot); - } - - static void addDeviceName(u16 vid,u16 pid,std::string value){ - ConfigValues * cur_instance = getInstance(); - if(cur_instance != NULL){ - cur_instance->addDeviceNameEx(vid,pid,value); - } - } - - /** - Returns empty String if not found - **/ - static std::string getStringByVIDPID(u16 vid,u16 pid){ - ConfigValues * cur_instance = getInstance(); - if(cur_instance == NULL) return ""; - return cur_instance->getStringByVIDPIDEx(vid,pid); - } - - //!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 deviceNames; - - std::map presetGCValues; - std::map presetDS3Values; - std::map presetDS4Values; - std::map presetXInputValues; - std::map presetSwitchProValues; - std::map presetSticks; - - s32 getValueFromMap(std::map values,std::string nameOfString); - - bool checkIfValueIsAControllerPreset(std::string value,s32 slot,s32 keyslot); - - s32 getPresetValueEx(std::string possibleString); - - void InitValues(){ - printf("ConfigValues::InitValues: Init values for the configuration\n"); - 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"] = CONTRPS_VPAD_BUTTON_L_STICK_UP; - CONTPRStringToValue["VPAD_L_STICK_DOWN"] = CONTRPS_VPAD_BUTTON_L_STICK_DOWN; - CONTPRStringToValue["VPAD_L_STICK_LEFT"] = CONTRPS_VPAD_BUTTON_L_STICK_LEFT; - CONTPRStringToValue["VPAD_L_STICK_RIGHT"] = CONTRPS_VPAD_BUTTON_L_STICK_RIGHT; - - CONTPRStringToValue["VPAD_R_STICK_UP"] = CONTRPS_VPAD_BUTTON_R_STICK_UP; - CONTPRStringToValue["VPAD_R_STICK_DOWN"] = CONTRPS_VPAD_BUTTON_R_STICK_DOWN; - CONTPRStringToValue["VPAD_R_STICK_LEFT"] = CONTRPS_VPAD_BUTTON_R_STICK_LEFT; - CONTPRStringToValue["VPAD_R_STICK_RIGHT"] = CONTRPS_VPAD_BUTTON_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; - CONTPRStringToValue["PAD1_FILTER"] = CONTRPS_PAD1_FILTER; - CONTPRStringToValue["PAD2_FILTER"] = CONTRPS_PAD2_FILTER; - CONTPRStringToValue["PAD3_FILTER"] = CONTRPS_PAD3_FILTER; - CONTPRStringToValue["PAD4_FILTER"] = CONTRPS_PAD4_FILTER; - CONTPRStringToValue["PAD5_FILTER"] = CONTRPS_PAD5_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; - - presetXInputValues["XINPUT_BUTTON_A"] = HID_XINPUT_BUTTON_A; - presetXInputValues["XINPUT_BUTTON_B"] = HID_XINPUT_BUTTON_B; - presetXInputValues["XINPUT_BUTTON_X"] = HID_XINPUT_BUTTON_X; - presetXInputValues["XINPUT_BUTTON_Y"] = HID_XINPUT_BUTTON_Y; - - presetXInputValues["XINPUT_BUTTON_LB"] = HID_XINPUT_BUTTON_LB; - presetXInputValues["XINPUT_BUTTON_LT"] = HID_XINPUT_BUTTON_LT; - presetXInputValues["XINPUT_BUTTON_L3"] = HID_XINPUT_BUTTON_L3; - presetXInputValues["XINPUT_BUTTON_RB"] = HID_XINPUT_BUTTON_RB; - presetXInputValues["XINPUT_BUTTON_RT"] = HID_XINPUT_BUTTON_RT; - presetXInputValues["XINPUT_BUTTON_R3"] = HID_XINPUT_BUTTON_R3; - - presetXInputValues["XINPUT_BUTTON_START"] = HID_XINPUT_BUTTON_START; - presetXInputValues["XINPUT_BUTTON_BACK"] = HID_XINPUT_BUTTON_BACK; - presetXInputValues["XINPUT_BUTTON_DPAD_TYPE"] = HID_XINPUT_BUTTON_DPAD_TYPE; - - presetXInputValues["XINPUT_BUTTON_DPAD_UP"] = HID_XINPUT_BUTTON_UP; - presetXInputValues["XINPUT_BUTTON_DPAD_DOWN"] = HID_XINPUT_BUTTON_DOWN; - presetXInputValues["XINPUT_BUTTON_DPAD_LEFT"] = HID_XINPUT_BUTTON_LEFT; - presetXInputValues["XINPUT_BUTTON_DPAD_RIGHT"] = HID_XINPUT_BUTTON_RIGHT; - - presetXInputValues["XINPUT_BUTTON_GUIDE"] = HID_XINPUT_BUTTON_GUIDE; - - presetSwitchProValues["SWITCH_PRO_BUTTON_A"] = HID_SWITCH_PRO_BT_BUTTON_A; - presetSwitchProValues["SWITCH_PRO_BUTTON_B"] = HID_SWITCH_PRO_BT_BUTTON_B; - presetSwitchProValues["SWITCH_PRO_BUTTON_X"] = HID_SWITCH_PRO_BT_BUTTON_X; - presetSwitchProValues["SWITCH_PRO_BUTTON_Y"] = HID_SWITCH_PRO_BT_BUTTON_Y; - - presetSwitchProValues["SWITCH_PRO_BUTTON_PLUS"] = HID_SWITCH_PRO_BT_BUTTON_PLUS; - presetSwitchProValues["SWITCH_PRO_BUTTON_MINUS"] = HID_SWITCH_PRO_BT_BUTTON_MINUS; - presetSwitchProValues["SWITCH_PRO_BUTTON_HOME"] = HID_SWITCH_PRO_BT_BUTTON_HOME; - - presetSwitchProValues["SWITCH_PRO_BUTTON_L"] = HID_SWITCH_PRO_BT_BUTTON_L; - presetSwitchProValues["SWITCH_PRO_BUTTON_R"] = HID_SWITCH_PRO_BT_BUTTON_R; - - presetSwitchProValues["SWITCH_PRO_BUTTON_ZL"] = HID_SWITCH_PRO_BT_BUTTON_ZL; - presetSwitchProValues["SWITCH_PRO_BUTTON_ZR"] = HID_SWITCH_PRO_BT_BUTTON_ZR; - - presetSwitchProValues["SWITCH_PRO_BUTTON_STICK_L"] = HID_SWITCH_PRO_BT_BUTTON_STICK_L; - presetSwitchProValues["SWITCH_PRO_BUTTON_STICK_R"] = HID_SWITCH_PRO_BT_BUTTON_STICK_R; - - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_N"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_N; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NE; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_E"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_E; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_SE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_SE; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_S"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_S; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_SW"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_SW; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_W"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_W; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NW"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NW; - presetSwitchProValues["SWITCH_PRO_BUTTON_DPAD_NEUTRAL"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL; - - presetKeyboardValues["KEYBOARD_SHIFT"] = HID_KEYBOARD_BUTTON_SHIFT; - presetKeyboardValues["KEYBOARD_A"] = HID_KEYBOARD_BUTTON_A; - presetKeyboardValues["KEYBOARD_B"] = HID_KEYBOARD_BUTTON_B; - 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["XINPUT_STICK_L_X"] = HID_XINPUT_STICK_L_X; - presetSticks["XINPUT_STICK_L_Y"] = HID_XINPUT_STICK_L_Y; - presetSticks["XINPUT_STICK_R_X"] = HID_XINPUT_STICK_R_X; - presetSticks["XINPUT_STICK_R_Y"] = HID_XINPUT_STICK_R_Y; - - presetSticks["SWITCH_PRO_STICK_L_X"] = HID_SWITCH_PRO_BT_STICK_L_X; - presetSticks["SWITCH_PRO_STICK_L_Y"] = HID_SWITCH_PRO_BT_STICK_L_Y; - presetSticks["SWITCH_PRO_STICK_R_X"] = HID_SWITCH_PRO_BT_STICK_R_X; - presetSticks["SWITCH_PRO_STICK_R_Y"] = HID_SWITCH_PRO_BT_STICK_R_Y; - - presetSticks["GC_DPAD_MODE"] = HID_GC_BUTTON_DPAD_TYPE; - presetSticks["DS3_DPAD_MODE"] = HID_DS3_BUTTON_DPAD_TYPE; - presetSticks["DS4_DPAD_MODE"] = HID_DS4_BUTTON_DPAD_TYPE; - presetSticks["XINPUT_DPAD_MODE"] = HID_XINPUT_BUTTON_DPAD_TYPE; - presetSticks["SWITCH_PRO_DPAD_MODE"] = HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE; - - gGamePadValuesToCONTRPSString["VPAD_BUTTON_A"] = CONTRPS_VPAD_BUTTON_A; - gGamePadValuesToCONTRPSString["VPAD_BUTTON_B"] = CONTRPS_VPAD_BUTTON_B; - 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; - - 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; - - deviceNames[CPStringTools::strfmt("%04X%04X",HID_GC_VID, HID_GC_PID).c_str()] = HID_GC_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_KEYBOARD_VID, HID_KEYBOARD_PID).c_str()] = HID_KEYBOARD_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_MOUSE_VID, HID_MOUSE_PID).c_str()] = HID_MOUSE_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS3_VID, HID_DS3_PID).c_str()] = HID_DS3_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_NEW_DS4_VID, HID_NEW_DS4_PID).c_str()] = HID_NEW_DS4_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_DS4_VID, HID_DS4_PID).c_str()] = HID_DS4_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_XINPUT_VID, HID_XINPUT_PID).c_str()] = HID_XINPUT_STRING; - deviceNames[CPStringTools::strfmt("%04X%04X",HID_SWITCH_PRO_VID,HID_SWITCH_PRO_PID).c_str()] = HID_SWITCH_PRO_STRING; - } - - const u8 * getValuesForPreset(std::map values,std::string possibleValue); - - bool setIfValueIsPreset(std::map values,std::string possibleValue,s32 slot,s32 keyslot); - bool setIfValueIsAControllerPresetEx(std::string value,s32 slot,s32 keyslot); - - void addDeviceNameEx(u16 vid,u16 pid,std::string value); - std::string getStringByVIDPIDEx(u16 vid,u16 pid); -}; -#endif diff --git a/wiiu/controller_patcher/network/ControllerPatcherNet.cpp b/wiiu/controller_patcher/network/ControllerPatcherNet.cpp deleted file mode 100644 index 8e5f7d109d..0000000000 --- a/wiiu/controller_patcher/network/ControllerPatcherNet.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "ControllerPatcherNet.hpp" -#include "wiiu/os.h" -#include "sys/socket.h" - -s32 ControllerPatcherNet::recvwait(s32 sock, void *buffer, s32 len) { - s32 ret; - while (len > 0) { - ret = recv(sock, buffer, len, 0); - if(ret < 0) return ret; - len -= ret; - buffer = (void *)(((char *) buffer) + ret); - } - return 0; -} - -u8 ControllerPatcherNet::recvbyte(s32 sock) { - unsigned char buffer[1]; - s32 ret; - - ret = recvwait(sock, buffer, 1); - if (ret < 0) return ret; - return buffer[0]; -} - -s32 ControllerPatcherNet::checkbyte(s32 sock) { - unsigned char buffer[1]; - s32 ret; - - ret = recv(sock, buffer, 1, MSG_DONTWAIT); - if (ret < 0) return ret; - if (ret == 0) return -1; - return buffer[0]; -} - -s32 ControllerPatcherNet::sendwait(s32 sock, const void *buffer, s32 len) { - s32 ret; - while (len > 0) { - ret = send(sock, buffer, len, 0); - if(ret < 0) return ret; - len -= ret; - buffer = (void *)(((char *) buffer) + ret); - } - return 0; -} - -s32 ControllerPatcherNet::sendbyte(s32 sock, unsigned char byte) { - unsigned char buffer[1]; - buffer[0] = byte; - return sendwait(sock, buffer, 1); -} diff --git a/wiiu/controller_patcher/network/ControllerPatcherNet.hpp b/wiiu/controller_patcher/network/ControllerPatcherNet.hpp deleted file mode 100644 index 331ad096a3..0000000000 --- a/wiiu/controller_patcher/network/ControllerPatcherNet.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _CONTROLLERPATCHERNET_H_ -#define _CONTROLLERPATCHERNET_H_ - -#include "wiiu/types.h" - -class ControllerPatcherNet{ - friend class TCPServer; - friend class UDPServer; - private: - static s32 recvwait(s32 sock, void *buffer, s32 len); - static u8 recvbyte(s32 sock); - static s32 checkbyte(s32 sock); - static s32 sendwait(s32 sock, const void *buffer, s32 len); - static s32 sendbyte(s32 sock, unsigned char byte); -}; - -#endif diff --git a/wiiu/controller_patcher/network/TCPServer.cpp b/wiiu/controller_patcher/network/TCPServer.cpp deleted file mode 100644 index 485544996d..0000000000 --- a/wiiu/controller_patcher/network/TCPServer.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "TCPServer.hpp" -#include -#include -#include - -#define wiiu_errno (*__gh_errno_ptr()) - -ControllerPatcherThread * TCPServer::pThread = NULL; -TCPServer * TCPServer::instance = NULL; - -TCPServer::TCPServer(s32 port){ - this->sockfd = -1; - this->clientfd = -1; - memset(&(this->sock_addr),0,sizeof(this->sock_addr)); - TCPServer::AttachDetach(DETACH); - StartTCPThread(this); -} - -TCPServer::~TCPServer(){ - CloseSockets(); - if(HID_DEBUG){ printf("TCPServer::~TCPServer(line %d): Thread will be closed\n",__LINE__); } - TCPServer::AttachDetach(DETACH); - exitThread = 1; - if(TCPServer::pThread != NULL){ - if(HID_DEBUG){ printf("TCPServer::~TCPServer(line %d): Deleting it!\n",__LINE__); } - delete TCPServer::pThread; - } - if(HID_DEBUG){ printf("TCPServer::~TCPServer(line %d): Thread done\n",__LINE__); } - TCPServer::pThread = NULL; -} - -void TCPServer::CloseSockets(){ - if (this->sockfd != -1){ - socketclose(this->sockfd); - } - if (this->clientfd != -1){ - socketclose(this->clientfd); - } - this->sockfd = -1; - this->clientfd = -1; -} - -void TCPServer::StartTCPThread(TCPServer * server){ - s32 priority = 28; - if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN - OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA - OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR - OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR - OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA - priority = 10; - printf("TCPServer::StartTCPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority); - } - TCPServer::pThread = ControllerPatcherThread::create(TCPServer::DoTCPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority); - TCPServer::pThread->resumeThread(); -} - -void TCPServer::AttachDetach(s32 attach){ - if(HID_DEBUG){ - if(attach){ - printf("TCPServer::AttachDetach(line %d): Network Attach\n",__LINE__); - }else{ - printf("TCPServer::AttachDetach(line %d): Network Detach\n",__LINE__); - } - } - - for(s32 i= 0;i< gHIDMaxDevices;i++){ - for(s32 j= 0;j< HID_MAX_PADS_COUNT;j++){ - if(gNetworkController[i][j][NETWORK_CONTROLLER_ACTIVE] > 0){ - printf("TCPServer::AttachDetach(line %d): Found a registered pad in deviceslot %d and padslot %d! Lets detach it.\n",__LINE__,i,j); - HIDDevice device; - memset(&device,0,sizeof(device)); - - device.interface_index = 0; - device.vid = gNetworkController[i][j][NETWORK_CONTROLLER_VID]; - device.pid = gNetworkController[i][j][NETWORK_CONTROLLER_PID]; - device.handle = gNetworkController[i][j][NETWORK_CONTROLLER_HANDLE]; - device.max_packet_size_rx = 8; - ControllerPatcherHID::externAttachDetachCallback(&device,attach); - memset(gNetworkController[i][j],0,sizeof(gNetworkController[i][j])); - } - } - } - - if(HID_DEBUG){ - if(attach){ - printf("TCPServer::AttachDetach(line %d): Network Attach DONE!\n",__LINE__); - }else{ - printf("TCPServer::AttachDetach(line %d): Network Detach DONE!\n",__LINE__); - } - } -} - -void TCPServer::DetachAndDelete(){ - TCPServer::AttachDetach(DETACH); - memset(&gNetworkController,0,sizeof(gNetworkController)); -} - -s32 TCPServer::RunTCP(){ - s32 ret; - while (1) { - if(exitThread) break; - ret = ControllerPatcherNet::checkbyte(clientfd); - if (ret < 0) { - if(wiiu_errno != 6) return ret; - wiiu_os_usleep(1000); - continue; - } - //printf("got byte from tcp! %01X\n",ret); - switch (ret) { - case WIIU_CP_TCP_ATTACH: { /*attach */ - if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){ - s32 handle; - ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_ATTACH); - return ret; - } - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): got handle %d\n",handle); } - u16 vid = 0; - u16 pid = 0; - ret = ControllerPatcherNet::recvwait(clientfd, &vid, 2); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait vid\n",__LINE__,WIIU_CP_TCP_ATTACH); - return ret; - } - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): got vid %04X\n",vid); } - - ret = ControllerPatcherNet::recvwait(clientfd, &pid, 2); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait pid\n",__LINE__,WIIU_CP_TCP_ATTACH); - return ret; - } - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): got pid %04X\n",pid); } - HIDDevice device; - memset(&device,0,sizeof(device)); - device.handle = handle; - device.interface_index = 0; - device.vid = SWAP16(vid); - device.pid = SWAP16(pid); - device.max_packet_size_rx = 8; - - my_cb_user * user = NULL; - ControllerPatcherHID::externAttachDetachCallback(&device,1); - if((ret = ControllerPatcherUtils::getDataByHandle(handle,&user)) < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_ATTACH,handle,&user); - printf("TCPServer::RunTCP(line %d): Error in %02X: Config for the controller is missing.\n",__LINE__,WIIU_CP_TCP_ATTACH); - if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND) < 0)){ - printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret); - } - return -1; - } - if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_CONFIG_FOUND) < 0)){ - printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_CONFIG_FOUND byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret); - return ret; - } - if(user != NULL){ - if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_OKAY) < 0)){ - printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_OKAY byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret); - return ret; - } - - ret = ControllerPatcherNet::sendwait(clientfd,&user->slotdata.deviceslot,2); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait slotdata: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->slotdata.deviceslot); - return ret; - } - ret = ControllerPatcherNet::sendwait(clientfd,&user->pad_slot,1); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: sendwait pad_slot: %04X\n",__LINE__,WIIU_CP_TCP_ATTACH,user->pad_slot); - return ret; - } - }else{ - printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_ATTACH); - if((ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_ATTACH_USER_DATA_BAD) < 0)){ - printf("TCPServer::RunTCP(line %d): Error in %02X: Sending the WIIU_CP_TCP_ATTACH_USER_DATA_BAD byte failed. Error: %d.\n",__LINE__,WIIU_CP_TCP_ATTACH,ret); - return ret; - } - return -1; - break; - } - - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): attachted to device slot: %d , pad slot is: %d\n",__LINE__,user->slotdata.deviceslot,user->pad_slot); } - - gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_VID] = device.vid; - gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_PID] = device.pid; - gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_ACTIVE] = 1; - gNetworkController[user->slotdata.deviceslot][user->pad_slot][NETWORK_CONTROLLER_HANDLE] = handle; - - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): handle %d connected! vid: %02X pid: %02X deviceslot %d, padslot %d\n",__LINE__,handle,vid,pid,user->slotdata.deviceslot,user->pad_slot); } - break; - } - break; - } - case WIIU_CP_TCP_DETACH: { /*detach */ - if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){ - s32 handle; - ret = ControllerPatcherNet::recvwait(clientfd, &handle, 4); - if(ret < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: recvwait handle\n",__LINE__,WIIU_CP_TCP_DETACH); - return ret; - break; - } - - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): got detach for handle: %d\n",__LINE__,handle); } - my_cb_user * user = NULL; - if(ControllerPatcherUtils::getDataByHandle(handle,&user) < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: getDataByHandle(%d,%08X).\n",__LINE__,WIIU_CP_TCP_DETACH,handle,&user); - return -1; - break; - } - if(user == NULL){ - printf("TCPServer::RunTCP(line %d): Error in %02X: invalid user data.\n",__LINE__,WIIU_CP_TCP_DETACH); - return -1; - break; - } - s32 deviceslot = user->slotdata.deviceslot; - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): device slot is: %d , pad slot is: %d\n",__LINE__,deviceslot,user->pad_slot); } - - DeviceVIDPIDInfo vidpid; - s32 result; - if((result = ControllerPatcherUtils::getVIDPIDbyDeviceSlot(deviceslot,&vidpid)) < 0){ - printf("TCPServer::RunTCP(line %d): Error in %02X: Couldn't find a valid VID/PID for device slot %d. Error: %d\n",__LINE__,WIIU_CP_TCP_DETACH,deviceslot,ret); - return -1; - break; - } - - HIDDevice device; - memset(&device,0,sizeof(device)); - device.handle = handle; - device.interface_index = 0; - device.vid = SWAP16(vidpid.vid); - device.pid = SWAP16(vidpid.pid); - device.max_packet_size_rx = 14; - - ControllerPatcherHID::externAttachDetachCallback(&device,DETACH); - memset(gNetworkController[deviceslot][user->pad_slot],0,sizeof(gNetworkController[deviceslot][user->pad_slot])); - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): handle %d disconnected!\n",__LINE__,handle); } - break; - } - break; - } - case WIIU_CP_TCP_PING: { /*ping*/ - if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){ - if(HID_DEBUG){ printf("TCPServer::RunTCP(line %d): Got Ping, sending now a Pong\n",__LINE__); } - s32 ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_PONG); - if(ret < 0){ printf("TCPServer::RunTCP(line %d): Error in %02X: sendbyte PONG\n",__LINE__); return -1;} - - break; - } - break; - } - default: - return -1; - break; - } - } - return 0; -} - -void TCPServer::ErrorHandling(){ - CloseSockets(); - wiiu_os_usleep(1000*1000*2); -} - -void TCPServer::DoTCPThreadInternal(){ - s32 ret; - s32 len; - while (1) { - if(exitThread) break; - memset(&(this->sock_addr),0,sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_port = DEFAULT_TCP_PORT; - sock_addr.sin_addr.s_addr = 0; - - this->sockfd = ret = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if(ret == -1){ ErrorHandling(); continue;} - s32 enable = 1; - - setsockopt(this->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); - - ret = bind(this->sockfd, (sockaddr *)&sock_addr, 16); - if(ret < 0) { ErrorHandling(); continue;} - ret = listen(this->sockfd, 1); - if(ret < 0){ ErrorHandling(); continue;} - - do{ - if(HID_DEBUG){ printf("TCPServer::DoTCPThreadInternal(line %d): Waiting for a connection\n",__LINE__); } - if(exitThread) break; - len = 16; - - /** - Handshake - 1. At first this server sends his protocol version - 2. The network clients answers with his preferred version (which needs to be equals or lower the version this server sent him) or an abort command. - 3a. If the client sent a abort, close the connection and wait for another connection - 3b. If the client sent his highest supported version, the server confirm that he is able to use this version (by sending the version back) or sending a abort command to disconnect. - **/ - - clientfd = ret = (s32)accept(sockfd, (sockaddr *)&(sock_addr),(socklen_t *) &len); - - if(ret == -1){ ErrorHandling(); break;} - printf("TCPServer::DoTCPThreadInternal(line %d): TCP Connection accepted! Sending my protocol version: %d (0x%02X)\n",__LINE__, (WIIU_CP_TCP_HANDSHAKE - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,WIIU_CP_TCP_HANDSHAKE); - - gUDPClientip = sock_addr.sin_addr.s_addr; - UDPClient::createInstance(); - - s32 ret; - ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE); //Hey I'm a WiiU console! - if(ret < 0){ printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte: %02X\n",__LINE__,WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;} - - u8 clientProtocolVersion = ControllerPatcherNet::recvbyte(clientfd); - if(ret < 0){ printf("TCPServer::DoTCPThreadInternal(line %d): Error recvbyte: %02X\n",__LINE__,WIIU_CP_TCP_HANDSHAKE); ErrorHandling(); break;} - - if(clientProtocolVersion == WIIU_CP_TCP_HANDSHAKE_ABORT){ - printf("TCPServer::DoTCPThreadInternal(line %d): The network client wants to abort.\n",__LINE__); - ErrorHandling(); break; - } - - printf("TCPServer::DoTCPThreadInternal(line %d): received protocol version: %d (0x%02X)\n",__LINE__,(clientProtocolVersion - WIIU_CP_TCP_HANDSHAKE_VERSION_1)+1,clientProtocolVersion); - - if(clientProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_MIN && clientProtocolVersion <= WIIU_CP_TCP_HANDSHAKE_VERSION_MAX){ - printf("TCPServer::DoTCPThreadInternal(line %d): We support this protocol version. Let's confirm it to the network client.\n",__LINE__); - gUsedProtocolVersion = clientProtocolVersion; - ret = ControllerPatcherNet::sendbyte(clientfd, clientProtocolVersion); - if(ret < 0){ printf("TCPServer::DoTCPThreadInternal(line %d): Error sendbyte: %02X\n",__LINE__,clientProtocolVersion); ErrorHandling(); break;} - }else{ - printf("TCPServer::DoTCPThreadInternal(line %d): We don't support this protocol version. We need to abort =(.\n",__LINE__); - ret = ControllerPatcherNet::sendbyte(clientfd, WIIU_CP_TCP_HANDSHAKE_ABORT); - ErrorHandling(); break; - } - - printf("TCPServer::DoTCPThreadInternal(line %d): Handshake done! Success!\n",__LINE__); - - TCPServer::DetachAndDelete(); //Clear connected controller - RunTCP(); - - if(clientfd != -1){ - socketclose(clientfd); - } - clientfd = -1; - }while(0); - printf("TCPServer::DoTCPThreadInternal(line %d): Connection closed\n",__LINE__); - gUDPClientip = 0; - UDPClient::destroyInstance(); - TCPServer::DetachAndDelete(); //Clear connected controller - CloseSockets(); - continue; - } - -} - -void TCPServer::DoTCPThread(ControllerPatcherThread *thread, void *arg){ - TCPServer * args = (TCPServer * )arg; - return args->DoTCPThreadInternal(); -} diff --git a/wiiu/controller_patcher/network/TCPServer.hpp b/wiiu/controller_patcher/network/TCPServer.hpp deleted file mode 100644 index 2266ce9663..0000000000 --- a/wiiu/controller_patcher/network/TCPServer.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 _TCPSERVER_WINDOW_H_ -#define _TCPSERVER_WINDOW_H_ - -#include "../ControllerPatcher.hpp" - -#include "sys/socket.h" -#include "netinet/in.h" -#include "wiiu/os.h" - -#define WIIU_CP_TCP_HANDSHAKE WIIU_CP_TCP_HANDSHAKE_VERSION_3 - -#define WIIU_CP_TCP_HANDSHAKE_VERSION_MIN WIIU_CP_TCP_HANDSHAKE_VERSION_1 -#define WIIU_CP_TCP_HANDSHAKE_VERSION_MAX WIIU_CP_TCP_HANDSHAKE_VERSION_3 - -#define WIIU_CP_TCP_HANDSHAKE_VERSION_1 0x12 -#define WIIU_CP_TCP_HANDSHAKE_VERSION_2 0x13 -#define WIIU_CP_TCP_HANDSHAKE_VERSION_3 0x14 - -#define WIIU_CP_TCP_HANDSHAKE_ABORT 0x30 - -#define ATTACH 0x01 -#define DETACH 0x00 - -#define WIIU_CP_TCP_ATTACH 0x01 -#define WIIU_CP_TCP_DETACH 0x02 -#define WIIU_CP_TCP_PING 0xF0 -#define WIIU_CP_TCP_PONG 0xF1 - -#define WIIU_CP_TCP_ATTACH_CONFIG_FOUND 0xE0 -#define WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND 0xE1 -#define WIIU_CP_TCP_ATTACH_USER_DATA_OKAY 0xE8 -#define WIIU_CP_TCP_ATTACH_USER_DATA_BAD 0xE9 - -#define DEFAULT_TCP_PORT 8112 - -class TCPServer{ - friend class ControllerPatcher; - -private: - static TCPServer *getInstance() { - if(!instance) - instance = new TCPServer(DEFAULT_TCP_PORT); - return instance; - } - - static void destroyInstance() { - if(instance){ - delete instance; - instance = NULL; - } - } - - TCPServer(s32 port); - ~TCPServer(); - - void CloseSockets(); - void ErrorHandling(); - - void StartTCPThread(TCPServer * server); - static void DoTCPThread(ControllerPatcherThread *thread, void *arg); - void DoTCPThreadInternal(); - static void DetachConnectedNetworkController(); - static void AttachDetach(s32 attach); - void DetachAndDelete(); - static TCPServer *instance; - - s32 RunTCP(); - - struct sockaddr_in sock_addr; - volatile s32 sockfd = -1; - volatile s32 clientfd = -1; - - - volatile s32 exitThread = 0; - static ControllerPatcherThread *pThread; -}; - -#endif //_TCPSERVER_WINDOW_H_ diff --git a/wiiu/controller_patcher/network/UDPClient.cpp b/wiiu/controller_patcher/network/UDPClient.cpp deleted file mode 100644 index 75d90e6aef..0000000000 --- a/wiiu/controller_patcher/network/UDPClient.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "UDPClient.hpp" -#include -#include - -#define MAX_UDP_SIZE 0x578 - -UDPClient * UDPClient::instance = NULL; - -UDPClient::UDPClient(u32 ip, s32 port){ - sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (sockfd < 0) - return; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = port; - connect_addr.sin_addr.s_addr = ip; - - if(connect(sockfd, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) - { - socketclose(sockfd); - sockfd = -1; - } -} - -UDPClient::~UDPClient(){ - if (this->sockfd != -1){ - socketclose(sockfd); - } - if(HID_DEBUG){ printf("UDPClient::~UDPClient(line %d): Thread has been closed\n",__LINE__); } -} - -bool UDPClient::sendData(char * data,s32 length){ - if(sockfd < 0 || data == 0 || length < 0 || gUsedProtocolVersion < WIIU_CP_TCP_HANDSHAKE_VERSION_3){ - return false; - } - if(length > 1400) length = 1400; - - s32 ret = send(sockfd, data, length, 0); - return (ret >= 0); -} diff --git a/wiiu/controller_patcher/network/UDPClient.hpp b/wiiu/controller_patcher/network/UDPClient.hpp deleted file mode 100644 index e45c91f3d9..0000000000 --- a/wiiu/controller_patcher/network/UDPClient.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 _UDPCLIENT_WINDOW_H_ -#define _UDPCLIENT_WINDOW_H_ - -#include "../ControllerPatcher.hpp" - -#include "sys/socket.h" -#include "netinet/in.h" - -#define DEFAULT_UDP_CLIENT_PORT 8114 - -class UDPClient{ - friend class ControllerPatcher; - friend class ControllerPatcherHID; - friend class TCPServer; -public: - -private: - static UDPClient *getInstance() { - if(instance == NULL){ - createInstance(); - } - return instance; - } - - - static UDPClient *createInstance() { - if(instance != NULL){ - destroyInstance(); - } - instance = new UDPClient(gUDPClientip,DEFAULT_UDP_CLIENT_PORT); - - return getInstance(); - } - - static void destroyInstance() { - if(instance != NULL){ - delete instance; - instance = NULL; - } - } - - UDPClient(u32 ip,s32 port); - ~UDPClient(); - bool sendData(char * data, s32 length); - - volatile s32 sockfd = -1; - struct sockaddr_in addr; - static UDPClient *instance; -}; - -#endif //_UDPClient_WINDOW_H_ diff --git a/wiiu/controller_patcher/network/UDPServer.cpp b/wiiu/controller_patcher/network/UDPServer.cpp deleted file mode 100644 index d30e63109e..0000000000 --- a/wiiu/controller_patcher/network/UDPServer.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "UDPServer.hpp" -#include -#include -#include - -#include "sys/socket.h" - -#define MAX_UDP_SIZE 0x578 -#define wiiu_errno (*__gh_errno_ptr()) - -ControllerPatcherThread * UDPServer::pThread = NULL; -UDPServer * UDPServer::instance = NULL; - -UDPServer::UDPServer(s32 port){ - s32 ret; - struct sockaddr_in addr; - - addr.sin_family = AF_INET; - addr.sin_port = port; - addr.sin_addr.s_addr = 0; - - this->sockfd = ret = socket(AF_INET, SOCK_DGRAM, 0); - if(ret == -1) return; - s32 enable = 1; - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); - ret = bind(sockfd, (sockaddr *)&addr, 16); - if(ret < 0) return; - - StartUDPThread(this); -} - -UDPServer::~UDPServer(){ - ControllerPatcherThread * pThreadPointer = UDPServer::pThread; - if(pThreadPointer != NULL){ - exitThread = 1; - if(pThreadPointer != NULL){ - delete pThreadPointer; - UDPServer::pThread = NULL; - if (this->sockfd != -1){ - socketclose(sockfd); - } - this->sockfd = -1; - } - } - if(HID_DEBUG){ printf("UDPServer::~UDPServer(line %d): Thread has been closed\n",__LINE__); } - - -} - -void UDPServer::StartUDPThread(UDPServer * server){ - s32 priority = 28; - if(OSGetTitleID() == 0x00050000101c9300 || //The Legend of Zelda Breath of the Wild JPN - OSGetTitleID() == 0x00050000101c9400 || //The Legend of Zelda Breath of the Wild USA - OSGetTitleID() == 0x00050000101c9500 || //The Legend of Zelda Breath of the Wild EUR - OSGetTitleID() == 0x00050000101c9b00 || //The Binding of Isaac: Rebirth EUR - OSGetTitleID() == 0x00050000101a3c00){ //The Binding of Isaac: Rebirth USA - priority = 10; - printf("UDPServer::StartUDPThread(line %d): This game needs higher thread priority. We set it to %d\n",__LINE__,priority); - } - UDPServer::pThread = ControllerPatcherThread::create(UDPServer::DoUDPThread, (void*)server, ControllerPatcherThread::eAttributeAffCore2,priority); - UDPServer::pThread->resumeThread(); -} - -bool UDPServer::cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum){ - if(((int)*offset + typesize) > maximum){ - printf("UDPServer::cpyIncrementBufferOffset(line %d): Transfer error. Excepted %04X bytes, but only got %04X\n",__LINE__,(*offset + typesize),maximum); - return false; - } - memcpy(target,(void*)((u32)source+(*offset)),typesize); - *offset += typesize; - return true; -} - -void UDPServer::DoUDPThread(ControllerPatcherThread *thread, void *arg){ - UDPServer * args = (UDPServer * )arg; - args->DoUDPThreadInternal(); -} - -void UDPServer::DoUDPThreadInternal(){ - u8 buffer[MAX_UDP_SIZE]; - s32 n; - - my_cb_user user; - while(1){ - //s32 usingVar = exitThread; - if(exitThread)break; - memset(buffer,0,MAX_UDP_SIZE); - n = recv(sockfd,buffer,MAX_UDP_SIZE,0); - if (n < 0){ - s32 errno_ = wiiu_errno; - wiiu_os_usleep(2000); - if(errno_ != 11 && errno_ != 9){ - break; - } - continue; - } - s32 bufferoffset = 0; - u8 type; - memcpy((void *)&type,buffer,sizeof(type)); - bufferoffset += sizeof(type); - switch (buffer[0]) { - case WIIU_CP_UDP_CONTROLLER_READ_DATA: { - if(gUsedProtocolVersion >= WIIU_CP_TCP_HANDSHAKE_VERSION_1){ - u8 count_commands; - memcpy((void *)&count_commands,buffer+bufferoffset,sizeof(count_commands)); - bufferoffset += sizeof(count_commands); - for(s32 i = 0;i. - ****************************************************************************/ -#ifndef _UDPSERVER_WINDOW_H_ -#define _UDPSERVER_WINDOW_H_ - -#include "../ControllerPatcher.hpp" - -#define DEFAULT_UDP_PORT 8113 - -#define WIIU_CP_UDP_CONTROLLER_READ_DATA 0x03 - -class UDPServer{ - friend class ControllerPatcher; - -private: - static UDPServer *getInstance() { - if(instance == NULL) - instance = new UDPServer(DEFAULT_UDP_PORT); - return instance; - } - - static void destroyInstance() { - if(instance != NULL){ - delete instance; - instance = NULL; - } - } - - UDPServer(s32 port); - ~UDPServer(); - void StartUDPThread(UDPServer * server); - static void DoUDPThread(ControllerPatcherThread *thread, void *arg); - void DoUDPThreadInternal(); - bool cpyIncrementBufferOffset(void * target, void * source, s32 * offset, s32 typesize, s32 maximum); - - volatile s32 sockfd = -1; - volatile s32 exitThread = 0; - - static UDPServer *instance; - static ControllerPatcherThread *pThread; -}; - -#endif //_UDPSERVER_WINDOW_H_ diff --git a/wiiu/controller_patcher/patcher/ControllerPatcherDefs.h b/wiiu/controller_patcher/patcher/ControllerPatcherDefs.h deleted file mode 100644 index 0dcc7954d0..0000000000 --- a/wiiu/controller_patcher/patcher/ControllerPatcherDefs.h +++ /dev/null @@ -1,710 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 . - ****************************************************************************/ - -/** - * @file ControllerPatcherDefs.h - * @author Maschell - * @date 30 Mar 2017 - * \brief This files contain all definitions for the ControllerPatcher engine - * - * @see https://github.com/Maschell/controller_patcher - */ - -#ifndef _CONTROLLER_PATCHER_DEFS_H_ -#define _CONTROLLER_PATCHER_DEFS_H_ - -#include - -#define FIRST_INSTRUCTION_IN_SAMPLING_CALLBACK 0x9421FFB8 - -#define HID_INIT_NOT_DONE 0 -#define HID_INIT_DONE 1 -#define HID_SDCARD_READ 2 - -#define gHIDMaxDevices 32 -#define HID_MAX_DATA_LENGTH_PER_PAD 16 -#define HID_MAX_PADS_COUNT 5 -#define HID_MAX_DEVICES_PER_SLOT 2 - -#define NETWORK_CONTROLLER_VID 0 -#define NETWORK_CONTROLLER_PID 1 -#define NETWORK_CONTROLLER_ACTIVE 2 -#define NETWORK_CONTROLLER_HANDLE 3 - - -#define CONTROLLER_PATCHER_VALUE_SET 0x01 -#define CONTROLLER_PATCHER_GC_DOUBLE_USE 0x01 -#define CONTROLLER_PATCHER_INVALIDVALUE 0xFF - -#define HID_INVALID_SLOT 0xFFFF -#define HID_INVALID_HIDMASK 0xFFFFFFFF - -typedef int CONTROLLER_PATCHER_RESULT_OR_ERROR; - -#define CONTROLLER_PATCHER_ERROR_NONE 0 -#define CONTROLLER_PATCHER_ERROR_INVALID_CHAN -1 -#define CONTROLLER_PATCHER_ERROR_UNKNOWN_VID_PID -2 -#define CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA -3 -#define CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED -4 -#define CONTROLLER_PATCHER_ERROR_INVALID_BUFFER -5 -#define CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED -6 -#define CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED -7 -#define CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND -8 -#define CONTROLLER_PATCHER_ERROR_NULL_POINTER -9 -#define CONTROLLER_PATCHER_ERROR_CONFIG_NOT_DONE -10 -#define CONTROLLER_PATCHER_ERROR_NO_FREE_SLOT -11 -#define CONTROLLER_PATCHER_ERROR_UNKNOWN -50 - -#define PRO_CONTROLLER_MODE_KPADDATA 0 -#define PRO_CONTROLLER_MODE_WPADReadData 1 - -#define STICK_VALUE_UP 1 << 1 -#define STICK_VALUE_DOWN 1 << 2 -#define STICK_VALUE_LEFT 1 << 3 -#define STICK_VALUE_RIGHT 1 << 4 - -/** - * @brief The enumeration of Controller sticks defines - */ -enum Controller_Stick_Defines -{ - STICK_CONF_MAGIC_VERSION, /**< Version of the stick configuration. Changes with every format*/ - STICK_CONF_BYTE, /**< Byte where the stick-axis data is stored*/ - STICK_CONF_DEFAULT, /**< Default value*/ - STICK_CONF_DEADZONE, /**< Size of the deadzone */ - STICK_CONF_INVERT, /**< Is 1 when the axis is inverted */ - STICK_CONF_MIN, /**< Value that represent the minimum value (-1.0f)*/ - STICK_CONF_MAX, /**< Value that represent the maximum value (1.0f) */ - STICK_CONF_ENUM_MAXVALUE /**< Maxmimum enum value for iteration*/ -}; - -#define STICK_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!! - -//! most data has the format: byte,value (byte starting at 0) -enum Controller_Patcher_Settings -{ - CONTRPS_VID, //! pid: 0x451d would be 0x45,0x1d - CONTRPS_PID, //! vid: 0x488d would be 0x48,0x8d - CONTRPS_BUF_SIZE, //! To set: CONTROLLER_PATCHER_VALUE_SET, BUF_SIZE (default is 64) - CONTRPS_VPAD_BUTTON_A, - CONTRPS_VPAD_BUTTON_B, - CONTRPS_VPAD_BUTTON_X, - CONTRPS_VPAD_BUTTON_Y, - CONTRPS_DPAD_MODE, //! To set mode: CONTROLLER_PATCHER_VALUE_SET, Controller_Patcher_DPAD_MODE (default is normal mode) - CONTRPS_DPAD_MASK, //! Mask needed for hat mode: CONTROLLER_PATCHER_VALUE_SET, mask - /* Normal DPAD */ - CONTRPS_VPAD_BUTTON_LEFT, - CONTRPS_VPAD_BUTTON_RIGHT, - CONTRPS_VPAD_BUTTON_UP, - CONTRPS_VPAD_BUTTON_DOWN, - /* DPAD hat mode */ - CONTRPS_VPAD_BUTTON_DPAD_N, - CONTRPS_VPAD_BUTTON_DPAD_NE, - CONTRPS_VPAD_BUTTON_DPAD_E, - CONTRPS_VPAD_BUTTON_DPAD_SE, - CONTRPS_VPAD_BUTTON_DPAD_S, - CONTRPS_VPAD_BUTTON_DPAD_SW, - 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, - CONTRPS_VPAD_BUTTON_L, - CONTRPS_VPAD_BUTTON_R, - CONTRPS_VPAD_BUTTON_PLUS, - CONTRPS_VPAD_BUTTON_MINUS, - CONTRPS_VPAD_BUTTON_HOME, - CONTRPS_VPAD_BUTTON_SYNC, - CONTRPS_VPAD_BUTTON_STICK_R, - CONTRPS_VPAD_BUTTON_STICK_L, - - 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 - CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX, //! min,max - CONTRPS_VPAD_BUTTON_L_STICK_Y, //! byte, default value - CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT, //! To invert: CONTROLLER_PATCHER_VALUE_SET, 0x01 - CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE, //! Deadzone - CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX, //! min,max - CONTRPS_VPAD_BUTTON_R_STICK_X, //! byte, default value - CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT, //! To invert: CONTROLLER_PATCHER_VALUE_SET, 0x01 - CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE, //! Deadzone - CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX, //! min,max - CONTRPS_VPAD_BUTTON_R_STICK_Y, //! byte, default value - CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT, //! To invert: CONTROLLER_PATCHER_VALUE_SET, 0x01 - CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE, //! Deadzone - CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX, //! min,max - - CONTRPS_VPAD_BUTTON_L_STICK_UP, - CONTRPS_VPAD_BUTTON_L_STICK_DOWN, - CONTRPS_VPAD_BUTTON_L_STICK_LEFT, - CONTRPS_VPAD_BUTTON_L_STICK_RIGHT, - CONTRPS_VPAD_BUTTON_R_STICK_UP, - CONTRPS_VPAD_BUTTON_R_STICK_DOWN, - CONTRPS_VPAD_BUTTON_R_STICK_LEFT, - CONTRPS_VPAD_BUTTON_R_STICK_RIGHT, - - CONTRPS_VPAD_BUTTON_TV, - CONTRPS_DOUBLE_USE, //!When used: e.g. CONTROLLER_PATCHER_VALUE_SET, CONTROLLER_PATCHER_GC_DOUBLE_USE - 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_CONNECTED_PADS, //! - CONTRPS_INPUT_FILTER, //! - CONTRPS_PAD1_FILTER, //! - CONTRPS_PAD2_FILTER, //! - CONTRPS_PAD3_FILTER, //! - CONTRPS_PAD4_FILTER, //! - CONTRPS_PAD5_FILTER, //! - CONTRPS_MOUSE_STICK, - CONTRPS_MAX_VALUE -}; -/** - * @brief The enumeration of different DPAD-Modes - */ -enum Controller_Patcher_DPAD_MODE -{ - CONTRPDM_Normal, /**< Normal mode */ - CONTRPDM_Hat, /**< Hat mode */ - CONTRPDM_Absolute_2Values, /**< DPAD Value stored in 2 values (one for each axis), acting like a stick */ -}; -/** - * @brief The enumeration of DPAD Settings. Needed for saving both in the PADConst. - */ -enum Controller_Patcher_DPAD_Settings -{ - CONTRDPAD_MODE = 0, /**< Byte where the DPAD Mode is stored */ - CONTRDPAD_MASK = 1, /**< Byte where the DPAD Mask is stored */ -}; - -/** - * @brief Stores data if the Slot the device is using in gHID_Devices - */ -typedef struct _HIDSlotData{ - u16 deviceslot; /**< deviceslot number */ - u32 hidmask; /**< Used HID-Mask */ -}HIDSlotData; - -/** - * @brief Stores a VID and PID - */ -typedef struct _DeviceVIDPIDInfo{ - u16 vid; /**< Vendor ID of this device */ - u16 pid; /**< Product ID of this device */ -}DeviceVIDPIDInfo; - -/** - * @brief Struct where the data for the callback funtion is stored - */ -typedef struct _my_cb_user{ - u8 *buf; /**< pointer the buffer that is used */ - u32 transfersize; /**< number of transfered data */ - u32 handle; /**< HID handle */ - HIDSlotData slotdata; /**< Information about the deviceslot and hidmask */ - u32 pads_per_device; /**< Number of maximum pads of this device */ - u8 pad_slot; /**< number of the pad that will be used */ - u8 rumblestatus[HID_MAX_PADS_COUNT]; /**< Current status of the device rumble */ - u8 forceRumbleInTicks[HID_MAX_PADS_COUNT]; - DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ -}my_cb_user; - - -typedef struct _ConnectionHelper{ - my_cb_user* usr; - u8 pad_slot; -}ConnectionHelper; - -/** - * @brief Stores data for the mouse - */ -typedef struct _HID_Mouse_Data { - u8 left_click; /**< Is 1 when the left mouse button is pressed */ - u8 right_click; /**< Is 1 when the right mouse button is pressed */ - s16 X; /**< X position of the cursor */ - s16 Y; /**< Y position of the cursor */ - s16 deltaX; /**< difference of the X value since the last call */ - s16 deltaY; /**< difference of the Y value since the last call */ - u8 valuedChanged; /**< Is 1 when the value has changed */ -} HID_Mouse_Data; - -/** - * @brief The enumeration of device types - */ -typedef enum DEVICE_TYPE_ -{ - DEVICE_TYPE_CONTROLLER = 0, /**< Normal Controller */ - DEVICE_TYPE_MOUSE = 1, /**< Mouse */ -}DEVICE_TYPE; - -/** - * @brief Stores all data of the HID Device for accessing - */ -typedef struct _HID_Data { - u32 handle; /**< The HID-handle this device is using */ - u8 rumbleActive; /**< 1 when rumble is active */ - u32 last_buttons; /**< The last pressed buttons, based on VPAD_BUTTON_XXX data */ - union{ - struct{ - u8 cur_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the current controller data is stored */ - u8 last_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the last controller data is stored */ - } controller; /**< Used when the device in a controller. Using u8 array where the raw data of the controller is placed. */ - struct{ - HID_Mouse_Data cur_mouse_data; /**< Struct where the current mouse data is stored */ - HID_Mouse_Data last_mouse_data; /**< Struct where the last mouse data is stored */ - } mouse; /**< Used when the device in a mouse. Using a new struct to store the data. */ - }data_union; /**< The data union where the current and last data is stored.*/ - DEVICE_TYPE type; /**< The device type*/ - HIDSlotData slotdata; /**< Information about the deviceslot and his mask*/ - my_cb_user * user_data; /**< Pointer to the user data the read callback is using*/ -} HID_Data; - - -/** - * @brief Struct where current hid data of one device type is stored - */ -typedef struct _HID_DEVICE_DATA { - HID_Data pad_data[HID_MAX_PADS_COUNT]; -} HID_DEVICE_DATA; - -/** - * @brief Infos of the device - */ -typedef struct _DeviceInfo{ - HIDSlotData slotdata; /**< The slot used by this device */ - DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ - u8 pad_count; /**< Number of maximum pads this device can have*/ -}DeviceInfo; - -/** - * @brief The enumeration of Controller-Mapping types - */ -typedef enum ControllerMapping_Type_Defines_{ - CM_Type_Controller = 0, /**< Device with single input */ - CM_Type_RealController = 1, /**< Real Pro Controller */ - CM_Type_Mouse = 2, /**< Mouse */ - CM_Type_Keyboard = 3, /**< Keyboard */ -} ControllerMapping_Type_Defines; - -/** - * @brief Infos of a mapped controller - */ -typedef struct _ControllerMappingPADInfo{ - u8 active; /**< Set to one if mapped */ - ControllerMapping_Type_Defines type; /**< Type of the controller mapping */ - DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */ - u8 pad; /**< Stores which pad it mapped */ -}ControllerMappingPADInfo; - -/** - * @brief Infos of a mapped controller - */ -typedef struct _ControllerMappingPAD{ - ControllerMappingPADInfo pad_infos[HID_MAX_DEVICES_PER_SLOT]; //lets limit this to HID_MAX_DEVICES_PER_SLOT. - u8 useAll; - u8 rumble; /**< Set when the controller should rumble */ -}ControllerMappingPAD; - -/** - * @brief Stores informations about all mapped controller - */ -typedef struct _ControllerMapping{ - ControllerMappingPAD gamepad; /**< Information about the gamepad mapping */ - ControllerMappingPAD proController[4]; /**< Information about the Pro Controller mapping */ -}ControllerMapping; - -/** - * @brief Pressed/Released/Down Button data. - */ -typedef struct _InputButtonData{ - u32 hold; /**< Buttons beeing hold */ - u32 trigger; /**< Buttons that started pressing */ - u32 release; /**< Buttons that were button released */ -}InputButtonData; - -typedef struct _InputStickData{ - f32 leftStickX; - f32 leftStickY; - f32 rightStickX; - f32 rightStickY; -}InputStickData; - -/** - * @brief Struct where the inputdata of a device for all HID_MAX_PADS_COUNT pads can be stored - */ -typedef struct _InputData{ - DeviceInfo device_info; /**< Infos about the device where the data is coming from */ - u8 status; - u8 pad; - InputButtonData button_data; - InputStickData stick_data; -}InputData; - -/** - * @brief The enumeration of WiiU Controller types - */ -enum UController_Type{ - UController_Type_Gamepad, - UController_Type_Pro1, - UController_Type_Pro2, - UController_Type_Pro3, - UController_Type_Pro4, -}; - -#define UController_Type_Gamepad_Name gettext("GamePad") -#define UController_Type_Pro1_Name gettext("Pro Controller 1") -#define UController_Type_Pro2_Name gettext("Pro Controller 2") -#define UController_Type_Pro3_Name gettext("Pro Controller 3") -#define UController_Type_Pro4_Name gettext("Pro Controller 4") - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * VID/PID values - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - - -#define HID_GC_VID 0x057e -#define HID_GC_PID 0x0337 - -#define HID_KEYBOARD_VID 0xAFFE -#define HID_KEYBOARD_PID 0XAAAC - -#define HID_MOUSE_VID 0xAFFE -#define HID_MOUSE_PID 0XAAAB - -#define HID_DS3_VID 0x054c -#define HID_DS3_PID 0x0268 - -#define HID_DS4_VID 0x054c -#define HID_DS4_PID 0x05c4 - -#define HID_NEW_DS4_VID 0x054c -#define HID_NEW_DS4_PID 0x09CC - -#define HID_XINPUT_VID 0x7331 -#define HID_XINPUT_PID 0x1337 - -#define HID_SWITCH_PRO_VID 0x057e -#define HID_SWITCH_PRO_PID 0x2009 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * GC Adapter - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#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 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * DS3 - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#define PS3_F4_REPORT_LEN 4 -#define PS3_F5_REPORT_LEN 8 -#define PS3_01_REPORT_LEN 48 -#define HID_REPORT_FEATURE 3 -#define HID_REPORT_OUTPUT 2 -#define PS3_F4_REPORT_ID 0xF4 -#define PS3_01_REPORT_ID 0x01 -#define PS3_F5_REPORT_ID 0xF5 - -#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_PAD_COUNT 1 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * DS4 - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#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 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * XInput - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#define HID_XINPUT_BUTTON_A_VALUE 0x01 // 7 -#define HID_XINPUT_BUTTON_B_VALUE 0x02 // 7 -#define HID_XINPUT_BUTTON_X_VALUE 0x04 // 7 -#define HID_XINPUT_BUTTON_Y_VALUE 0x08 // 7 - -#define HID_XINPUT_BUTTON_START_VALUE 0x02 // 6 -#define HID_XINPUT_BUTTON_BACK_VALUE 0x01 // 6 -#define HID_XINPUT_BUTTON_GUIDE_VALUE 0x80 // 6 - -#define HID_XINPUT_BUTTON_LB_VALUE 0x04 // 6 -#define HID_XINPUT_BUTTON_RB_VALUE 0x08 // 6 - -#define HID_XINPUT_BUTTON_L3_VALUE 0x10 // 6 -#define HID_XINPUT_BUTTON_R3_VALUE 0x20 // 6 - -#define HID_XINPUT_BUTTON_LT_VALUE 0x80 // 4 -#define HID_XINPUT_BUTTON_RT_VALUE 0x80 // 5 - -#define HID_XINPUT_BUTTON_DPAD_MASK_VALUE 0xF0 -#define HID_XINPUT_BUTTON_LEFT_VALUE 0x10 // 7 -#define HID_XINPUT_BUTTON_RIGHT_VALUE 0x40 // 7 -#define HID_XINPUT_BUTTON_DOWN_VALUE 0x80 // 7 -#define HID_XINPUT_BUTTON_UP_VALUE 0x20 // 7 - -#define HID_XINPUT_PAD_COUNT 1 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Switch Pro Controller - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#define HID_SWITCH_PRO_USB_BUTTON_A_VALUE 0x08000000 -#define HID_SWITCH_PRO_USB_BUTTON_B_VALUE 0x04000000 -#define HID_SWITCH_PRO_USB_BUTTON_X_VALUE 0x02000000 -#define HID_SWITCH_PRO_USB_BUTTON_Y_VALUE 0x01000000 -#define HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE 0x00020000 -#define HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE 0x00010000 -#define HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE 0x00100000 -#define HID_SWITCH_PRO_USB_BUTTON_SCREENSHOT_VALUE 0x00200000 -#define HID_SWITCH_PRO_USB_BUTTON_R_VALUE 0x40000000 -#define HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE 0x80000000 -#define HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE 0x00040000 -#define HID_SWITCH_PRO_USB_BUTTON_L_VALUE 0x00004000 -#define HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE 0x00008000 -#define HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE 0x00080000 - -#define HID_SWITCH_PRO_USB_BUTTON_DPAD_MASK_VALUE 0x0F -#define HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE 0x08 // 2 -#define HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE 0x04 // 2 -#define HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE 0x01 // 2 -#define HID_SWITCH_PRO_USB_BUTTON_UP_VALUE 0x02 // 2 - -#define HID_SWITCH_PRO_BT_BUTTON_A_VALUE 0x02000000 -#define HID_SWITCH_PRO_BT_BUTTON_B_VALUE 0x01000000 -#define HID_SWITCH_PRO_BT_BUTTON_X_VALUE 0x08000000 -#define HID_SWITCH_PRO_BT_BUTTON_Y_VALUE 0x04000000 -#define HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE 0x00020000 -#define HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE 0x00010000 -#define HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE 0x00100000 - -#define HID_SWITCH_PRO_BT_BUTTON_R_VALUE 0x20000000 -#define HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE 0x80000000 -#define HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE 0x00080000 - -#define HID_SWITCH_PRO_BT_BUTTON_L_VALUE 0x10000000 -#define HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE 0x40000000 -#define HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE 0x00040000 - - -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_MASK_VALUE 0x0F -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE 0x00 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE 0x01 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE 0x02 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE 0x03 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE 0x04 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE 0x05 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE 0x06 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE 0x07 // 2 -#define HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE 0x08 // 2 - - -#define HID_SWITCH_PRO_BT_PAD_COUNT 1 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Keyboard (Full list is on: http://www.freebsddiary.org/APC/usb_hid_usages.php) - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#define HID_KEYBOARD_BUTTON_SHIFT 0x02 - -#define HID_KEYBOARD_BUTTON_A 0x04 -#define HID_KEYBOARD_BUTTON_B 0x05 -#define HID_KEYBOARD_BUTTON_C 0x06 -#define HID_KEYBOARD_BUTTON_D 0x07 -#define HID_KEYBOARD_BUTTON_E 0x08 -#define HID_KEYBOARD_BUTTON_F 0x09 -#define HID_KEYBOARD_BUTTON_G 0x0A -#define HID_KEYBOARD_BUTTON_H 0x0B -#define HID_KEYBOARD_BUTTON_I 0x0C -#define HID_KEYBOARD_BUTTON_J 0x0D -#define HID_KEYBOARD_BUTTON_K 0x0E -#define HID_KEYBOARD_BUTTON_L 0x0F -#define HID_KEYBOARD_BUTTON_M 0x10 -#define HID_KEYBOARD_BUTTON_N 0x11 -#define HID_KEYBOARD_BUTTON_O 0x12 -#define HID_KEYBOARD_BUTTON_P 0x13 -#define HID_KEYBOARD_BUTTON_Q 0x14 -#define HID_KEYBOARD_BUTTON_R 0x15 -#define HID_KEYBOARD_BUTTON_S 0x16 -#define HID_KEYBOARD_BUTTON_T 0x17 -#define HID_KEYBOARD_BUTTON_U 0x18 -#define HID_KEYBOARD_BUTTON_V 0x19 -#define HID_KEYBOARD_BUTTON_W 0x1A -#define HID_KEYBOARD_BUTTON_X 0x1B -#define HID_KEYBOARD_BUTTON_Y 0x1C -#define HID_KEYBOARD_BUTTON_Z 0x1D -#define HID_KEYBOARD_BUTTON_F1 0x3A -#define HID_KEYBOARD_BUTTON_F2 0x3B -#define HID_KEYBOARD_BUTTON_F3 0x3C -#define HID_KEYBOARD_BUTTON_F4 0x3D -#define HID_KEYBOARD_BUTTON_F5 0x3E -#define HID_KEYBOARD_BUTTON_F6 0x3F -#define HID_KEYBOARD_BUTTON_F7 0x40 -#define HID_KEYBOARD_BUTTON_F8 0x41 -#define HID_KEYBOARD_BUTTON_F9 0x42 -#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_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 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Mouse - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -#define HID_MOUSE_BUTTON_LEFTCLICK 0x04 -#define HID_MOUSE_BUTTON_RIGHTCLICK 0x05 - -#define HID_MOUSE_PAD_COUNT 1 - -#define HID_MOUSE_MODE_AIM 0x01 -#define HID_MOUSE_MODE_TOUCH 0x02 - -#endif /* _CONTROLLER_PATCHER_DEFS_H_ */ diff --git a/wiiu/controller_patcher/patcher/ControllerPatcherHID.cpp b/wiiu/controller_patcher/patcher/ControllerPatcherHID.cpp deleted file mode 100644 index 21664262a1..0000000000 --- a/wiiu/controller_patcher/patcher/ControllerPatcherHID.cpp +++ /dev/null @@ -1,713 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "ControllerPatcherHID.hpp" - -#include -#include -#include - -#include "wiiu/os.h" - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * public implementation for the network controller - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -s32 ControllerPatcherHID::externAttachDetachCallback(HIDDevice *p_device, u32 attach){ - HIDClient client; - memset(&client,0,sizeof(client)); - return AttachDetachCallback(&client,p_device,attach); -} - -void ControllerPatcherHID::externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){ - HIDReadCallback(handle,buf,bytes_transfered,usr); -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * private implementation for the HID Api. - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -s32 ControllerPatcherHID::myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach){ - return AttachDetachCallback(p_client,p_device,attach); -} - -void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){ - if(error == 0){ - my_cb_user *usr = (my_cb_user*)p_user; - - u32 slot = 0; - if(usr->pad_slot < HID_MAX_PADS_COUNT){ - slot = usr->pad_slot; - } - - HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); - HID_Mouse_Data * cur_mouse_data = &data_ptr->data_union.mouse.cur_mouse_data; - - data_ptr->type = DEVICE_TYPE_MOUSE; - //printf("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered); - - if(buf[0] == 2 && bytes_transfered > 3){ // using the other mouse mode - buf +=1; - } - - s8 x_value = 0; - s8 y_value = 0; - - x_value = buf[1]; - y_value = buf[2]; - - cur_mouse_data->X += x_value; - cur_mouse_data->deltaX = x_value; - - cur_mouse_data->Y += y_value; - cur_mouse_data->deltaY = y_value; - - cur_mouse_data->left_click = buf[0]; - cur_mouse_data->right_click = buf[0]>>1; - - if(cur_mouse_data->X < 0) cur_mouse_data->X = 0; - if(cur_mouse_data->X > 1280) cur_mouse_data->X = 1280; - - if(cur_mouse_data->Y < 0) cur_mouse_data->Y = 0; - if(cur_mouse_data->Y > 720) cur_mouse_data->Y = 720; - - cur_mouse_data->valuedChanged = 1; - - //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); - - HIDRead(handle, usr->buf, bytes_transfered, myHIDMouseReadCallback, usr); - } -} - -void ControllerPatcherHID::myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user){ - if(error == 0 && p_user != NULL && gHIDAttached){ - my_cb_user *usr = (my_cb_user*)p_user; - - HIDReadCallback(handle,buf,bytes_transfered,usr); - - if(usr->slotdata.hidmask == gHID_LIST_DS4){ - wiiu_os_usleep(1000*2); //DS4 is way tooo fast. sleeping to reduce lag. (need to check the other pads) - } - HIDRead(handle, usr->buf, bytes_transfered, myHIDReadCallback, usr); - } -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Intern Callback actions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach){ - if(attach){ - printf("ControllerPatcherHID::AttachDetachCallback(line %d): vid %04x pid %04x connected\n",__LINE__, SWAP16(p_device->vid),SWAP16(p_device->pid)); - if(HID_DEBUG){ printf("interface index %02x\n", p_device->interface_index); - printf("sub class %02x\n", p_device->sub_class); - printf("protocol %02x\n", p_device->protocol); - printf("max packet in %02x\n", p_device->max_packet_size_rx); - printf("max packet out %02x\n", p_device->max_packet_size_tx); } - } - if(!attach){ - printf("ControllerPatcherHID::AttachDetachCallback(line %d): vid %04x pid %04x disconnected\n",__LINE__, SWAP16(p_device->vid),SWAP16(p_device->pid)); - } - DeviceInfo device_info; - memset(&device_info,0,sizeof(DeviceInfo)); - device_info.slotdata.deviceslot = -1; - device_info.vidpid.vid = SWAP16(p_device->vid); - device_info.vidpid.pid = SWAP16(p_device->pid); - - HIDSlotData * slotdata = &(device_info.slotdata); - - if ((p_device->sub_class == 1) && (p_device->protocol == 1)) { //Keyboard - slotdata->hidmask = gHID_LIST_KEYBOARD; - slotdata->deviceslot = gHID_SLOT_KEYBOARD; - //printf("Found Keyboard: device: %s slot: %d\n",byte_to_binary(device_info.slotdata.hidmask),device_info.slotdata.deviceslot); - }else if ((p_device->sub_class == 1) && (p_device->protocol == 2)){ // MOUSE - slotdata->hidmask = gHID_LIST_MOUSE; - slotdata->deviceslot = gMouseSlot; - //printf("Found Mouse: device: %s slot: %d\n",byte_to_binary(device_info.hid),device_info.slot); - }else{ - s32 ret; - if((ret = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) < 0){ - printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) failed %d \n",__LINE__,ret); - return HID_DEVICE_DETACH; - }else{ - //printf("ControllerPatcherHID::AttachDetachCallback(line %d): ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) success %d \n",__LINE__,ret); - } - } - - if(slotdata->hidmask){ - if(attach){ - s32 bufSize = 64; - if(slotdata->hidmask != gHID_LIST_MOUSE && config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][0] == CONTROLLER_PATCHER_VALUE_SET){ - bufSize = config_controller[slotdata->deviceslot][CONTRPS_BUF_SIZE][1]; - } - unsigned char *buf = (unsigned char *) memalign(64,bufSize); - memset(buf,0,bufSize); - my_cb_user *usr = (my_cb_user *) memalign(64,sizeof(my_cb_user)); - usr->buf = buf; - usr->slotdata = device_info.slotdata; - usr->transfersize = p_device->max_packet_size_rx; - usr->handle = p_device->handle; - usr->vidpid = device_info.vidpid; - gHIDAttached |= slotdata->hidmask; - gHIDCurrentDevice |= slotdata->hidmask; - s32 pads_per_device = 1; - if(config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - pads_per_device = config_controller[slotdata->deviceslot][CONTRPS_PAD_COUNT][1]; - if(pads_per_device > HID_MAX_PADS_COUNT){//maximum of HID_MAX_PADS_COUNT - pads_per_device = HID_MAX_PADS_COUNT; - } - } - - s32 pad_count = config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1]; - if(pad_count > 0x0F) pad_count = 0; //??? - - s32 pad_slot = 0; - - s32 failed = 1; - - for(s32 i = 0;ideviceslot][CONTRPS_CONNECTED_PADS][1] = pad_count; - - DCFlushRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); - DCInvalidateRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); - - usr->pads_per_device = pads_per_device; - usr->pad_slot = pad_slot; - - for(s32 i = 0;ideviceslot].pad_data[pad_slot+i],0,sizeof(HID_Data)); - - gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].handle = p_device->handle; - //printf("ControllerPatcherHID::AttachDetachCallback(line %d): saved handle %d to slot %d and pad %d\n",__LINE__,p_device->handle,slotdata->deviceslot,pad_slot); - - gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].user_data = usr; - gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i].slotdata = device_info.slotdata; - - DCFlushRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data)); - DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[pad_slot+i],sizeof(HID_Data)); - } - - for(s32 j = 0;j < pads_per_device; j++){ - for(s32 i = 0;i < gHIDMaxDevices; i++){ - if(connectionOrderHelper[i].usr == NULL){ - connectionOrderHelper[i].usr = usr; - connectionOrderHelper[i].pad_slot = pad_slot+j; - break; - } - } - } - DCFlushRange(connectionOrderHelper,sizeof(connectionOrderHelper)); - DCInvalidateRange(connectionOrderHelper,sizeof(connectionOrderHelper)); - - if(HID_DEBUG){ printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully attached\n",__LINE__); } - - if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD - //The GC Adapter has all ports in one device. Set them all. - gHID_Devices[slotdata->deviceslot].pad_data[0].slotdata = device_info.slotdata; - gHID_Devices[slotdata->deviceslot].pad_data[1].slotdata = device_info.slotdata; - gHID_Devices[slotdata->deviceslot].pad_data[2].slotdata = device_info.slotdata; - gHID_Devices[slotdata->deviceslot].pad_data[3].slotdata = device_info.slotdata; - - buf[0] = 0x13; - HIDWrite(p_device->handle, usr->buf, 1, NULL,NULL); - HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_MOUSE){ - 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_AIM; - HIDRead(p_device->handle, buf, p_device->max_packet_size_rx, myHIDMouseReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_SWITCH_PRO){ - s32 read_result = HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); - if(read_result == 64){ - if(usr->buf[01] == 0x01){ //We need to do the handshake - printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake needed\n",__LINE__); - /** - Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering) - **/ - //Get MAC - buf[0] = 0x80; - buf[1] = 0x01; - HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); - HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); - //Do handshake - buf[0] = 0x80; - buf[1] = 0x02; - HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); - HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); - //Talk over HID only. - buf[0] = 0x80; - buf[1] = 0x04; - HIDWrite(p_device->handle, usr->buf, 2, NULL,NULL); - HIDRead(p_device->handle, usr->buf, usr->transfersize, NULL, NULL); - }else{ - printf("ControllerPatcherHID::AttachDetachCallback(line %d): Switch Pro Controller handshake already done\n",__LINE__); - } - HIDRead(p_device->handle, usr->buf, usr->transfersize, myHIDReadCallback, usr); - } - }else if (slotdata->hidmask == gHID_LIST_KEYBOARD){ - HIDSetProtocol(p_device->handle, p_device->interface_index, 1, 0, 0); - HIDSetIdle(p_device->handle, p_device->interface_index, 0, 0, 0); - HIDRead(p_device->handle, buf, p_device->max_packet_size_rx, myHIDReadCallback, usr); - }else if (slotdata->hidmask == gHID_LIST_DS3){ - HIDSetProtocol(p_device->handle, p_device->interface_index, 1, 0, 0); - HIDDS3Rumble(p_device->handle,usr,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); - HIDRead(p_device->handle, usr->buf, p_device->max_packet_size_rx, myHIDReadCallback, usr); - }else{ - HIDRead(p_device->handle, usr->buf, p_device->max_packet_size_rx, myHIDReadCallback, usr); - } - return HID_DEVICE_ATTACH; - - }else{ - my_cb_user * user_data = NULL; - s32 founddata = 0; - for(s32 i = 0;ideviceslot].pad_data[i].handle == p_device->handle){ - gHID_Devices[slotdata->deviceslot].pad_data[i].handle = 0; - - DCFlushRange(&gHID_Devices[slotdata->deviceslot].pad_data[i].handle,sizeof(gHID_Devices[slotdata->deviceslot].pad_data[i].handle)); - DCInvalidateRange(&gHID_Devices[slotdata->deviceslot].pad_data[i].handle,sizeof(gHID_Devices[slotdata->deviceslot].pad_data[i].handle)); - - user_data = (my_cb_user *) gHID_Devices[slotdata->deviceslot].pad_data[i].user_data; - - founddata = 1; - break; - } - } - - if(user_data){ - for(s32 j = 0;j < user_data->pads_per_device; j++){ - for(s32 i = 0;i < gHIDMaxDevices; i++){ - if(connectionOrderHelper[i].usr == user_data){ - connectionOrderHelper[i].usr = NULL; - connectionOrderHelper[i].pad_slot = 0; - break; - } - } - } - DCFlushRange(connectionOrderHelper,sizeof(connectionOrderHelper)); - DCInvalidateRange(connectionOrderHelper,sizeof(connectionOrderHelper)); - - config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] &= ~ (1 << user_data->pad_slot); - DCFlushRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); - DCInvalidateRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1])); - if(user_data->buf){ - free(user_data->buf); - user_data->buf = NULL; - } - free(user_data); - user_data = NULL; - }else{ - if(founddata){ printf("ControllerPatcherHID::AttachDetachCallback(line %d): user_data null. You may have a memory leak.\n",__LINE__); } - return HID_DEVICE_DETACH; - } - if(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] == 0){ - gHIDAttached &= ~slotdata->hidmask; - gHIDCurrentDevice &= ~slotdata->hidmask; - - DCFlushRange(&gHIDAttached,sizeof(gHIDAttached)); - DCInvalidateRange(&gHIDAttached,sizeof(gHIDAttached)); - DCFlushRange(&gHIDCurrentDevice,sizeof(gHIDCurrentDevice)); - DCInvalidateRange(&gHIDCurrentDevice,sizeof(gHIDCurrentDevice)); - - if (slotdata->hidmask == gHID_LIST_MOUSE){ - gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; - } - }else{ - if(HID_DEBUG){printf("ControllerPatcherHID::AttachDetachCallback(line %d): We still have pad for deviceslot %d connected.\n",__LINE__,slotdata->deviceslot); } - } - if(HID_DEBUG){printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully detached\n",__LINE__); } - } - }else{ - printf("ControllerPatcherHID::AttachDetachCallback(line %d): HID-Device currently not supported! You can add support through config files\n",__LINE__); - } - return HID_DEVICE_DETACH; -} - -void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr){ - ControllerPatcherUtils::doSampling(usr->slotdata.deviceslot,usr->pad_slot,false); - - //printf("my_read_cbInternal: %d %08X %d\n",bytes_transfered,usr->slotdata.hidmask,usr->slotdata.deviceslot); - if(usr->slotdata.hidmask == gHID_LIST_GC){ - - HID_Data * data_ptr = NULL; - //Copy the data for all 4 pads - for(s32 i = 0;i<4;i++){ - data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]); - memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data. - memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data. - - } - - /* - s32 i = 0; - printf("GC1 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - printf("GC2 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - printf("GC3 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++; - printf("GC4 %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X \n", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);*/ - HIDGCRumble(handle,usr); - }else if(usr->slotdata.hidmask != 0){ - //Depending on how the switch pro controller is connected, it has a different data format. At first we had the Bluetooth version, so we need to convert - //the USB one into it now. (When it's connected via USB). The network client always sends the BT version, even if connected via USB to the PC. - if(usr->slotdata.hidmask == gHID_LIST_SWITCH_PRO && buf != NULL && bytes_transfered >= 0x20){ - u8 buffer[0x13]; - memcpy(buffer,buf+0x0D,0x013); - - /** - Thanks to ShinyQuagsire23 for the values (https://github.com/shinyquagsire23/HID-Joy-Con-Whispering) - **/ - buf[0] = 0x80; - buf[1] = 0x92; - buf[2] = 0x00; - buf[3] = 0x01; - buf[4] = 0x00; - buf[5] = 0x00; - buf[6] = 0x00; - buf[7] = 0x00; - buf[8] = 0x1F; - //We want to get the next input! - s32 res = HIDWrite(handle, buf, 9, NULL,NULL); - - if(res == 9){ //Check if it's the USB data format. - if(buffer[1] == 0) return; - //Converting the buttons - u32 buttons = (((u32*)(buffer))[0]) & 0xFFFFFF00; - u32 newButtons = 0; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_A_VALUE) == HID_SWITCH_PRO_USB_BUTTON_A_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_A_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_B_VALUE) == HID_SWITCH_PRO_USB_BUTTON_B_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_B_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_X_VALUE) == HID_SWITCH_PRO_USB_BUTTON_X_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_X_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_Y_VALUE) == HID_SWITCH_PRO_USB_BUTTON_Y_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_Y_VALUE; - - if((buttons & HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE) == HID_SWITCH_PRO_USB_BUTTON_PLUS_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE) == HID_SWITCH_PRO_USB_BUTTON_MINUS_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE) == HID_SWITCH_PRO_USB_BUTTON_HOME_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE; - //if((buttons & SWITCH_PRO_USB_BUTTON_SCREENSHOT) == HID_SWITCH_PRO_USB_BUTTON_SCREENSHOT) newButtons |= HID_SWITCH_PRO_BT_BUTTON_SCREENSHOT; - - if((buttons & HID_SWITCH_PRO_USB_BUTTON_R_VALUE) == HID_SWITCH_PRO_USB_BUTTON_R_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_R_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE) == HID_SWITCH_PRO_USB_BUTTON_ZR_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE) == HID_SWITCH_PRO_USB_BUTTON_STICK_R_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE; - - if((buttons & HID_SWITCH_PRO_USB_BUTTON_L_VALUE) == HID_SWITCH_PRO_USB_BUTTON_L_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_L_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE) == HID_SWITCH_PRO_USB_BUTTON_ZL_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE; - if((buttons & HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE) == HID_SWITCH_PRO_USB_BUTTON_STICK_L_VALUE) newButtons |= HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE; - - u8 dpad = buffer[2]; - u8 dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE; - - //Converting the DPAD - if(((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) && - ((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE)){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE; - }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) && - ((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE)){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE; - }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) && - ((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE)){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE; - }else if(((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) && - ((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE)){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE; - }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_UP_VALUE) == HID_SWITCH_PRO_USB_BUTTON_UP_VALUE){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE; - }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_RIGHT_VALUE){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE; - }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE) == HID_SWITCH_PRO_USB_BUTTON_DOWN_VALUE){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE; - }else if((dpad & HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE) == HID_SWITCH_PRO_USB_BUTTON_LEFT_VALUE){ - dpadResult = HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE; - } - - //Converting the stick data - u8 LX = (u8) ((u16) ((buffer[0x04] << 8 &0xFF00) | (((u16)buffer[0x03])&0xFF)) >> 0x04); - u8 LY = (u8)((buffer[0x05] *-1)); - u8 RX = (u8) ((u16) ((buffer[0x07] << 8 &0xFF00) | (((u16)buffer[0x06])&0xFF)) >> 0x04); - u8 RY = (u8)((buffer[0x08] *-1)); - - buf[0] = (newButtons >> 24) & 0xFF; - buf[1] = (newButtons >> 16) & 0xFF; - buf[2] |= dpadResult; - buf[4] = LX; - buf[6] = LY; - buf[8] = RX; - buf[10] = RY; - } - } - - s32 dsize = (HID_MAX_DATA_LENGTH_PER_PAD > bytes_transfered)? bytes_transfered : HID_MAX_DATA_LENGTH_PER_PAD; - s32 skip = 0; - - //Input filter - if( config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(buf[config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][0]] != config_controller[usr->slotdata.deviceslot][CONTRPS_INPUT_FILTER][1]){ - skip = 1; - } - } - - if(!skip){ - u32 slot = 0; - if(usr->pad_slot < HID_MAX_PADS_COUNT){ - slot = usr->pad_slot; - } - slot += ControllerPatcherUtils::getPadSlotInAdapter(usr->slotdata.deviceslot,buf); // If the controller has multiple slots, we need to use the right one. - - HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); - - memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),dsize); // save the last data. - memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[0],dsize); // save the new data. - - DCFlushRange(&gHID_Devices[usr->slotdata.deviceslot].pad_data[slot],sizeof(HID_Data)); - - data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]); - - HIDRumble(handle,usr,slot); - } - } -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Other functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(VPADStatus * buffer,std::vector& data){ - if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - HID_Data * data_cur; - - s32 buttons_hold; - for(u32 i = 0;islotdata.hidmask & gHID_LIST_MOUSE){ //Reset the input when we have no new inputs - HID_Mouse_Data * mouse_data = &data_cur->data_union.mouse.cur_mouse_data; - if(mouse_data->valuedChanged == 1){ //Fix for the mouse cursor - mouse_data->valuedChanged = 0; - }else{ - mouse_data->deltaX = 0; - mouse_data->deltaY = 0; - } - } - - buttons_hold = 0; - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_A); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_B); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_X); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_Y); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_LEFT); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_RIGHT); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_DOWN); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_UP); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_MINUS); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_L); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_R); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_PLUS); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_ZL); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_ZR); - - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_HOME); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_L); - ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_STICK_R); - - u32 last_emulate_stick = (data_cur->last_buttons) & VPAD_MASK_EMULATED_STICKS; // We should only need the emulated stick data. - s32 last_realbuttons = (data_cur->last_buttons) & VPAD_MASK_BUTTONS; - - buffer->hold |= buttons_hold; - buffer->trigger |= (buttons_hold & (~last_realbuttons)); - buffer->release |= (last_realbuttons & (~buttons_hold)); - - ControllerPatcherUtils::convertAnalogSticks(data_cur,buffer); - - ControllerPatcherUtils::setEmulatedSticks(buffer,&last_emulate_stick); - - ControllerPatcherUtils::checkAndSetMouseMode(data_cur); - - ControllerPatcherUtils::setTouch(data_cur,buffer); - - data_cur->last_buttons = buttons_hold & VPAD_MASK_BUTTONS; - data_cur->last_buttons |= last_emulate_stick; - } - - // Caculates a valid stick position - if(data.size() > 0){ - ControllerPatcherUtils::normalizeStickValues(&buffer->leftStick); - ControllerPatcherUtils::normalizeStickValues(&buffer->rightStick); - } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -std::vector ControllerPatcherHID::getHIDDataAll(){ - u32 hid = gHIDCurrentDevice; - - std::vector data_list; - for(s32 i = 0;i < gHIDMaxDevices;i++){ - if((hid & (1 << i)) != 0){ - u32 cur_hidmask = config_controller_hidmask[i]; - for(s32 pad = 0; pad < HID_MAX_PADS_COUNT; pad++){ - s32 res; - HID_Data * new_data = NULL; - if((res = ControllerPatcherHID::getHIDData(cur_hidmask,pad,&new_data)) < 0){ // Checks if the pad is invalid. - //printf("ControllerPatcherHID::getHIDDataAll(line %d): error: Error getting the HID data from HID(%s) CHAN(). Error %d\n",__LINE__,CPStringTools::byte_to_binary(cur_hidmask),pad,res); - continue; - } - if(new_data != NULL) data_list.push_back(new_data); - } - } - } - return data_list; -} - -/* -The slotdata in the HID_Data pointer is empty. We need to provide the hidmask via the parameter -*/ -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::getHIDData(u32 hidmask, s32 pad, HID_Data ** data){ - if(data == NULL) return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER; - if(!(hidmask & gHIDCurrentDevice)) return CONTROLLER_PATCHER_ERROR_HID_NOT_CONNECTED; - if(pad < 0 && pad > 3) return CONTROLLER_PATCHER_ERROR_INVALID_CHAN; - - s32 device_slot = ControllerPatcherUtils::getDeviceSlot(hidmask); - if(device_slot < 0){ - return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; - } - - s32 real_pad = pad; - if((device_slot != gHID_SLOT_GC) && config_controller[device_slot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - s32 pad_count = config_controller[device_slot][CONTRPS_PAD_COUNT][1]; - if(pad_count > HID_MAX_PADS_COUNT) pad_count = HID_MAX_PADS_COUNT; - pad = (pad/(pad_count))*pad_count; - } - - s32 result = ControllerPatcherUtils::checkActivePad(hidmask,pad); - - if(result < 0){ //Not pad connected to adapter - return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; - } - - *data = &gHID_Devices[device_slot].pad_data[real_pad]; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - - -void ControllerPatcherHID::HIDGCRumble(u32 handle,my_cb_user *usr){ - if(usr == NULL) return; - if(!ControllerPatcher::isRumbleActivated()) return; - - s32 rumblechanged = 0; - - for(s32 i = 0;islotdata.deviceslot].pad_data[i]); - if(data_ptr->rumbleActive != usr->rumblestatus[i]){ - rumblechanged = 1; - } - usr->rumblestatus[i] = data_ptr->rumbleActive; - usr->buf[i+1] = usr->rumblestatus[i]; - } - usr->forceRumbleInTicks[0]--; - if(rumblechanged || usr->forceRumbleInTicks[0] <= 0){ - usr->buf[0] = 0x11; - HIDWrite(handle, usr->buf, 5, NULL, NULL); - usr->forceRumbleInTicks[0] = 10; - } -} - -void ControllerPatcherHID::HIDRumble(u32 handle,my_cb_user *usr,u32 pad){ - if(usr == NULL || pad > HID_MAX_PADS_COUNT) return; - if(!ControllerPatcher::isRumbleActivated()) return; - - s32 rumblechanged = 0; - HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[pad]); - if(data_ptr->rumbleActive != usr->rumblestatus[pad]){ - usr->rumblestatus[pad] = data_ptr->rumbleActive; - rumblechanged = 1; - } - usr->forceRumbleInTicks[pad]--; - if(rumblechanged || usr->forceRumbleInTicks[pad] <= 0){ - //printf("Rumble: %d %d\n",usr->rumblestatus[pad],usr->rumbleForce[pad]); - //Seding to the network client! - char bytes[6]; - - s32 i = 0; - bytes[i++] = 0x01; - bytes[i++] = (handle >> 24) & 0xFF; - bytes[i++] = (handle >> 16) & 0xFF; - bytes[i++] = (handle >> 8) & 0xFF; - bytes[i++] = handle & 0xFF; - bytes[i++] = usr->rumblestatus[pad]; - - UDPClient * instance = UDPClient::getInstance(); - if(instance != NULL){ - instance->sendData(bytes,6); - } - - - if(usr->slotdata.hidmask == gHID_LIST_DS3){ - HIDDS3Rumble(handle,usr,usr->rumblestatus[pad]); - }else{ - // Not implemented for other devices =( - } - usr->forceRumbleInTicks[pad] = 10; - } -} - -static u8 ds3_rumble_Report[48] = -{ - 0x00, 0xFF, 0x00, 0xFF, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0x27, 0x10, 0x00, 0x32, - 0xFF, 0x27, 0x10, 0x00, 0x32, - 0xFF, 0x27, 0x10, 0x00, 0x32, - 0xFF, 0x27, 0x10, 0x00, 0x32, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, -}; - -void ControllerPatcherHID::HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble){ - memcpy(usr->buf, ds3_rumble_Report, 48); - - if (rumble) { - usr->buf[2] = 0x01; - usr->buf[4] = 0xff; - } - - HIDSetReport(handle, HID_REPORT_OUTPUT, PS3_01_REPORT_ID, usr->buf, 48, NULL, NULL); -} diff --git a/wiiu/controller_patcher/patcher/ControllerPatcherHID.hpp b/wiiu/controller_patcher/patcher/ControllerPatcherHID.hpp deleted file mode 100644 index 21ade01652..0000000000 --- a/wiiu/controller_patcher/patcher/ControllerPatcherHID.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 . - ****************************************************************************/ - -/** - * @file ControllerPatcherHID.hpp - * @author Maschell - * @date 25 Aug 2016 - * \brief This files contain useful all function for the direct HID Access - * - * @see https://github.com/Maschell/controller_patcher - */ - -#ifndef _CONTROLLER_PATCHER_HID_H_ -#define _CONTROLLER_PATCHER_HID_H_ - -#include - -#include "wiiu/syshid.h" -#include "wiiu/vpad.h" - -#include "../ControllerPatcher.hpp" - -#define SWAP16(x) ((x>>8) | ((x&0xFF)<<8)) -#define SWAP8(x) ((x>>4) | ((x&0xF)<<4)) - -class ControllerPatcherHID{ - friend class ControllerPatcher; - friend class ControllerPatcherUtils; - public: - static s32 externAttachDetachCallback(HIDDevice *p_device, u32 attach); - static void externHIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); - - private: - static CONTROLLER_PATCHER_RESULT_OR_ERROR setVPADControllerData(VPADStatus * buffer,std::vector& data); - static std::vector getHIDDataAll(); - static CONTROLLER_PATCHER_RESULT_OR_ERROR getHIDData(u32 hidmask, s32 pad, HID_Data ** data); - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Rumble - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - - static void HIDRumble(u32 handle,my_cb_user *usr,u32 pad); - - static void HIDGCRumble(u32 handle,my_cb_user *usr); - - static void HIDDS3Rumble(u32 handle,my_cb_user *usr,s32 rumble); - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * HID Callbacks - *--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - static s32 myAttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach); - - static void myHIDMouseReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); - static void myHIDReadCallback(u32 handle, s32 error, unsigned char *buf, u32 bytes_transfered, void *p_user); - - static s32 AttachDetachCallback(HIDClient *p_client, HIDDevice *p_device, u32 attach); - static void HIDReadCallback(u32 handle, unsigned char *buf, u32 bytes_transfered, my_cb_user * usr); -}; - -#endif /* _CONTROLLER_PATCHER_HID_H_ */ diff --git a/wiiu/controller_patcher/patcher/ControllerPatcherUtils.cpp b/wiiu/controller_patcher/patcher/ControllerPatcherUtils.cpp deleted file mode 100644 index e4b66f5a79..0000000000 --- a/wiiu/controller_patcher/patcher/ControllerPatcherUtils.cpp +++ /dev/null @@ -1,935 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "ControllerPatcherUtils.hpp" -#include -#include - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDataByHandle(s32 handle, my_cb_user ** data){ - for(s32 i = 0;i< gHIDMaxDevices;i++){ - for(s32 j = 0;j<4;j++){ - //printf("%d %d %d %d\n",i,j,gHID_Devices[i].pad_data[j].handle,(u32)handle); - if(gHID_Devices[i].pad_data[j].handle == (u32)handle){ - *data = gHID_Devices[i].pad_data[j].user_data; - return CONTROLLER_PATCHER_ERROR_NONE; - } - } - } - return CONTROLLER_PATCHER_ERROR_UNKNOWN; -} -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Analyse inputs - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton){ - if(data == NULL || buttons_hold == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 deviceslot = data->slotdata.deviceslot; - - s32 result = -1; - - do{ - if(data->type == DEVICE_TYPE_MOUSE){ - HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; - if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ - if(VPADButton == VPAD_BUTTON_TOUCH){ - if(ms_data->left_click & 0x01){ - result = 1; break; - } - } - }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_LEFT][1]]){ - if(ms_data->left_click & 0x01){ - result = 1; break; - } - } - } - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(VPADButton == (int)gGamePadValues[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_RIGHT][1]]){ - if(ms_data->right_click & 0x01){ - result = 1; break; - } - } - } - } - result = 0; break; - } - u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; - if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 cur_config = 0; - - if(VPADButton == VPAD_BUTTON_A){ - cur_config = CONTRPS_VPAD_BUTTON_A; - }else if(VPADButton == VPAD_BUTTON_B){ - cur_config = CONTRPS_VPAD_BUTTON_B; - }else if(VPADButton == VPAD_BUTTON_X){ - cur_config = CONTRPS_VPAD_BUTTON_X; - }else if(VPADButton == VPAD_BUTTON_Y){ - cur_config = CONTRPS_VPAD_BUTTON_Y; - }else if(VPADButton == VPAD_BUTTON_L){ - cur_config = CONTRPS_VPAD_BUTTON_L; - }else if(VPADButton == VPAD_BUTTON_R){ - cur_config = CONTRPS_VPAD_BUTTON_R; - }else if(VPADButton == VPAD_BUTTON_ZL){ - cur_config = CONTRPS_VPAD_BUTTON_ZL; - }else if(VPADButton == VPAD_BUTTON_ZR){ - cur_config = CONTRPS_VPAD_BUTTON_ZR; - }else if(VPADButton == VPAD_BUTTON_STICK_L){ - cur_config = CONTRPS_VPAD_BUTTON_STICK_L; - }else if(VPADButton == VPAD_BUTTON_STICK_R){ - cur_config = CONTRPS_VPAD_BUTTON_STICK_R; - }else if(VPADButton == VPAD_BUTTON_PLUS){ - cur_config = CONTRPS_VPAD_BUTTON_PLUS; - }else if(VPADButton == VPAD_BUTTON_MINUS){ - cur_config = CONTRPS_VPAD_BUTTON_MINUS; - }else if(VPADButton == VPAD_BUTTON_HOME){ - cur_config = CONTRPS_VPAD_BUTTON_HOME; - } - - //! Special DPAD treatment. - if(config_controller[deviceslot][CONTRPS_DPAD_MODE][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Hat){ - u8 mask = 0x0F; - if(config_controller[deviceslot][CONTRPS_DPAD_MASK][0] == CONTROLLER_PATCHER_VALUE_SET){ - mask = config_controller[deviceslot][CONTRPS_DPAD_MASK][1]; - } - if(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][0]] != config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NEUTRAL][1]){ // Not neutral - u8 dir1_0 = 0,dir1_1 = 0; - u8 dir2_0 = 0,dir2_1 = 0; - u8 dir3_0 = 0,dir3_1 = 0; - u8 direction = 0; - if(VPADButton == VPAD_BUTTON_LEFT){ - dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_W][0]; - dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][0]; - dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][0]; - dir1_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_W][1]; - dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][1]; - dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][1]; - direction = 1; - }else if(VPADButton == VPAD_BUTTON_RIGHT){ - dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_E][0]; - dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][0]; - dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][0]; - dir1_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_E][1]; - dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][1]; - dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][1]; - direction = 1; - }else if(VPADButton == VPAD_BUTTON_DOWN){ - dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_S][0]; - dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][0]; - dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][0]; - dir1_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_S][1]; - dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SE][1]; - dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_SW][1]; - direction = 1; - }else if(VPADButton == VPAD_BUTTON_UP){ - dir1_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_N][0]; - dir2_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][0]; - dir3_0 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][0]; - dir1_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_N][1]; - dir2_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NW][1]; - dir3_1 = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_DPAD_NE][1]; - direction = 1; - } - if(direction && (((cur_data[dir1_0] & mask) == dir1_1) || - ((cur_data[dir2_0] & mask) == dir2_1) || - ((cur_data[dir3_0] & mask) == dir3_1))) {result = 1; break;} - } - - }else if(config_controller[deviceslot][CONTRPS_DPAD_MODE][1] == CONTRPDM_Absolute_2Values){ - s32 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){ - s32 value_byte = CONTROLLER_PATCHER_INVALIDVALUE; - if((value_byte = config_controller[deviceslot][contrps_value][0]) != CONTROLLER_PATCHER_INVALIDVALUE){ - if(cur_data[config_controller[deviceslot][contrps_value][0]] == config_controller[deviceslot][contrps_value][1]){ - result = 1; - break; - } - } - } - } - } - - //! Normal DPAD treatment. - if(VPADButton == VPAD_BUTTON_LEFT){ - cur_config = CONTRPS_VPAD_BUTTON_LEFT; - }else if(VPADButton == VPAD_BUTTON_RIGHT){ - cur_config = CONTRPS_VPAD_BUTTON_RIGHT; - }else if(VPADButton == VPAD_BUTTON_DOWN){ - cur_config = CONTRPS_VPAD_BUTTON_DOWN; - }else if(VPADButton == VPAD_BUTTON_UP){ - cur_config = CONTRPS_VPAD_BUTTON_UP; - } - if(result && config_controller[deviceslot][CONTRPS_DOUBLE_USE][0] == CONTROLLER_PATCHER_VALUE_SET){ - if(config_controller[deviceslot][CONTRPS_DOUBLE_USE][1] == CONTROLLER_PATCHER_GC_DOUBLE_USE){ - if(cur_data[config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][0]] & config_controller[deviceslot][CONTRPS_DOUBLE_USE_BUTTON_ACTIVATOR][1]){ - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_RELEASED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_RELEASED,cur_config)){result = 0; break;} - }else{ - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_1_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_2_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_3_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_4_PRESSED,cur_config)){result = 0; break;} - if(checkValueinConfigController(deviceslot,CONTRPS_DOUBLE_USE_BUTTON_5_PRESSED,cur_config)){result = 0; break;} - } - } - } - - if(isValueSet(data,cur_config) == 1){ - result = 1; break; - }else{ - //printf("Invalid data! deviceslot(slot): %d config: %d\n",deviceslot,cur_config); - } - }while(0); //The break will become handy ;) - - - if(result == 1){ - *buttons_hold |= VPADButton; // -1 would be also true. - return 1; - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config){ - if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; - if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - u32 hidmask = data->slotdata.hidmask; - s32 deviceslot = data->slotdata.deviceslot; - - s32 result = CONTROLLER_PATCHER_ERROR_NONE; - if(config_controller[deviceslot][cur_config][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //Invalid data - if(hidmask & gHID_LIST_KEYBOARD){ - if(isInKeyboardData(cur_data,config_controller[deviceslot][cur_config][1]) > 0) { - result = 1; - } - }else{ - if((cur_data[config_controller[deviceslot][cur_config][0]] & config_controller[deviceslot][cur_config][1]) == config_controller[deviceslot][cur_config][1]){ - result = 1; - } - } - } - return result; - } -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isInKeyboardData(unsigned char * keyboardData,s32 key){ - if(keyboardData == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - for(s32 i = 0;i 1){ - break; - }else if (keyboardData[i] == key){ - return 1; - } - } - return 0; -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Utils for setting the Button data - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT){ - if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - u32 new_value = VPADButton; - - if(config_controller[gGamePadSlot][CONTRPS_SLOT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ //using new value! - new_value = gGamePadValues[config_controller[gGamePadSlot][CONTRPS_SLOT][1]]; - } - - setButtonData(old_buffer,new_buffer,VPADButton,new_value); - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton){ - if(old_buffer == NULL || new_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if((old_buffer->hold & oldVPADButton) == oldVPADButton){ - new_buffer->hold |= newVPADButton; - } - if((old_buffer->release & oldVPADButton) == oldVPADButton){ - new_buffer->release |= newVPADButton; - } - if((old_buffer->trigger & oldVPADButton) == oldVPADButton){ - new_buffer->trigger |= newVPADButton; - } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Pad Status functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hidmask,s32 pad){ - if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){ - if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1; - return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; - }else{ - s32 deviceslot = getDeviceSlot(hidmask); - if(deviceslot < 0 ) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; - s32 connected_pads = config_controller[deviceslot][CONTRPS_CONNECTED_PADS][1]; - - if((connected_pads & (1 << pad)) > 0){ - return 1; - } - } - return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; -} - -/* -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(u32 hidmask){ - if(hidmask & gHID_LIST_GC){ - if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 0; - if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1; - if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[2].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[2].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 2; - if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[3].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[3].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 3; - - return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED; - } - return 0; -}*/ - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Stick functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::normalizeStickValues(VPADVec2D * stick){ - if(stick == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - f32 max_val = 0.0f; - f32 mul_val = 0.0f; - - if((max_val = (fabs(stick->x)) + fabs(stick->y)) > 1.414f){ - mul_val = 1.414f / max_val; - stick->x *= mul_val; - stick->y *= mul_val; - } - - if(stick->x > 1.0f){ stick->x = 1.0f; } - if(stick->y > 1.0f){ stick->y = 1.0f; } - if(stick->x < -1.0f){ stick->x = -1.0f; } - if(stick->y < -1.0f){ stick->y = -1.0f; } - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -f32 ControllerPatcherUtils::convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone){ - s8 new_value = (s8)(value - default_val); - u8 range = 0; - if(value >= max){ - if(invert == 0x01) return -1.0f; - return 1.0f; - }else if(value <= min){ - if(invert == 0x01) return 1.0f; - return -1.0f; - } - if((value-deadzone) > default_val){ - new_value -= deadzone; - range = (max - (default_val + deadzone)); - }else if((value+deadzone) < default_val){ - new_value += deadzone; - range = ((default_val - deadzone) - min); - }else{ - return 0.0f; - } - if(invert != 0x01){ - return (new_value / (1.0f*range)); - }else{ - return -1.0f*(new_value / (1.0f*range)); - } -} - -VPADVec2D ControllerPatcherUtils::getAnalogValueByButtons(u8 stick_values){ - VPADVec2D stick; - stick.x = 0.0f; - stick.y = 0.0f; - - u8 up = ((stick_values & STICK_VALUE_UP) == STICK_VALUE_UP); - u8 down = ((stick_values & STICK_VALUE_DOWN) == STICK_VALUE_DOWN); - u8 left = ((stick_values & STICK_VALUE_LEFT) == STICK_VALUE_LEFT); - u8 right = ((stick_values & STICK_VALUE_RIGHT) == STICK_VALUE_RIGHT); - - 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; - } - }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; - } - }else{ - if(left){ - if(!right){ - stick.x = -1.0f; - } - - }else if(right){ - if(!down){ - stick.x = 1.0f; - } - } - } - return stick; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(HID_Data * data, VPADStatus * buffer){ - if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 deviceslot = data->slotdata.deviceslot; - if (data->type == DEVICE_TYPE_MOUSE){ - - if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values - HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; - if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - f32 x_value = ms_data->deltaX/10.0f; - f32 y_value = -1.0f*(ms_data->deltaY/10.0f); - - if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_MOUSE_STICK][1] == DEF_L_STICK){ - buffer->leftStick.x += x_value; - buffer->leftStick.y += y_value; - return CONTROLLER_PATCHER_ERROR_NONE; - } - } - - buffer->rightStick.x += x_value; - buffer->rightStick.y += y_value; - } - }else{ - u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; - if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 deadzone = 0; - - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE][1]; - } - - buffer->leftStick.x += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X_INVERT][1], - deadzone); - } - - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_DEADZONE][1]; - } - buffer->leftStick.y += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y_INVERT][1], - deadzone); - } - - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_DEADZONE][1]; - } - - buffer->rightStick.x += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X_INVERT][1], - deadzone); - } - - if( config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - deadzone = 0; - if(config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][0] == CONTROLLER_PATCHER_VALUE_SET){ - deadzone = config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE][1]; - } - - buffer->rightStick.y += convertAnalogValue(cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][0], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX][1], - config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y_INVERT][1], - deadzone); - } - - u8 stick_values = 0; - - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_UP)){ stick_values |= STICK_VALUE_UP; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_DOWN)){ stick_values |= STICK_VALUE_DOWN; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_LEFT)){ stick_values |= STICK_VALUE_LEFT; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_L_STICK_RIGHT)){ stick_values |= STICK_VALUE_RIGHT; } - - if(stick_values > 0 ){ - VPADVec2D stick = getAnalogValueByButtons(stick_values); - buffer->leftStick.x += stick.x; - buffer->leftStick.y += stick.y; - } - - stick_values = 0; - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_UP)){ stick_values |= STICK_VALUE_UP; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_DOWN)){ stick_values |= STICK_VALUE_DOWN; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_LEFT)){ stick_values |= STICK_VALUE_LEFT; } - if(isValueSet(data,CONTRPS_VPAD_BUTTON_R_STICK_RIGHT)){ stick_values |= STICK_VALUE_RIGHT; } - - if(stick_values > 0 ){ - VPADVec2D stick = getAnalogValueByButtons(stick_values); - buffer->rightStick.x += stick.x; - buffer->rightStick.y += stick.y; - } - - /*printf("LX %f(%02X) LY %f(%02X) RX %f(%02X) RY %f(%02X)\n",buffer->leftStick.x,cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_X][0]], - buffer->leftStick.y,cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_L_STICK_Y][0]], - buffer->rightStick.x,cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_X][0]], - buffer->rightStick.y,cur_data[config_controller[deviceslot][CONTRPS_VPAD_BUTTON_R_STICK_Y][0]]);*/ - - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks){ - if(buffer == NULL || last_emulatedSticks == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - u32 emulatedSticks = 0; - - s32 l_x_full = (buffer->leftStick.x > 0.5f || buffer->leftStick.x < -0.5f)? 1:0; - s32 l_y_full = (buffer->leftStick.y > 0.5f || buffer->leftStick.y < -0.5f)? 1:0; - s32 r_x_full = (buffer->rightStick.x > 0.5f || buffer->rightStick.x < -0.5f)? 1:0; - s32 r_y_full = (buffer->rightStick.y > 0.5f || buffer->rightStick.y < -0.5f)? 1:0; - - if((buffer->leftStick.x > 0.5f) || (buffer->leftStick.x > 0.1f && !l_y_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_RIGHT; - } - if((buffer->leftStick.x < -0.5f) || (buffer->leftStick.x < -0.1f && !l_y_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_LEFT; - } - if((buffer->leftStick.y > 0.5f) || (buffer->leftStick.y > 0.1f && !l_x_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_UP; - } - if((buffer->leftStick.y < -0.5f) || (buffer->leftStick.y < -0.1f && !l_x_full)){ - emulatedSticks |= VPAD_STICK_L_EMULATION_DOWN; - } - - if((buffer->rightStick.x > 0.5f) || (buffer->rightStick.x > 0.1f && !r_y_full)){ - emulatedSticks |= VPAD_STICK_R_EMULATION_RIGHT; - } - if((buffer->rightStick.x < -0.5f) || (buffer->rightStick.x < -0.1f && !r_y_full)){ - emulatedSticks |= VPAD_STICK_R_EMULATION_LEFT; - } - if((buffer->rightStick.y > 0.5f) || (buffer->rightStick.y > 0.1f && !r_x_full)){ - emulatedSticks |= VPAD_STICK_R_EMULATION_UP; - } - if((buffer->rightStick.y < -0.5f) || (buffer->rightStick.y < -0.1f && !r_x_full)){ - emulatedSticks |= VPAD_STICK_R_EMULATION_DOWN; - } - - //Setting the emulated sticks - buffer->hold |= emulatedSticks; - buffer->trigger |= (emulatedSticks & (~*last_emulatedSticks)); - buffer->release |= (*last_emulatedSticks & (~emulatedSticks)); - - *last_emulatedSticks = emulatedSticks; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Touch functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADStatus * buffer){ - if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ - s32 buttons_hold; - if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){ - HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data; - if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - s32 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f)); - s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f)); - buffer->tpNormal.x = x_mouse; - buffer->tpNormal.y = y_mouse; - buffer->tpNormal.touched = 1; - buffer->tpNormal.validity = 0; - buffer->tpFiltered1.x = x_mouse; - buffer->tpFiltered1.y = y_mouse; - buffer->tpFiltered1.touched = 1; - buffer->tpFiltered1.validity = 0; - buffer->tpFiltered2.x = x_mouse; - buffer->tpFiltered2.y = y_mouse; - buffer->tpFiltered2.touched = 1; - buffer->tpFiltered2.validity = 0; - } - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){ - u32 hidmask = data->slotdata.hidmask; - - if(hidmask & gHID_LIST_KEYBOARD){ - u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; - u8 * last_data = &data->data_union.controller.last_hid_data[0]; - if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){ - if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ - gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; - if(HID_DEBUG){ printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to touch \n",__LINE__); } - }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ - if(HID_DEBUG){ printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to aim \n",__LINE__); } - gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; - } - } - } - return CONTROLLER_PATCHER_ERROR_NONE; -} - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Other functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToPro(VPADStatus * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesPRO){ - if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesPRO == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 buttons_hold = 0; - - if(vpad_buffer->hold & VPAD_BUTTON_A) buttons_hold |= WPAD_PRO_BUTTON_A; - if(vpad_buffer->hold & VPAD_BUTTON_B) buttons_hold |= WPAD_PRO_BUTTON_B; - if(vpad_buffer->hold & VPAD_BUTTON_X) buttons_hold |= WPAD_PRO_BUTTON_X; - if(vpad_buffer->hold & VPAD_BUTTON_Y) buttons_hold |= WPAD_PRO_BUTTON_Y; - - if(vpad_buffer->hold & VPAD_BUTTON_PLUS) buttons_hold |= WPAD_PRO_BUTTON_PLUS; - if(vpad_buffer->hold & VPAD_BUTTON_MINUS) buttons_hold |= WPAD_PRO_BUTTON_MINUS; - if(vpad_buffer->hold & VPAD_BUTTON_HOME) buttons_hold |= WPAD_PRO_BUTTON_HOME; - - if(vpad_buffer->hold & VPAD_BUTTON_LEFT) buttons_hold |= WPAD_PRO_BUTTON_LEFT; - if(vpad_buffer->hold & VPAD_BUTTON_RIGHT) buttons_hold |= WPAD_PRO_BUTTON_RIGHT; - if(vpad_buffer->hold & VPAD_BUTTON_UP) buttons_hold |= WPAD_PRO_BUTTON_UP; - if(vpad_buffer->hold & VPAD_BUTTON_DOWN) buttons_hold |= WPAD_PRO_BUTTON_DOWN; - - if(vpad_buffer->hold & VPAD_BUTTON_L) buttons_hold |= WPAD_PRO_TRIGGER_L; - if(vpad_buffer->hold & VPAD_BUTTON_ZL) buttons_hold |= WPAD_PRO_TRIGGER_ZL; - - if(vpad_buffer->hold & VPAD_BUTTON_R) buttons_hold |= WPAD_PRO_TRIGGER_R; - if(vpad_buffer->hold & VPAD_BUTTON_ZR) buttons_hold |= WPAD_PRO_TRIGGER_ZR; - - if(vpad_buffer->hold & VPAD_BUTTON_STICK_L) buttons_hold |= WPAD_PRO_BUTTON_STICK_L; - if(vpad_buffer->hold & VPAD_BUTTON_STICK_R) buttons_hold |= WPAD_PRO_BUTTON_STICK_R; - - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_LEFT) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_LEFT; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_RIGHT) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_RIGHT; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_UP) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_UP; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_DOWN) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_DOWN; - - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_LEFT) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_LEFT; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_RIGHT) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_RIGHT; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_UP) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_UP; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_DOWN) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_DOWN; - - pro_buffer->pro.lstick_x = vpad_buffer->leftStick.x; - pro_buffer->pro.lstick_x = vpad_buffer->leftStick.y; - pro_buffer->pro.rstick_x = vpad_buffer->rightStick.x; - pro_buffer->pro.rstick_x = vpad_buffer->rightStick.y; - - /* - pro_buffer->unused_1[1] = 0xBF800000; - pro_buffer->unused_1[3] = 0x3F800000; - pro_buffer->angle_x = 0x3F800000; - pro_buffer->unused_3[4] = 0x3F800000; - pro_buffer->unused_3[7] = 0x3F800000; - pro_buffer->unused_6[17] = 0x3F800000; - pro_buffer->unused_7[1] = 0x3F800000; - pro_buffer->unused_7[5] = 0x3F800000;*/ - - pro_buffer->pro.hold = buttons_hold; - pro_buffer->pro.trigger = (buttons_hold & (~*lastButtonsPressesPRO)); - pro_buffer->pro.release = (*lastButtonsPressesPRO & (~buttons_hold)); - - *lastButtonsPressesPRO = buttons_hold; - - pro_buffer->format = WPAD_FMT_PRO_CONTROLLER; - pro_buffer->wpad_error = 0x00; - pro_buffer->device_type = WPAD_EXT_PRO_CONTROLLER; - pro_buffer->pro.wired = 1; - pro_buffer->pro.charging = 1; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToProWPADRead(VPADStatus * vpad_buffer,WPADReadData * pro_buffer){ - if(vpad_buffer == NULL || pro_buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 buttons_hold = 0; - - if(vpad_buffer->hold & VPAD_BUTTON_A) buttons_hold |= WPAD_PRO_BUTTON_A; - if(vpad_buffer->hold & VPAD_BUTTON_B) buttons_hold |= WPAD_PRO_BUTTON_B; - if(vpad_buffer->hold & VPAD_BUTTON_X) buttons_hold |= WPAD_PRO_BUTTON_X; - if(vpad_buffer->hold & VPAD_BUTTON_Y) buttons_hold |= WPAD_PRO_BUTTON_Y; - - if(vpad_buffer->hold & VPAD_BUTTON_PLUS) buttons_hold |= WPAD_PRO_BUTTON_PLUS; - if(vpad_buffer->hold & VPAD_BUTTON_MINUS) buttons_hold |= WPAD_PRO_BUTTON_MINUS; - if(vpad_buffer->hold & VPAD_BUTTON_HOME) buttons_hold |= WPAD_PRO_BUTTON_HOME; - - if(vpad_buffer->hold & VPAD_BUTTON_LEFT) buttons_hold |= WPAD_PRO_BUTTON_LEFT; - if(vpad_buffer->hold & VPAD_BUTTON_RIGHT) buttons_hold |= WPAD_PRO_BUTTON_RIGHT; - if(vpad_buffer->hold & VPAD_BUTTON_UP) buttons_hold |= WPAD_PRO_BUTTON_UP; - if(vpad_buffer->hold & VPAD_BUTTON_DOWN) buttons_hold |= WPAD_PRO_BUTTON_DOWN; - - if(vpad_buffer->hold & VPAD_BUTTON_L) buttons_hold |= WPAD_PRO_TRIGGER_L; - if(vpad_buffer->hold & VPAD_BUTTON_ZL) buttons_hold |= WPAD_PRO_TRIGGER_ZL; - - if(vpad_buffer->hold & VPAD_BUTTON_R) buttons_hold |= WPAD_PRO_TRIGGER_R; - if(vpad_buffer->hold & VPAD_BUTTON_ZR) buttons_hold |= WPAD_PRO_TRIGGER_ZR; - - if(vpad_buffer->hold & VPAD_BUTTON_STICK_L) buttons_hold |= WPAD_PRO_BUTTON_STICK_L; - if(vpad_buffer->hold & VPAD_BUTTON_STICK_R) buttons_hold |= WPAD_PRO_BUTTON_STICK_R; - - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_LEFT) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_LEFT; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_RIGHT) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_RIGHT; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_UP) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_UP; - if(vpad_buffer->hold & VPAD_STICK_L_EMULATION_DOWN) buttons_hold |= WPAD_PRO_STICK_L_EMULATION_DOWN; - - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_LEFT) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_LEFT; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_RIGHT) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_RIGHT; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_UP) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_UP; - if(vpad_buffer->hold & VPAD_STICK_R_EMULATION_DOWN) buttons_hold |= WPAD_PRO_STICK_R_EMULATION_DOWN; - - pro_buffer->l_stick_x = (s16) (vpad_buffer->leftStick.x * 950.0f); - pro_buffer->l_stick_y = (s16) (vpad_buffer->leftStick.y * 950.0f); - pro_buffer->r_stick_x = (s16) (vpad_buffer->rightStick.x * 950.0f); - pro_buffer->r_stick_y = (s16) (vpad_buffer->rightStick.y * 950.0f); - - pro_buffer->buttons = buttons_hold; - - pro_buffer->fmt = WPAD_FMT_PRO_CONTROLLER; - pro_buffer->err = 0x00; - pro_buffer->dev = WPAD_EXT_PRO_CONTROLLER; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::translateToVPAD(VPADStatus * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesVPAD){ - if(vpad_buffer == NULL || pro_buffer == NULL || lastButtonsPressesVPAD == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - - s32 buttons_hold = 0; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_A) buttons_hold |= VPAD_BUTTON_A; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_B) buttons_hold |= VPAD_BUTTON_B; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_X) buttons_hold |= VPAD_BUTTON_X; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_Y) buttons_hold |= VPAD_BUTTON_Y; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_PLUS) buttons_hold |= VPAD_BUTTON_PLUS; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_MINUS) buttons_hold |= VPAD_BUTTON_MINUS; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_HOME) buttons_hold |= VPAD_BUTTON_HOME; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_LEFT) buttons_hold |= VPAD_BUTTON_LEFT; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_RIGHT) buttons_hold |= VPAD_BUTTON_RIGHT; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_UP) buttons_hold |= VPAD_BUTTON_UP; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_DOWN) buttons_hold |= VPAD_BUTTON_DOWN; - - if(pro_buffer->pro.hold & WPAD_PRO_TRIGGER_L) buttons_hold |= VPAD_BUTTON_L; - if(pro_buffer->pro.hold & WPAD_PRO_TRIGGER_ZL) buttons_hold |= VPAD_BUTTON_ZL; - - if(pro_buffer->pro.hold & WPAD_PRO_TRIGGER_R) buttons_hold |= VPAD_BUTTON_R; - if(pro_buffer->pro.hold & WPAD_PRO_TRIGGER_ZR) buttons_hold |= VPAD_BUTTON_ZR; - - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_STICK_L) buttons_hold |= VPAD_BUTTON_STICK_L; - if(pro_buffer->pro.hold & WPAD_PRO_BUTTON_STICK_R) buttons_hold |= VPAD_BUTTON_STICK_R; - - if(pro_buffer->pro.hold & WPAD_PRO_STICK_L_EMULATION_LEFT) buttons_hold |= VPAD_STICK_L_EMULATION_LEFT; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_L_EMULATION_RIGHT) buttons_hold |= VPAD_STICK_L_EMULATION_RIGHT; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_L_EMULATION_UP) buttons_hold |= VPAD_STICK_L_EMULATION_UP; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_L_EMULATION_DOWN) buttons_hold |= VPAD_STICK_L_EMULATION_DOWN; - - if(pro_buffer->pro.hold & WPAD_PRO_STICK_R_EMULATION_LEFT) buttons_hold |= VPAD_STICK_R_EMULATION_LEFT; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_R_EMULATION_RIGHT) buttons_hold |= VPAD_STICK_R_EMULATION_RIGHT; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_R_EMULATION_UP) buttons_hold |= VPAD_STICK_R_EMULATION_UP; - if(pro_buffer->pro.hold & WPAD_PRO_STICK_R_EMULATION_DOWN) buttons_hold |= VPAD_STICK_R_EMULATION_DOWN; - - vpad_buffer->leftStick.x = pro_buffer->pro.lstick_x; - vpad_buffer->leftStick.y = pro_buffer->pro.lstick_x; - vpad_buffer->rightStick.x = pro_buffer->pro.rstick_x; - vpad_buffer->rightStick.y = pro_buffer->pro.rstick_x; - - vpad_buffer->hold |= buttons_hold; - vpad_buffer->trigger |= (buttons_hold & (~*lastButtonsPressesVPAD)); - vpad_buffer->release |= (*lastButtonsPressesVPAD & (~buttons_hold)); - - *lastButtonsPressesVPAD = buttons_hold; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkValueinConfigController(s32 deviceslot,s32 CONTRPS_slot,s32 expectedValue){ - if(config_controller[deviceslot][CONTRPS_slot][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - if(expectedValue == config_controller[deviceslot][CONTRPS_slot][1]) return 1; - } - return 0; -} - -void ControllerPatcherUtils::setConfigValue(u8 * dest, u8 first, u8 second){ - dest[0] = first; - dest[1] = second; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceSlot(u32 hidmask){ - for(s32 i = 0;i < gHIDMaxDevices;i++){ - if(hidmask & config_controller_hidmask[i]){ - return i; - } - } - return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getDeviceInfoFromVidPid(DeviceInfo * info){ - if(info != NULL){ - for(s32 i = 0;i< gHIDMaxDevices;i++){ - u16 my_vid = config_controller[i][CONTRPS_VID][0] * 0x100 + config_controller[i][CONTRPS_VID][1]; - u16 my_pid = config_controller[i][CONTRPS_PID][0] * 0x100 + config_controller[i][CONTRPS_PID][1]; - //printf("info->vidpid.vid (%04X) == my_vid (%04X) && info->vidpid.pid (%04X) == my_pid (%04X)\n",info->vidpid.vid,my_vid,info->vidpid.pid,my_pid); - if(info->vidpid.vid == my_vid && info->vidpid.pid == my_pid){ - info->slotdata.hidmask = config_controller_hidmask[i]; - info->slotdata.deviceslot = i; - info->pad_count = 1; - if(config_controller[i][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - info->pad_count = config_controller[i][CONTRPS_PAD_COUNT][1]; - if(info->pad_count > HID_MAX_PADS_COUNT){ - info->pad_count = HID_MAX_PADS_COUNT; - } - } - - return CONTROLLER_PATCHER_ERROR_NONE; - //printf("Found device: device: %s slot: %d\n",byte_to_binary(device),deviceSlot); - break; - } - } - return CONTROLLER_PATCHER_ERROR_UNKNOWN_VID_PID; - } - return CONTROLLER_PATCHER_ERROR_INVALID_BUFFER; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getNextSlotData(HIDSlotData * slotdata){ - if(slotdata == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(gHIDRegisteredDevices >= gHIDMaxDevices) return CONTROLLER_PATCHER_ERROR_NO_FREE_SLOT; - slotdata->deviceslot = gHIDRegisteredDevices; - slotdata->hidmask = (1 << (gHIDRegisteredDevices)); - gHIDRegisteredDevices++; - - return CONTROLLER_PATCHER_ERROR_NONE; -} - -CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid){ - if(vidpid == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER; - if(deviceslot >= gHIDMaxDevices || deviceslot < 0) return CONTROLLER_PATCHER_ERROR_DEVICE_SLOT_NOT_FOUND; - vidpid->vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1]; - vidpid->pid = config_controller[deviceslot][CONTRPS_PID][0] * 0x100 + config_controller[deviceslot][CONTRPS_PID][1]; - if(vidpid->vid == 0x0000) return CONTROLLER_PATCHER_ERROR_FAILED_TO_GET_HIDDATA; - return CONTROLLER_PATCHER_ERROR_NONE; -} - -s32 ControllerPatcherUtils::getPadSlotInAdapter(s32 deviceslot, u8 * input_data){ - s32 slot_incr = 0; - if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){ - s32 pad_count = config_controller[deviceslot][CONTRPS_PAD_COUNT][1]; - if(pad_count > HID_MAX_PADS_COUNT){ - pad_count = HID_MAX_PADS_COUNT; - } - for(s32 i= 0;iactive){ - DeviceInfo device_info; - - memset(&device_info,0,sizeof(device_info)); - device_info.vidpid = padinfo->vidpid; - - s32 res = -1; - if((res = ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info)) >= 0){ - if(!ignorePadSlot){ - s32 real_pad = (padinfo->pad/(device_info.pad_count))*device_info.pad_count; - if(real_pad == padslot && device_info.slotdata.deviceslot == deviceslot){ - if(ControllerPatcherUtils::checkActivePad(device_info.slotdata.hidmask,padinfo->pad)){ - gSamplingCallback(i); - } - } - }else{ - gSamplingCallback(i); - } - } - } - } - } - return CONTROLLER_PATCHER_ERROR_NONE; -} diff --git a/wiiu/controller_patcher/patcher/ControllerPatcherUtils.hpp b/wiiu/controller_patcher/patcher/ControllerPatcherUtils.hpp deleted file mode 100644 index b026839c7f..0000000000 --- a/wiiu/controller_patcher/patcher/ControllerPatcherUtils.hpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 . - ****************************************************************************/ - -/** - * @file ControllerPatcherUtil.hpp - * @author Maschell - * @date 25 Aug 2016 - * \brief This files contain useful functions for the controller patcher engine - * - * @see https://github.com/Maschell/controller_patcher - */ - -#ifndef _CONTROLLER_PATCHER_UTIL_H_ -#define _CONTROLLER_PATCHER_UTIL_H_ - - -#include "wiiu/vpad.h" -#include "wiiu/kpad.h" - -#include "../ControllerPatcher.hpp" - -class ControllerPatcherUtils{ - //give the other classes access to the private functions. - friend class ControllerPatcher; - friend class ControllerPatcherHID; - friend class ConfigParser; - - public: - /** - \brief Returns the device slot for a given HID-Mask. - - \param hidmask Given HID-Mask - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is the deviceslot of the given HID-Mask - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceSlot(u32 hidmask); - - /** - \brief Returns the device slot for a given HID-Mask. - - \param handle Given HID-handle - \param data Given my_cb_user ** where the result will be stored. Valid pointer when result is >= 0. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given my_cb_user **. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDataByHandle(s32 handle, my_cb_user ** data); - - /** - \brief Returns the VID/PID for the given device slot. - - \param deviceslot Given device slot - \param vidpid Pointer to the DeviceVIDPIDInfo struct where the result will be stored. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The actual result will be store in the given DeviceVIDPIDInfo *. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getVIDPIDbyDeviceSlot(s32 deviceslot, DeviceVIDPIDInfo * vidpid); - - /** \brief Set the VPAD data for a given KPAD data. - * - * \param vpad_buffer VPADStatus* A pointer to the VPAD Data where the result will be stored. - * \param pro_buffer KPADData* A pointer to the given KPADData data. - * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToVPAD(VPADStatus * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesVPAD); - private: - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Analyse inputs - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - - /** \brief Checks if a the given @p VPADButton was pressed in the given HID @data. When it was pressed, the result will be set the in given @p buttons_hold - * - * \param data Pointer to the HID_Data from where the input is read. - * \param buttons_hold Pointer to the u32 where the result will be written to. - * \param VPADButton The button that will be checked - * \return When the functions failed result < 0 is returned.If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getButtonPressed(HID_Data * data, s32 * buttons_hold, s32 VPADButton); - - - /** \brief Checks if a given value is set in the HID_DATA given the data in the slot number provided by cur_config. - * - * \param data Pointer to the HID_Data from where the input is read. - * \param cur_config slot of the configuration array which will be checked. - * \return When the functions failed result < 0 is returned. If the value is set, 1 will be returned. Otherwise 0. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR isValueSet(HID_Data * data,s32 cur_config); - - - /** \brief Checks if a given key in the keyboard data is pressed. - * - * \param keyboardData A pointer to the keyboard data. - * \param key A pointer to the keyboard data. - * \return When the functions failed result < 0 is returned. If the key is active pressed, 1 is returned. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR isInKeyboardData(unsigned char * keyboardData,s32 key); - - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Utils for setting the Button data - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - - /** \brief Checks if a @p VPADButton (VPAD_BUTTON_XXX) is set in the given @p CONTRPS_SLOT (usually the one for buttons remapping) of the GamePad. When its set it'll be - * set for the corresponding Button (aka button remapping). When the @p CONTRPS_SLOT is not valid, the normal buttons layout will be used. - * - * \param old_buffer A pointer to a VPADStatus struct from which will be read. - * \param new_buffer A pointer to a VPADStatus struct where the result will be written. - * \param VPADButton The buttons that will be may replaced - * \param CONTRPS_SLOT The CONTRPS_SLOT where the VPAD_Buttons we want to use instead of the parameter "VPADButton" could be saved. - * \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonRemappingData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 VPADButton, s32 CONTRPS_SLOT); - - /** - \brief Checks if a given button (oldVPADButton) is set in a given VPADStatus struct (old_buffer). If its set, it will set an other - button (newVPADButton) to the second given VPADStatus struct (new_buffer) - - \param old_buffer A pointer to a VPADStatus struct from which will be read. - \param new_buffer A pointer to a VPADStatus struct where the result will be written. - \param oldVPADButton The buttons that need to be set in the first VPADStatus - \param newVPADButton The buttons that will be set in the second VPADStatus, when the oldVPADButton is pressed in the first buffer. - - \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setButtonData(VPADStatus * old_buffer, VPADStatus * new_buffer,u32 oldVPADButton,u32 newVPADButton); - - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Pad Status functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Checks if a controller is attached for the given HID-Mask and pad. - - \param hidmask Bit-Mask of the target hid-device. - \param pad Defines for which pad the connection will be checked. - - \return When the functions failed result < 0 is returned. If the pad is active/connected, 1 is returned. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkActivePad(u32 hidmask,s32 pad); - - /** - \brief Returns the first active pad of devices with the given HID-Mask. Currently only implemented for the GC-Adapter. Every other pad will always return 0. - - \param hidmask Bit-Mask of the target hid-device. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. The returned value is fist active pad. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getActivePad(u32 hidmask); - - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Stick functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Normalizes the stick to valid values. - - \param stick Pointer to the stick that will be normalized - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR normalizeStickValues(VPADVec2D * stick); - - /** - \brief Converts the digital absolute stick data into a float value. It also applies the deadzones, and can invert the result. - - \param value Given current value of the stick axis - \param default_val Value in neutral axis-position - \param min Value that represents -1.0f - \param max Value that represents 1.0f - \param invert Set to 1 if the axis needs to be inverted - \param deadzone Deadzone - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static f32 convertAnalogValue(u8 value, u8 default_val, u8 min, u8 max, u8 invert,u8 deadzone); - - /** - \brief Calculates a the stick data (VPADVec2D) from given digital direction. - - \param stick_values bits need to set for each direction. (STICK_VALUE_UP,STICK_VALUE_DOWN,STICK_VALUE_LEFT,STICK_VALUE_RIGHT) - - \return The VPADVec2D with the set values. - **/ - static VPADVec2D getAnalogValueByButtons(u8 stick_values); - - /** - \brief Handles the analog-stick data of HID devices. The result will written in the VPADStatus buffer. - - \param data Pointer to the current data of the HID device - \param buffer Pointer to VPADStatus where the analog-stick data will be set. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR convertAnalogSticks(HID_Data * data,VPADStatus * buffer); - - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Mouse functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** - \brief Set the touch data in the VPADStatus buffer. - Currently its only possible to set the touch data from a Mouse - - \param data The current data of the HID device - \param buffer Pointer to VPADStatus where the touch data will be set. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setTouch(HID_Data * data,VPADStatus * buffer); - - /** \brief Checks if the mouse mode needs to be changed. Sets it to the new mode if necessary. - * Currently the incoming data needs to be from a keyboard. - * - * \param data HID_Data* Pointer to the current data - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkAndSetMouseMode(HID_Data * data); - - /** - \brief Set the emulated sticks for a given VPAD data. - - \param buffer: A pointer to the given VPAD Data. - \param last_emulatedSticks: A pointer to the button presses of the previous call. Will be updated while calling. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR setEmulatedSticks(VPADStatus * buffer, u32 * last_emulatedSticks); - - /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * Other functions - *---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - /** \brief Set the Pro Controller for a given VPAD data. - * - * \param vpad_buffer VPADStatus* A pointer to the given VPAD Data. - * \param pro_buffer KPADData* A pointer to the KPADData where the result will be stored. - * \param lastButtonsPressesPRO u32* A pointer to the button presses of the previous call. Will be updated while calling. - * \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - * - */ - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToPro(VPADStatus * vpad_buffer,KPADData * pro_buffer,u32 * lastButtonsPressesPRO); - static CONTROLLER_PATCHER_RESULT_OR_ERROR translateToProWPADRead(VPADStatus * vpad_buffer,WPADReadData * pro_buffer); - - /** - \brief Checks if the value at the given device + CONTRPS slot equals the expected value. - - \param device_slot - \param CONTRPS_slot - \param expectedValue - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR checkValueinConfigController(s32 device_slot,s32 CONTRPS_slot,s32 expectedValue); - - /** - \brief Sets two u8 values to the given pointer. - - \param dest: pointer to the destination array. - \param first: Value that will be written in @p dest[0] - \param second: Value that will be written in @p dest[1] - **/ - static void setConfigValue(u8 * dest , u8 first, u8 second); - - /** - \brief Saves a new free device slot and the corresponding HID-Mask in the given @p HIDSlotData pointer - - \param slotdata Pointer to the HIDSlotData struct where the result will be saved. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getNextSlotData(HIDSlotData * slotdata); - - /** - \brief Fills up a given DeviceInfo, which provides a valid VID/PID, with HIDSlotData. - - \param info Pointer the target DeviceInfo. The VID/PID need to be set, the HIDSlotData will be filled with data. - - \return When the functions failed result < 0 is returned. If the result is >= 0 the function was successful. - **/ - static CONTROLLER_PATCHER_RESULT_OR_ERROR getDeviceInfoFromVidPid(DeviceInfo * info); - - /** - \brief returns the internal slot number of the device. Some adapters have multiple slot and send the data for each one - alternating (with an identifier at the beginning). This function searches for the identifier (if it's set) and returns the - slot number relative to this pad. - - \param device slot - \param current input data - \return The relative slot in the device - **/ - static s32 getPadSlotInAdapter(s32 deviceslot, u8 * input_data); - - /** - \brief returns a pointer to the ControllerMapping to the given controller type - - \param type controller type - - \return pointer to ControllerMapping data, null is type was invalid - **/ - static ControllerMappingPAD * getControllerMappingByType(UController_Type type); - - static CONTROLLER_PATCHER_RESULT_OR_ERROR doSampling(u16 deviceslot,u8 padslot,bool ignorePadSlot); -}; - -#endif /* _CONTROLLER_PATCHER_UTIL_H_ */ diff --git a/wiiu/controller_patcher/utils/CPRetainVars.cpp b/wiiu/controller_patcher/utils/CPRetainVars.cpp deleted file mode 100644 index b4c253fe43..0000000000 --- a/wiiu/controller_patcher/utils/CPRetainVars.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "../ControllerPatcher.hpp" - -ControllerMapping gControllerMapping __attribute__((section(".data"))); - -u8 gConfig_done __attribute__((section(".data"))) = 0; -u8 gButtonRemappingConfigDone __attribute__((section(".data"))) = 0; - -u32 gHIDAttached __attribute__((section(".data"))) = 0; -u32 gHIDCurrentDevice __attribute__((section(".data"))) = 0; - -u16 gHIDRegisteredDevices __attribute__((section(".data"))) = 0; - -HIDClient gHIDClient __attribute__((section(".data"))); - -HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices] __attribute__((section(".data"))); - -u8 gHID_Mouse_Mode __attribute__((section(".data"))) = HID_MOUSE_MODE_TOUCH; - -u32 gGamePadValues[CONTRPS_MAX_VALUE] __attribute__((section(".data"))); - -u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2] __attribute__((section(".data"))); -u32 config_controller_hidmask[gHIDMaxDevices] __attribute__((section(".data"))); - -u32 gHID_LIST_GC __attribute__((section(".data"))) = 0; -u32 gHID_LIST_DS3 __attribute__((section(".data"))) = 0; -u32 gHID_LIST_DS4 __attribute__((section(".data"))) = 0; -u32 gHID_LIST_KEYBOARD __attribute__((section(".data"))) = 0; -u32 gHID_LIST_SWITCH_PRO __attribute__((section(".data"))) = 0; -u32 gHID_LIST_MOUSE __attribute__((section(".data"))) = 0; - -u16 gGamePadSlot __attribute__((section(".data"))) = 0; -u16 gHID_SLOT_GC __attribute__((section(".data"))) = 0; -u16 gHID_SLOT_KEYBOARD __attribute__((section(".data"))) = 0; -u16 gMouseSlot __attribute__((section(".data"))) = 0; - -u8 gOriginalDimState __attribute__((section(".data"))) = 0; -u8 gOriginalAPDState __attribute__((section(".data"))) = 0; - -u16 gNetworkController[gHIDMaxDevices][HID_MAX_PADS_COUNT][4] __attribute__((section(".data"))); -s32 gHIDNetworkClientID __attribute__((section(".data"))) = 0; -u8 gUsedProtocolVersion __attribute__((section(".data"))) = WIIU_CP_TCP_HANDSHAKE; - -wpad_connect_callback_t gWPADConnectCallback[4] __attribute__((section(".data"))); -wpad_connect_callback_t gKPADConnectCallback[4] __attribute__((section(".data"))); -wpad_extension_callback_t gExtensionCallback[4] __attribute__((section(".data"))); -wpad_sampling_callback_t gSamplingCallback __attribute__((section(".data"))) = 0; -u8 gCallbackCooldown __attribute__((section(".data"))) = 0; - -u8 gGlobalRumbleActivated __attribute__((section(".data"))) = 0; - -ConnectionHelper connectionOrderHelper[gHIDMaxDevices] __attribute__((section(".data"))); - -u32 gUDPClientip __attribute__((section(".data"))) = 0; -ControllerMappingPADInfo* gProPadInfo[4] __attribute__((section(".data"))) = {&gControllerMapping.proController[0].pad_infos[0], - &gControllerMapping.proController[1].pad_infos[0], - &gControllerMapping.proController[2].pad_infos[0], - &gControllerMapping.proController[3].pad_infos[0]} ; diff --git a/wiiu/controller_patcher/utils/CPRetainVars.hpp b/wiiu/controller_patcher/utils/CPRetainVars.hpp deleted file mode 100644 index 87ab0d7af4..0000000000 --- a/wiiu/controller_patcher/utils/CPRetainVars.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "wiiu/syshid.h" -#include "wiiu/kpad.h" -#include "../patcher/ControllerPatcherDefs.h" - -extern ControllerMapping gControllerMapping; - -extern u8 gConfig_done; -extern u8 gButtonRemappingConfigDone; - -extern u32 gHIDAttached; -extern u32 gHIDCurrentDevice; -extern HIDClient gHIDClient; - -extern u16 gHIDRegisteredDevices; - -extern HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices]; - -extern u8 gHID_Mouse_Mode; - -extern u32 gGamePadValues[CONTRPS_MAX_VALUE]; - -extern u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2]; -extern u32 config_controller_hidmask[gHIDMaxDevices]; - -extern u32 gHID_LIST_GC; -extern u32 gHID_LIST_DS3; -extern u32 gHID_LIST_DS4; -extern u32 gHID_LIST_KEYBOARD; -extern u32 gHID_LIST_SWITCH_PRO; -extern u32 gHID_LIST_MOUSE; -extern u16 gGamePadSlot; - -extern u16 gHID_SLOT_GC; -extern u16 gHID_SLOT_KEYBOARD; -extern u16 gMouseSlot; - -extern u8 gOriginalDimState; -extern u8 gOriginalAPDState; - -extern u16 gNetworkController[gHIDMaxDevices][HID_MAX_PADS_COUNT][4]; -extern s32 gHIDNetworkClientID; - -extern u8 gUsedProtocolVersion; - -extern wpad_connect_callback_t gWPADConnectCallback[4]; -extern wpad_connect_callback_t gKPADConnectCallback[4]; -extern wpad_extension_callback_t gExtensionCallback[4]; -extern wpad_sampling_callback_t gSamplingCallback; -extern u8 gCallbackCooldown; -extern u8 gGlobalRumbleActivated; - -extern ConnectionHelper connectionOrderHelper[gHIDMaxDevices]; - -extern u32 gUDPClientip; -extern ControllerMappingPADInfo* gProPadInfo[4]; - -#endif // CP_RETAINS_VARS_H_ diff --git a/wiiu/controller_patcher/utils/CPStringTools.cpp b/wiiu/controller_patcher/utils/CPStringTools.cpp deleted file mode 100644 index ab4a97a409..0000000000 --- a/wiiu/controller_patcher/utils/CPStringTools.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "CPStringTools.hpp" -#include -#include -#include -#include - -#include -#include - -#include "wiiu/types.h" - -bool CPStringTools::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 CPStringTools::StringSplit(const std::string & inValue, const std::string & splitter){ - std::string value = inValue; - std::vector result; - while (true) { - u32 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; -} - -const char * CPStringTools::byte_to_binary(s32 x){ - static char b[9]; - b[0] = '\0'; - - s32 z; - for (z = 128; z > 0; z >>= 1) - { - strcat(b, ((x & z) == z) ? "1" : "0"); - } - - return b; -} - -std::string CPStringTools::removeCharFromString(std::string& input,char toBeRemoved){ - std::string output = input; - size_t position; - while(1){ - position = output.find(toBeRemoved); - if(position == std::string::npos) - break; - output.erase(position, 1); - } - return output; -} - - -std::string CPStringTools::strfmt(const char * format, ...){ - std::string str; - char * tmp = NULL; - - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - str = tmp; - } - va_end(va); - - if(tmp){ - free(tmp); - tmp = NULL; - } - - return str; -} -//CPStringTools diff --git a/wiiu/controller_patcher/utils/CPStringTools.hpp b/wiiu/controller_patcher/utils/CPStringTools.hpp deleted file mode 100644 index 7a3a13009f..0000000000 --- a/wiiu/controller_patcher/utils/CPStringTools.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _CPSTRING_TOOLS_H_ -#define _CPSTRING_TOOLS_H_ -#include -#include - -#include "wiiu/types.h" - -class CPStringTools{ - public: - static bool EndsWith(const std::string& a, const std::string& b); - static std::vector StringSplit(const std::string & inValue, const std::string & splitter); - static std::string removeCharFromString(std::string& input,char toBeRemoved); - static const char * byte_to_binary(s32 test); - static std::string strfmt(const char * format, ...); -}; - -#endif /* _CPSTRING_TOOLS_H_ */ diff --git a/wiiu/controller_patcher/utils/ControllerPatcherThread.hpp b/wiiu/controller_patcher/utils/ControllerPatcherThread.hpp deleted file mode 100644 index 6cf101cec4..0000000000 --- a/wiiu/controller_patcher/utils/ControllerPatcherThread.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 Dimok - * - * 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 ControllerPatcherThread_H_ -#define ControllerPatcherThread_H_ - -#include -#include -#include "wiiu/os/thread.h" - -class ControllerPatcherThread -{ -public: - typedef void (* Callback)(ControllerPatcherThread *thread, void *arg); - - //! constructor - ControllerPatcherThread(int iAttr, int iPriority = 16, int iStackSize = 0x8000, ControllerPatcherThread::Callback callback = NULL, void *callbackArg = NULL) - : pThread(NULL) - , pThreadStack(NULL) - , pCallback(callback) - , pCallbackArg(callbackArg) - { - //! save attribute assignment - iAttributes = iAttr; - //! allocate the thread - pThread = (OSThread*)memalign(8, sizeof(OSThread)); - //! allocate the stack - pThreadStack = (u8 *) memalign(0x20, iStackSize); - //! create the thread - if(pThread && pThreadStack) - OSCreateThread(pThread, &ControllerPatcherThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); - } - - //! destructor - virtual ~ControllerPatcherThread() { shutdownThread(); } - - static ControllerPatcherThread *create(ControllerPatcherThread::Callback callback, void *callbackArg, int iAttr = eAttributeNone, int iPriority = 16, int iStackSize = 0x8000) - { - return ( new ControllerPatcherThread(iAttr, iPriority, iStackSize, callback, callbackArg) ); - } - - //! Get thread ID - virtual void* getThread() const { return pThread; } - //! Thread entry function - virtual void executeThread(void) - { - if(pCallback) - pCallback(this, pCallbackArg); - } - //! Suspend thread - virtual void suspendThread(void) { if(isThreadSuspended()) return; if(pThread) OSSuspendThread(pThread); } - //! Resume thread - virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); } - //! Set thread priority - virtual void setThreadPriority(int prio) { if(pThread) OSSetThreadPriority(pThread, prio); } - //! Check if thread is suspended - virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; } - //! Check if thread is terminated - virtual bool isThreadTerminated(void) const { if(pThread) return OSIsThreadTerminated(pThread); return false; } - //! Check if thread is running - virtual bool isThreadRunning(void) const { return !isThreadSuspended() && !isThreadRunning(); } - //! Shutdown thread - virtual void shutdownThread(void) - { - //! wait for thread to finish - if(pThread && !(iAttributes & eAttributeDetach)) - { - if(isThreadSuspended()) - resumeThread(); - - OSJoinThread(pThread, NULL); - } - //! free the thread stack buffer - if(pThreadStack) - free(pThreadStack); - if(pThread) - free(pThread); - - pThread = NULL; - pThreadStack = NULL; - } - //! Thread attributes - enum eControllerPatcherThreadAttributes - { - eAttributeNone = 0x07, - eAttributeAffCore0 = 0x01, - eAttributeAffCore1 = 0x02, - eAttributeAffCore2 = 0x04, - eAttributeDetach = 0x08, - eAttributePinnedAff = 0x10 - }; -private: - static int threadCallback(int argc, const char **argv) - { - //! After call to start() continue with the internal function - ((ControllerPatcherThread *) argv)->executeThread(); - return 0; - } - int iAttributes; - OSThread *pThread; - u8 *pThreadStack; - Callback pCallback; - void *pCallbackArg; -}; - -#endif diff --git a/wiiu/controller_patcher/utils/FSHelper.c b/wiiu/controller_patcher/utils/FSHelper.c deleted file mode 100644 index 0b117c752e..0000000000 --- a/wiiu/controller_patcher/utils/FSHelper.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define FS_MAX_MOUNTPATH_SIZE 128 -int FS_Helper_MountFS(void *pClient, void *pCmd, char **mount_path){ - int result = -1; - - void *mountSrc = malloc(sizeof(FSMountSource)); - if(!mountSrc) - return -3; - - char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE); - if(!mountPath) { - free(mountSrc); - return -4; - } - - memset(mountSrc, 0, sizeof(FSMountSource)); - memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE); - - // Mount sdcard - if (FSGetMountSource(pClient, pCmd, FS_MOUNT_SOURCE_SD, mountSrc, -1) == 0) - { - result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); - if((result == 0) && mount_path) { - *mount_path = (char*)malloc(strlen(mountPath) + 1); - if(*mount_path) - strcpy(*mount_path, mountPath); - } - } - - free(mountPath); - free(mountSrc); - return result; -} - -int FS_Helper_GetFile(void * pClient,void * pCmd,const char * path, char *(*result)){ - if(pClient == NULL || pCmd == NULL || path == NULL || result == NULL) return -2; - FSStat stats; - s32 status = -1; - s32 handle = 0; - if((status = FSGetStat(pClient,pCmd,path,&stats,-1)) == FS_STATUS_OK){ - (*result) = (uint8_t *) memalign(0x40, (sizeof(uint8_t)*stats.size)+1); - if(!(*result)){ - printf("FS_Helper_GetFile(line %d): error: Failed to allocate space for reading the file\n",__LINE__); - return -1; - } - (*result)[stats.size] = '\0'; - if((status = FSOpenFile(pClient,pCmd,path,"r",&handle,-1)) == FS_STATUS_OK){ - s32 total_read = 0; - s32 ret2 = 0; - - char * cur_result_pointer = *result; - s32 sizeToRead = stats.size; - - while ((ret2 = FSReadFile(pClient,pCmd, cur_result_pointer, 0x01, sizeToRead, handle, 0, -1)) > 0){ - total_read += ret2; - cur_result_pointer += ret2; - sizeToRead -= ret2; - } - - }else{ - printf("FS_Helper_GetFile(line %d): error: (FSOpenFile) Couldn't open file (%s), error: %d",__LINE__,path,status); - free((*result)); - (*result)=NULL; - return -1; - } - - FSCloseFile(pClient,pCmd,handle,-1); - return 0; - }else{ - printf("FS_Helper_GetFile(line %d): error: (GetStat) Couldn't open file (%s), error: %d",__LINE__,path,status); - } - return -1; -} diff --git a/wiiu/controller_patcher/utils/FSHelper.h b/wiiu/controller_patcher/utils/FSHelper.h deleted file mode 100644 index 4f22024701..0000000000 --- a/wiiu/controller_patcher/utils/FSHelper.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __FSHELPER_H_ -#define __FSHELPER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int FS_Helper_MountFS(void *pClient, void *pCmd, char **mount_path); -int FS_Helper_GetFile(void * pClient,void * pCmd,const char *, char **result); - -#ifdef __cplusplus -} -#endif - -#endif // __FSHELPER_H_ diff --git a/wiiu/controller_patcher/utils/PadConst.cpp b/wiiu/controller_patcher/utils/PadConst.cpp deleted file mode 100644 index a4c8858ae7..0000000000 --- a/wiiu/controller_patcher/utils/PadConst.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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 "PadConst.hpp" - -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; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Device names -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -const char *HID_GC_STRING = "GameCube\nUSB-Adapter"; -const char *HID_KEYBOARD_STRING = "Keyboard"; -const char *HID_MOUSE_STRING = "Mouse"; -const char *HID_DS3_STRING = "DualShock 3\nController"; -const char *HID_DS4_STRING = "DualShock 4\nController"; -const char *HID_NEW_DS4_STRING = "DualShock 4\nController"; -const char *HID_XINPUT_STRING = "XInput\nController"; -const char *HID_SWITCH_PRO_STRING = "Switch\nPro Controller"; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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, - 0x1A, //STICK_CONF_MIN, - 0xE4};//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, - 0x11, //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, - 0x2B, //STICK_CONF_MIN, - 0xE2};//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, - 0x1D, //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, - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! XInput -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -const u8 HID_XINPUT_BUTTON_A[] = { 0x07,HID_XINPUT_BUTTON_A_VALUE}; -const u8 HID_XINPUT_BUTTON_B[] = { 0x07,HID_XINPUT_BUTTON_B_VALUE}; -const u8 HID_XINPUT_BUTTON_X[] = { 0x07,HID_XINPUT_BUTTON_X_VALUE}; -const u8 HID_XINPUT_BUTTON_Y[] = { 0x07,HID_XINPUT_BUTTON_Y_VALUE}; - -const u8 HID_XINPUT_BUTTON_LB[] = { 0x06,HID_XINPUT_BUTTON_LB_VALUE}; -const u8 HID_XINPUT_BUTTON_LT[] = { 0x04,HID_XINPUT_BUTTON_LT_VALUE}; -const u8 HID_XINPUT_BUTTON_L3[] = { 0x06,HID_XINPUT_BUTTON_L3_VALUE}; - -const u8 HID_XINPUT_BUTTON_RB[] = { 0x06,HID_XINPUT_BUTTON_RB_VALUE}; -const u8 HID_XINPUT_BUTTON_RT[] = { 0x05,HID_XINPUT_BUTTON_RT_VALUE}; -const u8 HID_XINPUT_BUTTON_R3[] = { 0x06,HID_XINPUT_BUTTON_R3_VALUE}; - -const u8 HID_XINPUT_BUTTON_START[] = { 0x06,HID_XINPUT_BUTTON_START_VALUE}; -const u8 HID_XINPUT_BUTTON_BACK[] = { 0x06,HID_XINPUT_BUTTON_BACK_VALUE}; -const u8 HID_XINPUT_BUTTON_GUIDE[] = { 0x06,HID_XINPUT_BUTTON_GUIDE_VALUE}; - -const u8 HID_XINPUT_BUTTON_DPAD_TYPE[] = { CONTRPDM_Normal,HID_XINPUT_BUTTON_DPAD_MASK_VALUE}; -const u8 HID_XINPUT_BUTTON_LEFT[] = { 0x07,HID_XINPUT_BUTTON_LEFT_VALUE}; -const u8 HID_XINPUT_BUTTON_RIGHT[] = { 0x07,HID_XINPUT_BUTTON_RIGHT_VALUE}; -const u8 HID_XINPUT_BUTTON_DOWN[] = { 0x07,HID_XINPUT_BUTTON_DOWN_VALUE}; -const u8 HID_XINPUT_BUTTON_UP[] = { 0x07,HID_XINPUT_BUTTON_UP_VALUE}; - -const u8 HID_XINPUT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x00, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, - -const u8 HID_XINPUT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x01, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, - -const u8 HID_XINPUT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x02, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, - -const u8 HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x03, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x10, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x00, //STICK_CONF_MIN, - 0xFF};//STICK_CONF_MAX, - - - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Switch Pro Controller -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -const u8 HID_SWITCH_PRO_BT_BUTTON_A[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_A_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_B[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_B_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_X[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_X_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_Y[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_Y_VALUE >> 24) & 0xFF)}; - -const u8 HID_SWITCH_PRO_BT_BUTTON_L[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_L_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_ZL[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_ZL_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_L[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_STICK_L_VALUE >> 16) & 0xFF)}; - -const u8 HID_SWITCH_PRO_BT_BUTTON_R[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_R_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_ZR[] = { 0x00,(u8)((HID_SWITCH_PRO_BT_BUTTON_ZR_VALUE >> 24) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_R[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_STICK_R_VALUE >> 16) & 0xFF)}; - -const u8 HID_SWITCH_PRO_BT_BUTTON_PLUS[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_PLUS_VALUE >> 16) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_MINUS[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_MINUS_VALUE >> 16) & 0xFF)}; -const u8 HID_SWITCH_PRO_BT_BUTTON_HOME[] = { 0x01,(u8)((HID_SWITCH_PRO_BT_BUTTON_HOME_VALUE >> 16) & 0xFF)}; - -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[] = { CONTRPDM_Hat,HID_SWITCH_PRO_BT_BUTTON_DPAD_MASK_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_N[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_N_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NE_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_E[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_E_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_SE_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_S[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_S_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_SW_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_W[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_W_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NW_VALUE}; -const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[] = { 0x02,HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL_VALUE}; - - -const u8 HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x04, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x01, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x28, //STICK_CONF_MIN, - 0xDF};//STICK_CONF_MAX, - -const u8 HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x06, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x06, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x16, //STICK_CONF_MIN, - 0xD7};//STICK_CONF_MAX, - -const u8 HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x08, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x04, //STICK_CONF_DEADZONE, - 0x00, //STICK_CONF_INVERT, - 0x29, //STICK_CONF_MIN, - 0xE2};//STICK_CONF_MAX, - -const u8 HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION - 0x0A, //STICK_CONF_BYTE, - 0x80, //STICK_CONF_DEFAULT, - 0x08, //STICK_CONF_DEADZONE, - 0x01, //STICK_CONF_INVERT, - 0x22, //STICK_CONF_MIN, - 0xE4};//STICK_CONF_MAX, diff --git a/wiiu/controller_patcher/utils/PadConst.hpp b/wiiu/controller_patcher/utils/PadConst.hpp deleted file mode 100644 index 9e4fd3dcb9..0000000000 --- a/wiiu/controller_patcher/utils/PadConst.hpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016,2017 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_ - -#include -#include "../patcher/ControllerPatcherDefs.h" - -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; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Device names -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern const char *HID_GC_STRING; -extern const char *HID_KEYBOARD_STRING; -extern const char *HID_MOUSE_STRING; -extern const char *HID_DS3_STRING; -extern const char *HID_DS4_STRING; -extern const char *HID_NEW_DS4_STRING; -extern const char *HID_XINPUT_STRING; -extern const char *HID_SWITCH_PRO_STRING; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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]; - - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! XInput -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -extern const u8 HID_XINPUT_BUTTON_A[]; -extern const u8 HID_XINPUT_BUTTON_B[]; -extern const u8 HID_XINPUT_BUTTON_X[]; -extern const u8 HID_XINPUT_BUTTON_Y[]; - -extern const u8 HID_XINPUT_BUTTON_LB[]; -extern const u8 HID_XINPUT_BUTTON_LT[]; -extern const u8 HID_XINPUT_BUTTON_L3[]; - -extern const u8 HID_XINPUT_BUTTON_RB[]; -extern const u8 HID_XINPUT_BUTTON_RT[]; -extern const u8 HID_XINPUT_BUTTON_R3[]; - -extern const u8 HID_XINPUT_BUTTON_START[]; -extern const u8 HID_XINPUT_BUTTON_BACK[]; -extern const u8 HID_XINPUT_BUTTON_GUIDE[]; - -extern const u8 HID_XINPUT_BUTTON_DPAD_TYPE[]; -extern const u8 HID_XINPUT_BUTTON_LEFT[]; -extern const u8 HID_XINPUT_BUTTON_RIGHT[]; -extern const u8 HID_XINPUT_BUTTON_DOWN[]; -extern const u8 HID_XINPUT_BUTTON_UP[]; - -extern const u8 HID_XINPUT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_XINPUT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_XINPUT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_XINPUT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Switch Pro Controller -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -extern const u8 HID_SWITCH_PRO_BT_BUTTON_A[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_B[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_X[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_Y[]; - -extern const u8 HID_SWITCH_PRO_BT_BUTTON_L[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_ZL[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_L[]; - -extern const u8 HID_SWITCH_PRO_BT_BUTTON_R[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_ZR[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_STICK_R[]; - -extern const u8 HID_SWITCH_PRO_BT_BUTTON_PLUS[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_MINUS[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_HOME[]; - -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_TYPE[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_N[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NE[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_E[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SE[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_S[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_SW[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_W[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NW[]; -extern const u8 HID_SWITCH_PRO_BT_BUTTON_DPAD_NEUTRAL[]; - - -extern const u8 HID_SWITCH_PRO_BT_STICK_L_X[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_SWITCH_PRO_BT_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_SWITCH_PRO_BT_STICK_R_X[STICK_CONF_ENUM_MAXVALUE]; -extern const u8 HID_SWITCH_PRO_BT_STICK_R_Y[STICK_CONF_ENUM_MAXVALUE]; - -#endif /* _PAD_CONST_H_ */ From 3b92cce6bfa2eb10457b1bc3a7ba62c341f7f3da Mon Sep 17 00:00:00 2001 From: gblues Date: Sat, 2 Dec 2017 01:01:43 -0800 Subject: [PATCH 02/26] Start wiring up the HID driver - add alloc/free for necessary objects - register callback with Wii U OS Don't think I've put the unregister bit in, so this is very likely broken. --- input/drivers_hid/wiiu_hid.c | 114 +++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index a6cafe552b..b0ac012da4 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -15,6 +15,10 @@ */ #include +#include + +#include +#include #include "../input_defines.h" #include "../input_driver.h" @@ -22,8 +26,31 @@ typedef struct wiiu_hid { void *empty; + uint32_t nsyshid; + HIDClient *client; + HIDAttachCallback attach_callback; } wiiu_hid_t; +typedef struct wiiu_hid_user +{ + unsigned char *buffer; + uint32_t nsishid; + void *hid_read; + void *hid_write; + uint32_t transfersize; +} wiiu_hid_user_t; + +static wiiu_hid_t *new_wiiu_hid_t(void); +static void delete_wiiu_hid_t(wiiu_hid_t *hid); +static HIDClient *new_hidclient(void); +static void delete_hidclient(HIDClient *hid); + +int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); + +/** + * HID driver entrypoints registered with hid_driver_t + */ + static bool wiiu_hid_joypad_query(void *data, unsigned pad) { return pad < MAX_USERS; @@ -73,15 +100,33 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *wiiu_hid_init(void) { - return (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t)); + wiiu_hid_t *hid = new_wiiu_hid_t(); + HIDClient *client = new_hidclient(); + + if(!hid || !client) + goto error; + + HIDAddClient(client, hid->attach_callback); + hid->client = client; + + return hid; + + error: + if(hid) + delete_wiiu_hid_t(hid); + if(client) + free(client); + + return NULL; } static void wiiu_hid_free(void *data) { - wiiu_hid_t *hid_wiiu = (wiiu_hid_t*)data; + wiiu_hid_t *hid = (wiiu_hid_t*)data; - if (hid_wiiu) - free(hid_wiiu); + if (hid) { + delete_wiiu_hid_t(hid); + } } static void wiiu_hid_poll(void *data) @@ -89,6 +134,67 @@ static void wiiu_hid_poll(void *data) (void)data; } +/** + * Callbacks + */ + +int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { + return 0; +} + +static void wiiu_read_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) { +} + +static void wiiu_write_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) { +} + +/** + * Allocation/deallocation + */ + +static wiiu_hid_t *new_wiiu_hid_t(void) { + wiiu_hid_t *hid = (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t)); + + if(!hid) + goto error; + + memset(hid, 0, sizeof(wiiu_hid_t)); + hid->attach_callback = wiiu_attach_callback; + + return hid; + + error: + if(hid) + delete_wiiu_hid_t(hid); + return NULL; +} + +static void delete_wiiu_hid_t(wiiu_hid_t *hid) { + if(!hid) + return; + + if(hid->client) { + HIDDelClient(hid->client); + delete_hidclient(hid->client); + } + + free(hid); +} + +static HIDClient *new_hidclient() { + HIDClient *client = calloc(1, sizeof(HIDClient)); + if(client != NULL) { + memset(client, 0, sizeof(HIDClient)); + } + + return client; +} + +static void delete_hidclient(HIDClient *client) { + if(client) + free(client); +} + hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, From 7e56881b8819cf4c9ad2f27f0ef702034c50c030 Mon Sep 17 00:00:00 2001 From: gblues Date: Sat, 2 Dec 2017 13:48:32 -0800 Subject: [PATCH 03/26] Some cleanups --- input/drivers_hid/wiiu_hid.c | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index b0ac012da4..0ebc7bc772 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -26,18 +26,14 @@ typedef struct wiiu_hid { void *empty; - uint32_t nsyshid; HIDClient *client; - HIDAttachCallback attach_callback; } wiiu_hid_t; typedef struct wiiu_hid_user { - unsigned char *buffer; - uint32_t nsishid; - void *hid_read; - void *hid_write; + uint8_t *buffer; uint32_t transfersize; + uint32_t handle; } wiiu_hid_user_t; static wiiu_hid_t *new_wiiu_hid_t(void); @@ -106,7 +102,7 @@ static void *wiiu_hid_init(void) if(!hid || !client) goto error; - HIDAddClient(client, hid->attach_callback); + HIDAddClient(client, wiiu_attach_callback); hid->client = client; return hid; @@ -139,7 +135,20 @@ static void wiiu_hid_poll(void *data) */ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { - return 0; + switch(attach) { + int32_t result = DEVICE_UNUSED; + case HID_DEVICE_ATTACH: + // TODO: new device attached! Register it. + break; + case HID_DEVICE_DETACH: + // TODO: device detached! Unregister it. + break; + default: + // Undefined behavior, bail out + break; + } + + return result; } static void wiiu_read_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) { @@ -159,7 +168,6 @@ static wiiu_hid_t *new_wiiu_hid_t(void) { goto error; memset(hid, 0, sizeof(wiiu_hid_t)); - hid->attach_callback = wiiu_attach_callback; return hid; @@ -176,6 +184,7 @@ static void delete_wiiu_hid_t(wiiu_hid_t *hid) { if(hid->client) { HIDDelClient(hid->client); delete_hidclient(hid->client); + hid->client = NULL; } free(hid); @@ -195,6 +204,21 @@ static void delete_hidclient(HIDClient *client) { free(client); } +static wiiu_hid_user_t *new_wiiu_hid_user_t(void) { + wiiu_hid_user_t *user = calloc(1, sizeof(wiiu_hid_user_t)); + if(user != NULL) { + memset(client, 0, sizeof(wiiu_hid_user_t)); + } + + return client; +} + +static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user) { + if(user) { + free(user); + } +} + hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, From 1657079c452df8c7fc67008064a46f24a46bdf0a Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 3 Dec 2017 15:52:30 -0800 Subject: [PATCH 04/26] Start implementing HID polling thread == DETAILS Looking at the other HID USB drivers, it looks like the typical implementation is to start up a background thread to do the polling, rather than wait for RA to invoke the poll() method. This commit sets up the skeleton of the background thread: - The thread gets created in init() - The thread gets stopped in free() Right now the body of the thread is a 10ms sleep. == TESTING It compiles cleanly, and links. Don't know if it actually works. --- input/drivers_hid/wiiu_hid.c | 102 ++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 6 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 0ebc7bc772..8466efe573 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include @@ -23,10 +25,18 @@ #include "../input_defines.h" #include "../input_driver.h" +#define POLL_THREAD_SLEEP 10000 + +#define DEVICE_UNUSED 0 +#define DEVICE_USED 1 + typedef struct wiiu_hid { - void *empty; HIDClient *client; + OSThread *polling_thread; + // memory accounting; keep a pointer to the stack buffer so we can clean up later. + void *polling_thread_stack; + volatile bool polling_thread_quit; } wiiu_hid_t; typedef struct wiiu_hid_user @@ -41,7 +51,11 @@ static void delete_wiiu_hid_t(wiiu_hid_t *hid); static HIDClient *new_hidclient(void); static void delete_hidclient(HIDClient *hid); -int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +static void start_polling_thread(wiiu_hid_t *hid); +static void stop_polling_thread(wiiu_hid_t *hid); +static int wiiu_hid_polling_thread(int argc, const char **argv); +static void wiiu_hid_do_poll(wiiu_hid_t *hid); /** * HID driver entrypoints registered with hid_driver_t @@ -102,14 +116,20 @@ static void *wiiu_hid_init(void) if(!hid || !client) goto error; + start_polling_thread(hid); + if(hid->polling_thread == NULL) + goto error; + HIDAddClient(client, wiiu_attach_callback); hid->client = client; return hid; error: - if(hid) + if(hid) { + stop_polling_thread(hid); delete_wiiu_hid_t(hid); + } if(client) free(client); @@ -121,22 +141,92 @@ static void wiiu_hid_free(void *data) wiiu_hid_t *hid = (wiiu_hid_t*)data; if (hid) { + stop_polling_thread(hid); delete_wiiu_hid_t(hid); } } +/** + * This is a no-op because polling is done with a worker thread. + */ static void wiiu_hid_poll(void *data) { (void)data; } +/** + * Implementation functions + */ + +static void start_polling_thread(wiiu_hid_t *hid) { + OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2 | + OS_THREAD_ATTRIB_DETACHED | + OS_THREAD_ATTRIB_STACK_USAGE; + int32_t stack_size = 0x8000; + // wild-ass guess. the patcher thread used 28 for the network threads (10 for BOTW). + int32_t priority = 19; + OSThread *thread = memalign(8, sizeof(OSThread)); + void *stack = memalign(32, stack_size); + + if(!thread || !stack) + goto error; + + if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) + goto error; + + hid->polling_thread = thread; + hid->polling_thread_stack = stack; + return; + + error: + if(stack) + free(stack); + if(thread) + free(thread); + + return; +} + +static void stop_polling_thread(wiiu_hid_t *hid) { + int thread_result = 0; + + if(hid == NULL || hid->polling_thread == NULL) + return; + + hid->polling_thread_quit = true; + OSJoinThread(hid->polling_thread, &thread_result); + + free(hid->polling_thread); + free(hid->polling_thread_stack); +} + +/** + * Entrypoint for the polling thread. + */ +static int wiiu_hid_polling_thread(int argc, const char **argv) { + wiiu_hid_t *hid = (wiiu_hid_t *)argv; + while(!hid->polling_thread_quit) { + wiiu_hid_do_poll(hid); + } + + return 0; +} + +/** + * Only call this from the polling thread. + */ +static void wiiu_hid_do_poll(wiiu_hid_t *hid) { + usleep(POLL_THREAD_SLEEP); +} + /** * Callbacks */ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { + int32_t result = DEVICE_UNUSED; + switch(attach) { - int32_t result = DEVICE_UNUSED; case HID_DEVICE_ATTACH: // TODO: new device attached! Register it. break; @@ -207,10 +297,10 @@ static void delete_hidclient(HIDClient *client) { static wiiu_hid_user_t *new_wiiu_hid_user_t(void) { wiiu_hid_user_t *user = calloc(1, sizeof(wiiu_hid_user_t)); if(user != NULL) { - memset(client, 0, sizeof(wiiu_hid_user_t)); + memset(user, 0, sizeof(wiiu_hid_user_t)); } - return client; + return user; } static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user) { From 203876a206fdc06631c9f9e92d71b1b98e013a9f Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 3 Dec 2017 22:42:23 -0800 Subject: [PATCH 05/26] More progress on the HID driver == DETAILS I think I've about got the thread startup/teardown code worked out. Logically, anyway, if not accurately. The challenge has been figuring out how best to integrate the features of HID2VPAD. I found `input/connect/joypad_connection.c` and this seems like the logical place for: - Special-case driver for the Switch Pro controller - Any other special cases HIDTOVPAD supports that core RetroArch doesn't - Parsing of HIDTOVPAD config file to add custom button mapping == TESTING Compiles. Haven't tested with a real Wii U. Probably doesn't work though. I very likely have the threading bit wrong. --- input/drivers_hid/wiiu_hid.c | 99 +++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 8466efe573..5b61d63bd0 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2013-2014 - Jason Fetters * Copyright (C) 2011-2017 - Daniel De Matteis - * + * * RetroArch 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 Found- * ation, either version 3 of the License, or (at your option) any later version. @@ -30,26 +30,41 @@ #define DEVICE_UNUSED 0 #define DEVICE_USED 1 +typedef struct wiiu_hid_user wiiu_hid_user_t; + +struct wiiu_hid_user +{ + wiiu_hid_user_t *next; + uint8_t *buffer; + uint32_t transfersize; + uint32_t handle; +}; + typedef struct wiiu_hid { HIDClient *client; OSThread *polling_thread; // memory accounting; keep a pointer to the stack buffer so we can clean up later. void *polling_thread_stack; + // setting this to true tells the polling thread to quit volatile bool polling_thread_quit; } wiiu_hid_t; -typedef struct wiiu_hid_user -{ - uint8_t *buffer; - uint32_t transfersize; - uint32_t handle; -} wiiu_hid_user_t; +/* + * The attach/detach callback has no access to the wiiu_hid_t object. Therefore, we need a + * global place to handle device data. + */ +static wiiu_hid_user_t *pad_list = NULL; +static OSFastMutex *pad_list_mutex; static wiiu_hid_t *new_wiiu_hid_t(void); static void delete_wiiu_hid_t(wiiu_hid_t *hid); +static wiiu_hid_user_t *new_wiiu_hid_user_t(void); +static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user); static HIDClient *new_hidclient(void); static void delete_hidclient(HIDClient *hid); +static OSFastMutex *new_fastmutex(const char *name); +static void delete_fastmutex(OSFastMutex *mutex); static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); static void start_polling_thread(wiiu_hid_t *hid); @@ -57,6 +72,8 @@ static void stop_polling_thread(wiiu_hid_t *hid); static int wiiu_hid_polling_thread(int argc, const char **argv); static void wiiu_hid_do_poll(wiiu_hid_t *hid); +static void enqueue_device(void); + /** * HID driver entrypoints registered with hid_driver_t */ @@ -131,7 +148,11 @@ static void *wiiu_hid_init(void) delete_wiiu_hid_t(hid); } if(client) - free(client); + delete_hidclient(client); + if(pad_list_mutex) { + delete_fastmutex(pad_list_mutex); + pad_list_mutex = NULL; + } return NULL; } @@ -146,6 +167,16 @@ static void wiiu_hid_free(void *data) } } +static void free_pad_list(void) { + wiiu_hid_user_t *top; + + while(pad_list != NULL) { + top = pad_list; + pad_list = top->next; + delete_wiiu_hid_user_t(top); + } +} + /** * This is a no-op because polling is done with a worker thread. */ @@ -168,7 +199,11 @@ static void start_polling_thread(wiiu_hid_t *hid) { OSThread *thread = memalign(8, sizeof(OSThread)); void *stack = memalign(32, stack_size); - if(!thread || !stack) + if(pad_list_mutex == NULL) { + pad_list_mutex = new_fastmutex("pad_list"); + } + + if(!thread || !stack || !pad_list_mutex) goto error; if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) @@ -179,6 +214,8 @@ static void start_polling_thread(wiiu_hid_t *hid) { return; error: + if(pad_list_mutex) + delete_fastmutex(pad_list_mutex); if(stack) free(stack); if(thread) @@ -198,6 +235,11 @@ static void stop_polling_thread(wiiu_hid_t *hid) { free(hid->polling_thread); free(hid->polling_thread_stack); + + // with the thread stopped, we don't need the mutex. + delete_fastmutex(pad_list_mutex); + pad_list_mutex = NULL; + free_pad_list(); } /** @@ -219,6 +261,23 @@ static void wiiu_hid_do_poll(wiiu_hid_t *hid) { usleep(POLL_THREAD_SLEEP); } +int32_t wiiu_attach_device(HIDClient *client, HIDDevice *device) { + wiiu_hid_user_t *adapter = new_wiiu_hid_user_t(); + + if(!adapter) + goto error; + + error: + if(adapter) { + delete_wiiu_hid_user_t(adapter); + } + return DEVICE_UNUSED; +} + +int32_t wiiu_detach_device(HIDClient *client, HIDDevice *device) { + return DEVICE_UNUSED; +} + /** * Callbacks */ @@ -228,10 +287,10 @@ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t atta switch(attach) { case HID_DEVICE_ATTACH: - // TODO: new device attached! Register it. + result = wiiu_attach_device(client, device); break; case HID_DEVICE_DETACH: - // TODO: device detached! Unregister it. + result = wiiu_detach_device(client, device); break; default: // Undefined behavior, bail out @@ -280,7 +339,7 @@ static void delete_wiiu_hid_t(wiiu_hid_t *hid) { free(hid); } -static HIDClient *new_hidclient() { +static HIDClient *new_hidclient(void) { HIDClient *client = calloc(1, sizeof(HIDClient)); if(client != NULL) { memset(client, 0, sizeof(HIDClient)); @@ -289,6 +348,17 @@ static HIDClient *new_hidclient() { return client; } +static OSFastMutex *new_fastmutex(const char *name) { + OSFastMutex *mutex = calloc(1, sizeof(OSFastMutex)); + if(mutex != NULL) { + memset(mutex, 0, sizeof(OSFastMutex)); + } + + OSFastMutex_Init(mutex, name); + + return mutex; +} + static void delete_hidclient(HIDClient *client) { if(client) free(client); @@ -309,6 +379,11 @@ static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user) { } } +static void delete_fastmutex(OSFastMutex *mutex) { + if(mutex) + free(mutex); +} + hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, From c3736adb7747b43c11391797af0df9e961837be6 Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 3 Dec 2017 15:52:30 -0800 Subject: [PATCH 06/26] Start implementing HID polling thread == DETAILS Looking at the other HID USB drivers, it looks like the typical implementation is to start up a background thread to do the polling, rather than wait for RA to invoke the poll() method. This commit sets up the skeleton of the background thread: - The thread gets created in init() - The thread gets stopped in free() Right now the body of the thread is a 10ms sleep. == TESTING It compiles cleanly, and links. Don't know if it actually works. --- input/drivers_hid/wiiu_hid.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 5b61d63bd0..4a3a1abde4 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -26,6 +26,21 @@ #include "../input_driver.h" #define POLL_THREAD_SLEEP 10000 +<<<<<<< HEAD +======= + +#define DEVICE_UNUSED 0 +#define DEVICE_USED 1 + +typedef struct wiiu_hid +{ + HIDClient *client; + OSThread *polling_thread; + // memory accounting; keep a pointer to the stack buffer so we can clean up later. + void *polling_thread_stack; + volatile bool polling_thread_quit; +} wiiu_hid_t; +>>>>>>> Start implementing HID polling thread #define DEVICE_UNUSED 0 #define DEVICE_USED 1 @@ -71,8 +86,11 @@ static void start_polling_thread(wiiu_hid_t *hid); static void stop_polling_thread(wiiu_hid_t *hid); static int wiiu_hid_polling_thread(int argc, const char **argv); static void wiiu_hid_do_poll(wiiu_hid_t *hid); +<<<<<<< HEAD static void enqueue_device(void); +======= +>>>>>>> Start implementing HID polling thread /** * HID driver entrypoints registered with hid_driver_t @@ -167,6 +185,7 @@ static void wiiu_hid_free(void *data) } } +<<<<<<< HEAD static void free_pad_list(void) { wiiu_hid_user_t *top; @@ -177,6 +196,8 @@ static void free_pad_list(void) { } } +======= +>>>>>>> Start implementing HID polling thread /** * This is a no-op because polling is done with a worker thread. */ @@ -199,11 +220,15 @@ static void start_polling_thread(wiiu_hid_t *hid) { OSThread *thread = memalign(8, sizeof(OSThread)); void *stack = memalign(32, stack_size); +<<<<<<< HEAD if(pad_list_mutex == NULL) { pad_list_mutex = new_fastmutex("pad_list"); } if(!thread || !stack || !pad_list_mutex) +======= + if(!thread || !stack) +>>>>>>> Start implementing HID polling thread goto error; if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) @@ -214,8 +239,11 @@ static void start_polling_thread(wiiu_hid_t *hid) { return; error: +<<<<<<< HEAD if(pad_list_mutex) delete_fastmutex(pad_list_mutex); +======= +>>>>>>> Start implementing HID polling thread if(stack) free(stack); if(thread) @@ -235,11 +263,14 @@ static void stop_polling_thread(wiiu_hid_t *hid) { free(hid->polling_thread); free(hid->polling_thread_stack); +<<<<<<< HEAD // with the thread stopped, we don't need the mutex. delete_fastmutex(pad_list_mutex); pad_list_mutex = NULL; free_pad_list(); +======= +>>>>>>> Start implementing HID polling thread } /** @@ -261,6 +292,7 @@ static void wiiu_hid_do_poll(wiiu_hid_t *hid) { usleep(POLL_THREAD_SLEEP); } +<<<<<<< HEAD int32_t wiiu_attach_device(HIDClient *client, HIDDevice *device) { wiiu_hid_user_t *adapter = new_wiiu_hid_user_t(); @@ -278,6 +310,8 @@ int32_t wiiu_detach_device(HIDClient *client, HIDDevice *device) { return DEVICE_UNUSED; } +======= +>>>>>>> Start implementing HID polling thread /** * Callbacks */ From 5c5e5be649006b690c09a059d5e95919f2cea5a9 Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 3 Dec 2017 22:42:23 -0800 Subject: [PATCH 07/26] More progress on the HID driver == DETAILS I think I've about got the thread startup/teardown code worked out. Logically, anyway, if not accurately. The challenge has been figuring out how best to integrate the features of HID2VPAD. I found `input/connect/joypad_connection.c` and this seems like the logical place for: - Special-case driver for the Switch Pro controller - Any other special cases HIDTOVPAD supports that core RetroArch doesn't - Parsing of HIDTOVPAD config file to add custom button mapping == TESTING Compiles. Haven't tested with a real Wii U. Probably doesn't work though. I very likely have the threading bit wrong. --- input/drivers_hid/wiiu_hid.c | 71 +++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 4a3a1abde4..7228e1a987 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -32,19 +32,6 @@ #define DEVICE_UNUSED 0 #define DEVICE_USED 1 -typedef struct wiiu_hid -{ - HIDClient *client; - OSThread *polling_thread; - // memory accounting; keep a pointer to the stack buffer so we can clean up later. - void *polling_thread_stack; - volatile bool polling_thread_quit; -} wiiu_hid_t; ->>>>>>> Start implementing HID polling thread - -#define DEVICE_UNUSED 0 -#define DEVICE_USED 1 - typedef struct wiiu_hid_user wiiu_hid_user_t; struct wiiu_hid_user @@ -64,7 +51,34 @@ typedef struct wiiu_hid // setting this to true tells the polling thread to quit volatile bool polling_thread_quit; } wiiu_hid_t; +>>>>>>> Start implementing HID polling thread +#define DEVICE_UNUSED 0 +#define DEVICE_USED 1 + +typedef struct wiiu_hid_user wiiu_hid_user_t; + +<<<<<<< HEAD +struct wiiu_hid_user +{ + wiiu_hid_user_t *next; + uint8_t *buffer; + uint32_t transfersize; + uint32_t handle; +}; + +typedef struct wiiu_hid +{ + HIDClient *client; + OSThread *polling_thread; + // memory accounting; keep a pointer to the stack buffer so we can clean up later. + void *polling_thread_stack; + // setting this to true tells the polling thread to quit + volatile bool polling_thread_quit; +} wiiu_hid_t; + +======= +>>>>>>> More progress on the HID driver /* * The attach/detach callback has no access to the wiiu_hid_t object. Therefore, we need a * global place to handle device data. @@ -92,6 +106,8 @@ static void enqueue_device(void); ======= >>>>>>> Start implementing HID polling thread +static void enqueue_device(void); + /** * HID driver entrypoints registered with hid_driver_t */ @@ -186,6 +202,9 @@ static void wiiu_hid_free(void *data) } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> More progress on the HID driver static void free_pad_list(void) { wiiu_hid_user_t *top; @@ -196,8 +215,11 @@ static void free_pad_list(void) { } } +<<<<<<< HEAD ======= >>>>>>> Start implementing HID polling thread +======= +>>>>>>> More progress on the HID driver /** * This is a no-op because polling is done with a worker thread. */ @@ -221,14 +243,20 @@ static void start_polling_thread(wiiu_hid_t *hid) { void *stack = memalign(32, stack_size); <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> More progress on the HID driver if(pad_list_mutex == NULL) { pad_list_mutex = new_fastmutex("pad_list"); } if(!thread || !stack || !pad_list_mutex) +<<<<<<< HEAD ======= if(!thread || !stack) >>>>>>> Start implementing HID polling thread +======= +>>>>>>> More progress on the HID driver goto error; if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) @@ -239,11 +267,16 @@ static void start_polling_thread(wiiu_hid_t *hid) { return; error: +<<<<<<< HEAD <<<<<<< HEAD if(pad_list_mutex) delete_fastmutex(pad_list_mutex); ======= >>>>>>> Start implementing HID polling thread +======= + if(pad_list_mutex) + delete_fastmutex(pad_list_mutex); +>>>>>>> More progress on the HID driver if(stack) free(stack); if(thread) @@ -264,13 +297,19 @@ static void stop_polling_thread(wiiu_hid_t *hid) { free(hid->polling_thread); free(hid->polling_thread_stack); <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> More progress on the HID driver // with the thread stopped, we don't need the mutex. delete_fastmutex(pad_list_mutex); pad_list_mutex = NULL; free_pad_list(); +<<<<<<< HEAD ======= >>>>>>> Start implementing HID polling thread +======= +>>>>>>> More progress on the HID driver } /** @@ -293,6 +332,9 @@ static void wiiu_hid_do_poll(wiiu_hid_t *hid) { } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> More progress on the HID driver int32_t wiiu_attach_device(HIDClient *client, HIDDevice *device) { wiiu_hid_user_t *adapter = new_wiiu_hid_user_t(); @@ -310,8 +352,11 @@ int32_t wiiu_detach_device(HIDClient *client, HIDDevice *device) { return DEVICE_UNUSED; } +<<<<<<< HEAD ======= >>>>>>> Start implementing HID polling thread +======= +>>>>>>> More progress on the HID driver /** * Callbacks */ From d0368124e6e69ae6b5158b9adcde298d99ef2c93 Mon Sep 17 00:00:00 2001 From: gblues Date: Tue, 5 Dec 2017 20:43:49 -0800 Subject: [PATCH 08/26] Add OSFastMutex WiiU calls to list of imports --- wiiu/system/imports.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wiiu/system/imports.h b/wiiu/system/imports.h index 866382c1de..11dc810352 100644 --- a/wiiu/system/imports.h +++ b/wiiu/system/imports.h @@ -16,6 +16,9 @@ IMPORT(OSSignalCond); IMPORT(OSInitSpinLock); IMPORT(OSUninterruptibleSpinLock_Acquire); IMPORT(OSUninterruptibleSpinLock_Release); +IMPORT(OSFastMutex_Init); +IMPORT(OSFastMutex_Lock); +IMPORT(OSFastMutex_Unlock); IMPORT(OSSleepTicks); IMPORT(OSGetTitleID); IMPORT(OSIsThreadTerminated); From 1beba28d02ebe4a919afa5ea8ae65bbcdef18366 Mon Sep 17 00:00:00 2001 From: gblues Date: Wed, 6 Dec 2017 22:33:14 -0800 Subject: [PATCH 09/26] Only call HIDSetup/HidTeardown once == DETAILS I did a minimalist edit of the HID thread that stripped out all HID* syscalls, and this stopped the crashing. I then re-added just the HIDSetup() and HIDTeardown() calls, and the crash came back. This smells like an OS bug. To work around it, I've put the HIDSetup() and HIDTeardown() calls into the app init/shutdown section, so they only get called once in the application lifetime and not each time the input driver is initialized. --- frontend/drivers/platform_wiiu.c | 9 +- input/drivers_hid/wiiu_hid.c | 160 +++++++++++++---------------- input/drivers_joypad/wiiu_joypad.c | 8 ++ input/input_driver.c | 13 ++- input/input_driver.h | 1 + 5 files changed, 100 insertions(+), 91 deletions(-) diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index a188ebb3f0..ce1866a5fd 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -49,7 +49,7 @@ #include "system/memory.h" #include "system/exception_handler.h" #include - +#include #include #include #include @@ -641,9 +641,16 @@ void _start(int argc, char **argv) memoryInitialize(); __init(); fsdev_init(); +#ifdef HAVE_HID + HIDSetup(); +#endif main(argc, argv); +#ifdef HAVE_HID + HIDTeardown(); +#endif + fsdev_exit(); /* TODO: fix elf2rpl so it doesn't error with "Could not find matching symbol diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 7228e1a987..dd6af87ff4 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -24,6 +24,8 @@ #include "../input_defines.h" #include "../input_driver.h" +#include "../connect/joypad_connection.h" +#include "../../verbosity.h" #define POLL_THREAD_SLEEP 10000 <<<<<<< HEAD @@ -37,9 +39,18 @@ typedef struct wiiu_hid_user wiiu_hid_user_t; struct wiiu_hid_user { wiiu_hid_user_t *next; - uint8_t *buffer; - uint32_t transfersize; + uint8_t *send_control_buffer; + uint8_t *send_control_type; + uint32_t handle; + uint32_t physical_device_inst; + uint16_t vid; + uint16_t pid; + uint8_t interface_index; + uint8_t sub_class; + uint8_t protocol; + uint16_t max_packet_size_rx; + uint16_t max_packet_size_tx; }; typedef struct wiiu_hid @@ -53,6 +64,7 @@ typedef struct wiiu_hid } wiiu_hid_t; >>>>>>> Start implementing HID polling thread +<<<<<<< HEAD #define DEVICE_UNUSED 0 #define DEVICE_USED 1 @@ -96,6 +108,9 @@ static OSFastMutex *new_fastmutex(const char *name); static void delete_fastmutex(OSFastMutex *mutex); static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +======= +//static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +>>>>>>> Only call HIDSetup/HidTeardown once static void start_polling_thread(wiiu_hid_t *hid); static void stop_polling_thread(wiiu_hid_t *hid); static int wiiu_hid_polling_thread(int argc, const char **argv); @@ -106,7 +121,10 @@ static void enqueue_device(void); ======= >>>>>>> Start implementing HID polling thread -static void enqueue_device(void); +//HIDClient *new_hidclient(void); +//void delete_hidclient(HIDClient *client); +wiiu_hid_t *new_hid(void); +void delete_hid(wiiu_hid_t *hid); /** * HID driver entrypoints registered with hid_driver_t @@ -119,7 +137,7 @@ static bool wiiu_hid_joypad_query(void *data, unsigned pad) static const char *wiiu_hid_joypad_name(void *data, unsigned pad) { - return NULL; + return NULL; } static uint64_t wiiu_hid_joypad_get_buttons(void *data, unsigned port) @@ -161,32 +179,30 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *wiiu_hid_init(void) { - wiiu_hid_t *hid = new_wiiu_hid_t(); - HIDClient *client = new_hidclient(); + wiiu_hid_t *hid = new_hid(); +// HIDClient *client = new_hidclient(); - if(!hid || !client) +// if(!hid || !client) + if(!hid) goto error; start_polling_thread(hid); if(hid->polling_thread == NULL) goto error; - HIDAddClient(client, wiiu_attach_callback); - hid->client = client; +// HIDAddClient(client, wiiu_attach_callback); +// hid->client = client; return hid; error: if(hid) { stop_polling_thread(hid); - delete_wiiu_hid_t(hid); - } - if(client) - delete_hidclient(client); - if(pad_list_mutex) { - delete_fastmutex(pad_list_mutex); - pad_list_mutex = NULL; + delete_hid(hid); } +// if(client) { +// delete_hidclient(client); +// } return NULL; } @@ -197,6 +213,7 @@ static void wiiu_hid_free(void *data) if (hid) { stop_polling_thread(hid); +<<<<<<< HEAD delete_wiiu_hid_t(hid); } } @@ -212,6 +229,9 @@ static void free_pad_list(void) { top = pad_list; pad_list = top->next; delete_wiiu_hid_user_t(top); +======= + delete_hid(hid); +>>>>>>> Only call HIDSetup/HidTeardown once } } @@ -234,14 +254,14 @@ static void wiiu_hid_poll(void *data) static void start_polling_thread(wiiu_hid_t *hid) { OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2 | - OS_THREAD_ATTRIB_DETACHED | OS_THREAD_ATTRIB_STACK_USAGE; int32_t stack_size = 0x8000; // wild-ass guess. the patcher thread used 28 for the network threads (10 for BOTW). - int32_t priority = 19; + int32_t priority = 10; OSThread *thread = memalign(8, sizeof(OSThread)); void *stack = memalign(32, stack_size); +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD ======= @@ -257,6 +277,9 @@ static void start_polling_thread(wiiu_hid_t *hid) { >>>>>>> Start implementing HID polling thread ======= >>>>>>> More progress on the HID driver +======= + if(!thread || !stack) +>>>>>>> Only call HIDSetup/HidTeardown once goto error; if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) @@ -268,6 +291,7 @@ static void start_polling_thread(wiiu_hid_t *hid) { error: <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD if(pad_list_mutex) delete_fastmutex(pad_list_mutex); @@ -277,6 +301,8 @@ static void start_polling_thread(wiiu_hid_t *hid) { if(pad_list_mutex) delete_fastmutex(pad_list_mutex); >>>>>>> More progress on the HID driver +======= +>>>>>>> Only call HIDSetup/HidTeardown once if(stack) free(stack); if(thread) @@ -298,6 +324,7 @@ static void stop_polling_thread(wiiu_hid_t *hid) { free(hid->polling_thread_stack); <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> More progress on the HID driver @@ -310,6 +337,8 @@ static void stop_polling_thread(wiiu_hid_t *hid) { >>>>>>> Start implementing HID polling thread ======= >>>>>>> More progress on the HID driver +======= +>>>>>>> Only call HIDSetup/HidTeardown once } /** @@ -331,6 +360,7 @@ static void wiiu_hid_do_poll(wiiu_hid_t *hid) { usleep(POLL_THREAD_SLEEP); } +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD ======= @@ -357,19 +387,21 @@ int32_t wiiu_detach_device(HIDClient *client, HIDDevice *device) { >>>>>>> Start implementing HID polling thread ======= >>>>>>> More progress on the HID driver +======= +>>>>>>> Only call HIDSetup/HidTeardown once /** * Callbacks */ - +/* int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { int32_t result = DEVICE_UNUSED; switch(attach) { case HID_DEVICE_ATTACH: - result = wiiu_attach_device(client, device); + RARCH_LOG("Device attached\n"); break; case HID_DEVICE_DETACH: - result = wiiu_detach_device(client, device); + RARCH_LOG("Device detached\n"); break; default: // Undefined behavior, bail out @@ -378,91 +410,41 @@ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t atta return result; } - -static void wiiu_read_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) { -} - -static void wiiu_write_callback(uint32_t handle, int32_t errno, unsigned char *buffer, uint32_t transferred, void *usr) { -} - +*/ /** - * Allocation/deallocation + * Allocation */ -static wiiu_hid_t *new_wiiu_hid_t(void) { - wiiu_hid_t *hid = (wiiu_hid_t*)calloc(1, sizeof(wiiu_hid_t)); - - if(!hid) - goto error; - - memset(hid, 0, sizeof(wiiu_hid_t)); +wiiu_hid_t *new_hid(void) { + wiiu_hid_t *hid = calloc(1, sizeof(wiiu_hid_t)); + if(hid) + memset(hid, 0, sizeof(wiiu_hid_t)); return hid; - - error: - if(hid) - delete_wiiu_hid_t(hid); - return NULL; } -static void delete_wiiu_hid_t(wiiu_hid_t *hid) { - if(!hid) - return; +void delete_hid(wiiu_hid_t *hid) { + if(hid) { + if(hid->polling_thread_stack) + free(hid->polling_thread_stack); - if(hid->client) { - HIDDelClient(hid->client); - delete_hidclient(hid->client); - hid->client = NULL; + free(hid); } - - free(hid); } - -static HIDClient *new_hidclient(void) { - HIDClient *client = calloc(1, sizeof(HIDClient)); - if(client != NULL) { +/* +HIDClient *new_hidclient(void) { + HIDClient *client = memalign(32, sizeof(HIDClient)); + if(client) memset(client, 0, sizeof(HIDClient)); - } return client; } -static OSFastMutex *new_fastmutex(const char *name) { - OSFastMutex *mutex = calloc(1, sizeof(OSFastMutex)); - if(mutex != NULL) { - memset(mutex, 0, sizeof(OSFastMutex)); - } - - OSFastMutex_Init(mutex, name); - - return mutex; -} - -static void delete_hidclient(HIDClient *client) { +void delete_hidclient(HIDClient *client) { if(client) free(client); } - -static wiiu_hid_user_t *new_wiiu_hid_user_t(void) { - wiiu_hid_user_t *user = calloc(1, sizeof(wiiu_hid_user_t)); - if(user != NULL) { - memset(user, 0, sizeof(wiiu_hid_user_t)); - } - - return user; -} - -static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user) { - if(user) { - free(user); - } -} - -static void delete_fastmutex(OSFastMutex *mutex) { - if(mutex) - free(mutex); -} - +*/ hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, @@ -473,5 +455,5 @@ hid_driver_t wiiu_hid = { wiiu_hid_poll, wiiu_hid_joypad_rumble, wiiu_hid_joypad_name, - "wiiu", + "wiiu_usb", }; diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 4fb667c34d..3a08305c37 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -43,6 +43,8 @@ #define GAMEPAD_OFFSET 0 +static const hid_driver_t *hid_driver = NULL; + static uint64_t pad_state[MAX_PADS]; static uint8_t pad_type[MAX_PADS-1] = {WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE}; @@ -299,6 +301,7 @@ static void wiiu_joypad_poll(void) static bool wiiu_joypad_init(void* data) { + hid_driver = input_hid_init_first(); wiiu_joypad_autodetect_add(0); wiiu_joypad_poll(); @@ -315,6 +318,11 @@ static bool wiiu_joypad_query_pad(unsigned pad) static void wiiu_joypad_destroy(void) { + if(hid_driver) { + hid_driver->free(hid_driver_get_data()); + hid_driver_reset_data(); + hid_driver = NULL; + } wiiu_pad_inited = false; } diff --git a/input/input_driver.c b/input/input_driver.c index 6dc5d6908d..f0d63cbb46 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -176,7 +176,10 @@ static input_device_driver_t *joypad_drivers[] = { #ifdef DJGPP &dos_joypad, #endif -#ifdef HAVE_HID +// Selecting the HID gamepad driver disables the Wii U gamepad. So while +// we want the HID code to be compiled & linked, we don't want the driver +// to be selectable in the UI. +#if defined(HAVE_HID) && !defined(WIIU) &hid_joypad, #endif &null_joypad, @@ -1829,6 +1832,14 @@ const void *hid_driver_get_data(void) return hid_data; } +// This is only to be called after we've invoked free() on the +// HID driver; the memory will have already been freed, so we need to +// reset the pointer. +void hid_driver_reset_data(void) +{ + hid_data = NULL; +} + /** * hid_driver_find_ident: * @idx : index of driver to get handle to. diff --git a/input/input_driver.h b/input/input_driver.h index dcc7c0df2b..bffc934816 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -647,6 +647,7 @@ const char* config_get_hid_driver_options(void); const hid_driver_t *input_hid_init_first(void); const void *hid_driver_get_data(void); +void hid_driver_reset_data(void); #endif /** Line complete callback. From 192f5875b970d9c27e65daafdaf79948876550ba Mon Sep 17 00:00:00 2001 From: gblues Date: Fri, 8 Dec 2017 19:58:04 -0800 Subject: [PATCH 10/26] Simplify, add logging, revert some of the changes == DETAILS The old code was crashing; I did a minimalized branch and the crash went away, so I'm bringing that over here. Meaning I'll have to redo some of the other work I'd put in, but oh well. (now watch it start crashing again) == TESTING Can confirm it builds. Wii U is busy ATM so I can't test. --- Makefile.wiiu | 4 +- frontend/drivers/platform_wiiu.c | 9 -- input/drivers_hid/wiiu_hid.c | 213 ++++++++++++++++++++++++------- wiiu/net_listen.sh | 18 +-- 4 files changed, 180 insertions(+), 64 deletions(-) diff --git a/Makefile.wiiu b/Makefile.wiiu index cd2bdad24e..4f8dfa3e9b 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -10,8 +10,8 @@ ifneq ($(V), 1) Q := @ endif -PC_DEVELOPMENT_IP_ADDRESS ?= -PC_DEVELOPMENT_TCP_PORT ?= +PC_DEVELOPMENT_IP_ADDRESS ?=192.168.29.137 +PC_DEVELOPMENT_TCP_PORT ?=4405 OBJ := OBJ += input/drivers_hid/wiiu_hid.o diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index ce1866a5fd..84b4c5bdc0 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -641,16 +641,7 @@ void _start(int argc, char **argv) memoryInitialize(); __init(); fsdev_init(); -#ifdef HAVE_HID - HIDSetup(); -#endif - main(argc, argv); - -#ifdef HAVE_HID - HIDTeardown(); -#endif - fsdev_exit(); /* TODO: fix elf2rpl so it doesn't error with "Could not find matching symbol diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index dd6af87ff4..d10c20880c 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -14,19 +14,17 @@ * If not, see . */ -#include #include #include #include - #include #include #include "../input_defines.h" #include "../input_driver.h" -#include "../connect/joypad_connection.h" #include "../../verbosity.h" +<<<<<<< HEAD #define POLL_THREAD_SLEEP 10000 <<<<<<< HEAD ======= @@ -78,17 +76,21 @@ struct wiiu_hid_user uint32_t transfersize; uint32_t handle; }; +======= +#define DEVICE_UNUSED 0 +#define DEVICE_USED 1 +#define ALIGN_POINTER sizeof(void *) +>>>>>>> Simplify, add logging, revert some of the changes typedef struct wiiu_hid { - HIDClient *client; - OSThread *polling_thread; - // memory accounting; keep a pointer to the stack buffer so we can clean up later. - void *polling_thread_stack; - // setting this to true tells the polling thread to quit - volatile bool polling_thread_quit; + HIDClient *client; + OSThread *polling_thread; + void *polling_thread_stack; + volatile bool polling_thread_quit; } wiiu_hid_t; +<<<<<<< HEAD ======= >>>>>>> More progress on the HID driver /* @@ -102,11 +104,15 @@ static wiiu_hid_t *new_wiiu_hid_t(void); static void delete_wiiu_hid_t(wiiu_hid_t *hid); static wiiu_hid_user_t *new_wiiu_hid_user_t(void); static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user); +======= +void *alloc_zeroed(size_t alignment, size_t size); +static wiiu_hid_t *new_hid(void); +static void delete_hid(wiiu_hid_t *hid); +static void delete_hidclient(HIDClient *client); +>>>>>>> Simplify, add logging, revert some of the changes static HIDClient *new_hidclient(void); -static void delete_hidclient(HIDClient *hid); -static OSFastMutex *new_fastmutex(const char *name); -static void delete_fastmutex(OSFastMutex *mutex); +<<<<<<< HEAD static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); ======= //static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); @@ -129,6 +135,12 @@ void delete_hid(wiiu_hid_t *hid); /** * HID driver entrypoints registered with hid_driver_t */ +======= +static void start_polling_thread(wiiu_hid_t *hid); +static void stop_polling_thread(wiiu_hid_t *hid); +static int wiiu_hid_polling_thread(int argc, const char **argv); +static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +>>>>>>> Simplify, add logging, revert some of the changes static bool wiiu_hid_joypad_query(void *data, unsigned pad) { @@ -137,15 +149,19 @@ static bool wiiu_hid_joypad_query(void *data, unsigned pad) static const char *wiiu_hid_joypad_name(void *data, unsigned pad) { - return NULL; + /* TODO/FIXME - implement properly */ + if (pad >= MAX_USERS) + return NULL; + + return NULL; } -static uint64_t wiiu_hid_joypad_get_buttons(void *data, unsigned port) +static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state) { (void)data; (void)port; - return 0; + BIT256_CLEAR_ALL_PTR(state); } static bool wiiu_hid_joypad_button(void *data, unsigned port, uint16_t joykey) @@ -179,6 +195,7 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *wiiu_hid_init(void) { +<<<<<<< HEAD wiiu_hid_t *hid = new_hid(); // HIDClient *client = new_hidclient(); @@ -205,10 +222,35 @@ static void *wiiu_hid_init(void) // } return NULL; +======= + HIDSetup(); + wiiu_hid_t *hid = new_hid(); + HIDClient *client = new_hidclient(); + if(!hid || !client) { + goto error; + } + + start_polling_thread(hid); + if(!hid->polling_thread) + goto error; + + HIDAddClient(client, wiiu_attach_callback); + hid->client = client; + + return hid; + + error: + RARCH_LOG("[hid]: initialization failed. cleaning up.\n"); + stop_polling_thread(hid); + delete_hid(hid); + delete_hidclient(client); + return NULL; +>>>>>>> Simplify, add logging, revert some of the changes } static void wiiu_hid_free(void *data) { +<<<<<<< HEAD wiiu_hid_t *hid = (wiiu_hid_t*)data; if (hid) { @@ -243,24 +285,35 @@ static void free_pad_list(void) { /** * This is a no-op because polling is done with a worker thread. */ +======= + wiiu_hid_t *hid = (wiiu_hid_t*)data; + + if (hid) { + stop_polling_thread(hid); + delete_hidclient(hid->client); + delete_hid(hid); + } + HIDTeardown(); +} + +>>>>>>> Simplify, add logging, revert some of the changes static void wiiu_hid_poll(void *data) { (void)data; } -/** - * Implementation functions - */ - static void start_polling_thread(wiiu_hid_t *hid) { + RARCH_LOG("[hid]: starting polling thread.\n"); OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2 | OS_THREAD_ATTRIB_STACK_USAGE; - int32_t stack_size = 0x8000; - // wild-ass guess. the patcher thread used 28 for the network threads (10 for BOTW). - int32_t priority = 10; - OSThread *thread = memalign(8, sizeof(OSThread)); - void *stack = memalign(32, stack_size); + BOOL result; + int32_t stack_size = 0x8000; + int32_t priority = 10; + OSThread *thread = memalign(ALIGN_POINTER, sizeof(OSThread)); + void *stack = memalign(ALIGN_POINTER, stack_size); + +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD @@ -281,9 +334,19 @@ static void start_polling_thread(wiiu_hid_t *hid) { if(!thread || !stack) >>>>>>> Only call HIDSetup/HidTeardown once goto error; - - if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) +======= + if(!thread || !stack) { + RARCH_LOG("[hid]: allocation failed, aborting thread start.\n"); goto error; + } + + RARCH_LOG("[hid]: thread = %x; stack = %x\n", thread, stack); +>>>>>>> Simplify, add logging, revert some of the changes + + if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) { + RARCH_LOG("[hid]: OSCreateThread failed.\n"); + goto error; + } hid->polling_thread = thread; hid->polling_thread_stack = stack; @@ -292,6 +355,7 @@ static void start_polling_thread(wiiu_hid_t *hid) { error: <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD if(pad_list_mutex) delete_fastmutex(pad_list_mutex); @@ -305,26 +369,32 @@ static void start_polling_thread(wiiu_hid_t *hid) { >>>>>>> Only call HIDSetup/HidTeardown once if(stack) free(stack); +======= +>>>>>>> Simplify, add logging, revert some of the changes if(thread) free(thread); + if(stack) + free(stack); return; } + static void stop_polling_thread(wiiu_hid_t *hid) { int thread_result = 0; + RARCH_LOG("[hid]: stopping polling thread.\n"); - if(hid == NULL || hid->polling_thread == NULL) + if(!hid || !hid->polling_thread) return; hid->polling_thread_quit = true; OSJoinThread(hid->polling_thread, &thread_result); - free(hid->polling_thread); free(hid->polling_thread_stack); <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> More progress on the HID driver @@ -339,17 +409,18 @@ static void stop_polling_thread(wiiu_hid_t *hid) { >>>>>>> More progress on the HID driver ======= >>>>>>> Only call HIDSetup/HidTeardown once +======= + hid->polling_thread = NULL; + hid->polling_thread_stack = NULL; +>>>>>>> Simplify, add logging, revert some of the changes } -/** - * Entrypoint for the polling thread. - */ -static int wiiu_hid_polling_thread(int argc, const char **argv) { - wiiu_hid_t *hid = (wiiu_hid_t *)argv; - while(!hid->polling_thread_quit) { - wiiu_hid_do_poll(hid); +void log_device(HIDDevice *device) { + if(!device) { + RARCH_LOG("NULL device.\n"); } +<<<<<<< HEAD return 0; } @@ -402,14 +473,35 @@ int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t atta break; case HID_DEVICE_DETACH: RARCH_LOG("Device detached\n"); +======= + RARCH_LOG(" handle: %d\n", device->handle); + RARCH_LOG(" physical_device_inst: %d\n", device->physical_device_inst); + RARCH_LOG(" vid: 0x%x\n", device->vid); + RARCH_LOG(" pid: 0x%x\n", device->pid); + RARCH_LOG(" interface_index: %d\n", device->interface_index); + RARCH_LOG(" sub_class: %d\n", device->sub_class); + RARCH_LOG(" protocol: %d\n", device->protocol); + RARCH_LOG(" max_packet_size_rx: %d\n", device->max_packet_size_rx); + RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx); +} + +static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { + switch(attach) { + case HID_DEVICE_ATTACH: + RARCH_LOG("USB device attach event\n"); + break; + case HID_DEVICE_DETACH: + RARCH_LOG("USB device detach event\n"); +>>>>>>> Simplify, add logging, revert some of the changes break; default: - // Undefined behavior, bail out break; } + log_device(device); - return result; + return DEVICE_UNUSED; } +<<<<<<< HEAD */ /** * Allocation @@ -421,16 +513,27 @@ wiiu_hid_t *new_hid(void) { memset(hid, 0, sizeof(wiiu_hid_t)); return hid; -} +======= -void delete_hid(wiiu_hid_t *hid) { - if(hid) { - if(hid->polling_thread_stack) - free(hid->polling_thread_stack); - - free(hid); +static int wiiu_hid_polling_thread(int argc, const char **argv) { + wiiu_hid_t *hid = (wiiu_hid_t *)argv; + while(!hid->polling_thread_quit) { + usleep(10000); } + + return 0; } + +static wiiu_hid_t *new_hid(void) { + return alloc_zeroed(2, sizeof(wiiu_hid_t)); +>>>>>>> Simplify, add logging, revert some of the changes +} + +static void delete_hid(wiiu_hid_t *hid) { + if(hid) + free(hid); +} +<<<<<<< HEAD /* HIDClient *new_hidclient(void) { HIDClient *client = memalign(32, sizeof(HIDClient)); @@ -445,6 +548,28 @@ void delete_hidclient(HIDClient *client) { free(client); } */ +======= + +static HIDClient *new_hidclient(void) { + return alloc_zeroed(32, sizeof(HIDClient)); +} + +static void delete_hidclient(HIDClient *client) { + if(client) + free(client); +} + +void *alloc_zeroed(size_t alignment, size_t size) { + void *result = memalign(alignment, size); + if(result) { + memset(result, 0, size); + } + + return result; +} + + +>>>>>>> Simplify, add logging, revert some of the changes hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, diff --git a/wiiu/net_listen.sh b/wiiu/net_listen.sh index 167be1fa63..ae39b5caa7 100755 --- a/wiiu/net_listen.sh +++ b/wiiu/net_listen.sh @@ -1,14 +1,14 @@ #!/bin/sh -if [ -z $1 ] ; then - echo - echo "usage: $0 " - echo - exit 0 -fi - interrupt_count=0 -trap 'if [ $interrupt_count -eq 20 ]; then exit 0; else interrupt_count=$(($interrupt_count + 1)); fi' INT +trap 'if [ $interrupt_count -eq 5 ]; then exit 0; else interrupt_count=$(($interrupt_count + 1)); fi' INT -while true; do echo; echo ========= `date` =========; echo; netcat -p 4405 -l $1; done +echo ===== START: `date` ===== +while true; do + netcat -p 4405 -l + if [ $? -ne 0 ]; then + break + fi +done +echo ===== END: `date` ===== From e98b0067151d678eb963c7bea8350e3f2a71bfaf Mon Sep 17 00:00:00 2001 From: gblues Date: Sat, 9 Dec 2017 00:18:04 -0800 Subject: [PATCH 11/26] HID worker thread is now operational == DETAILS After wasting some cycles trying to isolate a crash, I went back to basics. I enabled the network logging, and put in a bunch of logging lines, and noticed that the HID thread wasn't actually starting. I did quite a bit of experimenting, working with different memory alignments, and finally got it working. == TESTING As you can see, I put a log output inside the worker thread. When I run the build, I can see the TICK messages. I can also see that the thread shuts down as expected. Also! The HID callback works as expected too! I have the GC adapter, and when I register the HID callback it fires and I get the following data: [INFO] USB device attach event [INFO] handle: 2058729 [INFO] physical_device_inst: 0 [INFO] vid: 0x7e05 [INFO] pid: 0x3703 [INFO] interface_index: 0 [INFO] sub_class: 0 [INFO] protocol: 0 [INFO] max_packet_size_rx: 37 [INFO] max_packet_size_tx: 5 Note that these are raw dumps of the data passed to the method, so e.g. the VID/PID might be byte-swapped from how they're usually represented. Have not done the stress test to try to reproduce the crash. --- input/drivers_hid/wiiu_hid.c | 361 ++++------------------------------- 1 file changed, 41 insertions(+), 320 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index d10c20880c..b66a3bad94 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -24,64 +24,9 @@ #include "../input_driver.h" #include "../../verbosity.h" -<<<<<<< HEAD -#define POLL_THREAD_SLEEP 10000 -<<<<<<< HEAD -======= - #define DEVICE_UNUSED 0 #define DEVICE_USED 1 -typedef struct wiiu_hid_user wiiu_hid_user_t; - -struct wiiu_hid_user -{ - wiiu_hid_user_t *next; - uint8_t *send_control_buffer; - uint8_t *send_control_type; - - uint32_t handle; - uint32_t physical_device_inst; - uint16_t vid; - uint16_t pid; - uint8_t interface_index; - uint8_t sub_class; - uint8_t protocol; - uint16_t max_packet_size_rx; - uint16_t max_packet_size_tx; -}; - -typedef struct wiiu_hid -{ - HIDClient *client; - OSThread *polling_thread; - // memory accounting; keep a pointer to the stack buffer so we can clean up later. - void *polling_thread_stack; - // setting this to true tells the polling thread to quit - volatile bool polling_thread_quit; -} wiiu_hid_t; ->>>>>>> Start implementing HID polling thread - -<<<<<<< HEAD -#define DEVICE_UNUSED 0 -#define DEVICE_USED 1 - -typedef struct wiiu_hid_user wiiu_hid_user_t; - -<<<<<<< HEAD -struct wiiu_hid_user -{ - wiiu_hid_user_t *next; - uint8_t *buffer; - uint32_t transfersize; - uint32_t handle; -}; -======= -#define DEVICE_UNUSED 0 -#define DEVICE_USED 1 -#define ALIGN_POINTER sizeof(void *) ->>>>>>> Simplify, add logging, revert some of the changes - typedef struct wiiu_hid { HIDClient *client; @@ -90,57 +35,17 @@ typedef struct wiiu_hid volatile bool polling_thread_quit; } wiiu_hid_t; -<<<<<<< HEAD -======= ->>>>>>> More progress on the HID driver -/* - * The attach/detach callback has no access to the wiiu_hid_t object. Therefore, we need a - * global place to handle device data. - */ -static wiiu_hid_user_t *pad_list = NULL; -static OSFastMutex *pad_list_mutex; - -static wiiu_hid_t *new_wiiu_hid_t(void); -static void delete_wiiu_hid_t(wiiu_hid_t *hid); -static wiiu_hid_user_t *new_wiiu_hid_user_t(void); -static void delete_wiiu_hid_user_t(wiiu_hid_user_t *user); -======= void *alloc_zeroed(size_t alignment, size_t size); +static OSThread *new_thread(void); static wiiu_hid_t *new_hid(void); static void delete_hid(wiiu_hid_t *hid); static void delete_hidclient(HIDClient *client); ->>>>>>> Simplify, add logging, revert some of the changes static HIDClient *new_hidclient(void); -<<<<<<< HEAD -static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); -======= -//static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); ->>>>>>> Only call HIDSetup/HidTeardown once -static void start_polling_thread(wiiu_hid_t *hid); -static void stop_polling_thread(wiiu_hid_t *hid); -static int wiiu_hid_polling_thread(int argc, const char **argv); -static void wiiu_hid_do_poll(wiiu_hid_t *hid); -<<<<<<< HEAD - -static void enqueue_device(void); -======= ->>>>>>> Start implementing HID polling thread - -//HIDClient *new_hidclient(void); -//void delete_hidclient(HIDClient *client); -wiiu_hid_t *new_hid(void); -void delete_hid(wiiu_hid_t *hid); - -/** - * HID driver entrypoints registered with hid_driver_t - */ -======= static void start_polling_thread(wiiu_hid_t *hid); static void stop_polling_thread(wiiu_hid_t *hid); static int wiiu_hid_polling_thread(int argc, const char **argv); static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); ->>>>>>> Simplify, add logging, revert some of the changes static bool wiiu_hid_joypad_query(void *data, unsigned pad) { @@ -149,7 +54,6 @@ static bool wiiu_hid_joypad_query(void *data, unsigned pad) static const char *wiiu_hid_joypad_name(void *data, unsigned pad) { - /* TODO/FIXME - implement properly */ if (pad >= MAX_USERS) return NULL; @@ -195,48 +99,26 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *wiiu_hid_init(void) { -<<<<<<< HEAD - wiiu_hid_t *hid = new_hid(); -// HIDClient *client = new_hidclient(); - -// if(!hid || !client) - if(!hid) - goto error; - - start_polling_thread(hid); - if(hid->polling_thread == NULL) - goto error; - -// HIDAddClient(client, wiiu_attach_callback); -// hid->client = client; - - return hid; - - error: - if(hid) { - stop_polling_thread(hid); - delete_hid(hid); - } -// if(client) { -// delete_hidclient(client); -// } - - return NULL; -======= - HIDSetup(); + RARCH_LOG("[hid]: wiiu_hid: init\n"); +// HIDSetup(); wiiu_hid_t *hid = new_hid(); HIDClient *client = new_hidclient(); if(!hid || !client) { goto error; } + RARCH_LOG("[hid]: hid: 0x%x\n", hid); + RARCH_LOG("[hid]: client: 0x%x\n", client); + start_polling_thread(hid); if(!hid->polling_thread) goto error; + RARCH_LOG("[hid]: Registering HIDClient\n"); HIDAddClient(client, wiiu_attach_callback); hid->client = client; + RARCH_LOG("[hid]: init success"); return hid; error: @@ -245,47 +127,10 @@ static void *wiiu_hid_init(void) delete_hid(hid); delete_hidclient(client); return NULL; ->>>>>>> Simplify, add logging, revert some of the changes } static void wiiu_hid_free(void *data) { -<<<<<<< HEAD - wiiu_hid_t *hid = (wiiu_hid_t*)data; - - if (hid) { - stop_polling_thread(hid); -<<<<<<< HEAD - delete_wiiu_hid_t(hid); - } -} - -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> More progress on the HID driver -static void free_pad_list(void) { - wiiu_hid_user_t *top; - - while(pad_list != NULL) { - top = pad_list; - pad_list = top->next; - delete_wiiu_hid_user_t(top); -======= - delete_hid(hid); ->>>>>>> Only call HIDSetup/HidTeardown once - } -} - -<<<<<<< HEAD -======= ->>>>>>> Start implementing HID polling thread -======= ->>>>>>> More progress on the HID driver -/** - * This is a no-op because polling is done with a worker thread. - */ -======= wiiu_hid_t *hid = (wiiu_hid_t*)data; if (hid) { @@ -293,10 +138,9 @@ static void free_pad_list(void) { delete_hidclient(hid->client); delete_hid(hid); } - HIDTeardown(); + //HIDTeardown(); } ->>>>>>> Simplify, add logging, revert some of the changes static void wiiu_hid_poll(void *data) { (void)data; @@ -304,73 +148,37 @@ static void wiiu_hid_poll(void *data) static void start_polling_thread(wiiu_hid_t *hid) { RARCH_LOG("[hid]: starting polling thread.\n"); - OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2 | - OS_THREAD_ATTRIB_STACK_USAGE; + OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2; BOOL result; int32_t stack_size = 0x8000; int32_t priority = 10; - OSThread *thread = memalign(ALIGN_POINTER, sizeof(OSThread)); - void *stack = memalign(ALIGN_POINTER, stack_size); + OSThread *thread = new_thread(); + void *stack = alloc_zeroed(16, stack_size); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> More progress on the HID driver - if(pad_list_mutex == NULL) { - pad_list_mutex = new_fastmutex("pad_list"); - } - - if(!thread || !stack || !pad_list_mutex) -<<<<<<< HEAD -======= - if(!thread || !stack) ->>>>>>> Start implementing HID polling thread -======= ->>>>>>> More progress on the HID driver -======= - if(!thread || !stack) ->>>>>>> Only call HIDSetup/HidTeardown once - goto error; -======= if(!thread || !stack) { RARCH_LOG("[hid]: allocation failed, aborting thread start.\n"); goto error; } - RARCH_LOG("[hid]: thread = %x; stack = %x\n", thread, stack); ->>>>>>> Simplify, add logging, revert some of the changes + RARCH_LOG("[hid]: thread: 0x%x; stack: 0x%x\n", thread, stack); - if(!OSCreateThread(thread, wiiu_hid_polling_thread, 1, (char *)hid, stack, stack_size, priority, attributes)) { + if(!OSCreateThread(thread, + wiiu_hid_polling_thread, + 1, (char *)hid, + stack+stack_size, stack_size, + priority, + attributes)) { RARCH_LOG("[hid]: OSCreateThread failed.\n"); goto error; } hid->polling_thread = thread; hid->polling_thread_stack = stack; + OSResumeThread(thread); return; error: -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - if(pad_list_mutex) - delete_fastmutex(pad_list_mutex); -======= ->>>>>>> Start implementing HID polling thread -======= - if(pad_list_mutex) - delete_fastmutex(pad_list_mutex); ->>>>>>> More progress on the HID driver -======= ->>>>>>> Only call HIDSetup/HidTeardown once - if(stack) - free(stack); -======= ->>>>>>> Simplify, add logging, revert some of the changes if(thread) free(thread); if(stack) @@ -391,28 +199,8 @@ static void stop_polling_thread(wiiu_hid_t *hid) { OSJoinThread(hid->polling_thread, &thread_result); free(hid->polling_thread); free(hid->polling_thread_stack); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> More progress on the HID driver - - // with the thread stopped, we don't need the mutex. - delete_fastmutex(pad_list_mutex); - pad_list_mutex = NULL; - free_pad_list(); -<<<<<<< HEAD -======= ->>>>>>> Start implementing HID polling thread -======= ->>>>>>> More progress on the HID driver -======= ->>>>>>> Only call HIDSetup/HidTeardown once -======= hid->polling_thread = NULL; hid->polling_thread_stack = NULL; ->>>>>>> Simplify, add logging, revert some of the changes } void log_device(HIDDevice *device) { @@ -420,60 +208,6 @@ void log_device(HIDDevice *device) { RARCH_LOG("NULL device.\n"); } -<<<<<<< HEAD - return 0; -} - -/** - * Only call this from the polling thread. - */ -static void wiiu_hid_do_poll(wiiu_hid_t *hid) { - usleep(POLL_THREAD_SLEEP); -} - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> More progress on the HID driver -int32_t wiiu_attach_device(HIDClient *client, HIDDevice *device) { - wiiu_hid_user_t *adapter = new_wiiu_hid_user_t(); - - if(!adapter) - goto error; - - error: - if(adapter) { - delete_wiiu_hid_user_t(adapter); - } - return DEVICE_UNUSED; -} - -int32_t wiiu_detach_device(HIDClient *client, HIDDevice *device) { - return DEVICE_UNUSED; -} - -<<<<<<< HEAD -======= ->>>>>>> Start implementing HID polling thread -======= ->>>>>>> More progress on the HID driver -======= ->>>>>>> Only call HIDSetup/HidTeardown once -/** - * Callbacks - */ -/* -int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { - int32_t result = DEVICE_UNUSED; - - switch(attach) { - case HID_DEVICE_ATTACH: - RARCH_LOG("Device attached\n"); - break; - case HID_DEVICE_DETACH: - RARCH_LOG("Device detached\n"); -======= RARCH_LOG(" handle: %d\n", device->handle); RARCH_LOG(" physical_device_inst: %d\n", device->physical_device_inst); RARCH_LOG(" vid: 0x%x\n", device->vid); @@ -492,7 +226,6 @@ static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32 break; case HID_DEVICE_DETACH: RARCH_LOG("USB device detach event\n"); ->>>>>>> Simplify, add logging, revert some of the changes break; default: break; @@ -501,60 +234,49 @@ static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32 return DEVICE_UNUSED; } -<<<<<<< HEAD -*/ -/** - * Allocation - */ - -wiiu_hid_t *new_hid(void) { - wiiu_hid_t *hid = calloc(1, sizeof(wiiu_hid_t)); - if(hid) - memset(hid, 0, sizeof(wiiu_hid_t)); - - return hid; -======= static int wiiu_hid_polling_thread(int argc, const char **argv) { wiiu_hid_t *hid = (wiiu_hid_t *)argv; + int i = 0; + RARCH_LOG("[hid]: polling thread is starting\n"); while(!hid->polling_thread_quit) { usleep(10000); + i += 10000; + if(i >= (1000 * 1000 * 3)) { + RARCH_LOG("[hid]: thread: TICK!\n"); + i = 0; + } } + RARCH_LOG("[hid]: polling thread is stopping\n"); return 0; } +static OSThread *new_thread(void) { + OSThread *t = alloc_zeroed(8, sizeof(OSThread)); + t->tag = OS_THREAD_TAG; + + return t; +} + static wiiu_hid_t *new_hid(void) { - return alloc_zeroed(2, sizeof(wiiu_hid_t)); ->>>>>>> Simplify, add logging, revert some of the changes + RARCH_LOG("[hid]: new_hid()\n"); + return alloc_zeroed(4, sizeof(wiiu_hid_t)); } static void delete_hid(wiiu_hid_t *hid) { + RARCH_LOG("[hid]: delete_hid()\n"); if(hid) free(hid); } -<<<<<<< HEAD -/* -HIDClient *new_hidclient(void) { - HIDClient *client = memalign(32, sizeof(HIDClient)); - if(client) - memset(client, 0, sizeof(HIDClient)); - - return client; -} - -void delete_hidclient(HIDClient *client) { - if(client) - free(client); -} -*/ -======= static HIDClient *new_hidclient(void) { + RARCH_LOG("[hid]: new_hidclient()\n"); return alloc_zeroed(32, sizeof(HIDClient)); } static void delete_hidclient(HIDClient *client) { + RARCH_LOG("[hid]: delete_hidclient()\n"); if(client) free(client); } @@ -569,7 +291,6 @@ void *alloc_zeroed(size_t alignment, size_t size) { } ->>>>>>> Simplify, add logging, revert some of the changes hid_driver_t wiiu_hid = { wiiu_hid_init, wiiu_hid_joypad_query, @@ -580,5 +301,5 @@ hid_driver_t wiiu_hid = { wiiu_hid_poll, wiiu_hid_joypad_rumble, wiiu_hid_joypad_name, - "wiiu_usb", + "wiiu", }; From 5804233ca8db773bf3be458ddc6180c1f17e5cb4 Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 10 Dec 2017 22:31:00 -0800 Subject: [PATCH 12/26] Start fleshing out wiiu_hid driver == DETAILS - Added entrypoints into `input/connect/joypad_connection.c` to allow a max value to be passed in, instead of using single macro value - Created a hand-off between the HID attach handler and the worker thread - Created a pad initializer in `wiiu_hid.c` leveraging the new functionality added to `joypad_connection.c` == TESTING Compiles cleanly. At best, doesn't do anything. Might crash--not ready to test quite yet. --- input/connect/joypad_connection.c | 26 +++- input/connect/joypad_connection.h | 4 + input/drivers_hid/wiiu_hid.c | 200 ++++++++++++++++++++++++------ input/drivers_hid/wiiu_hid.h | 92 ++++++++++++++ 4 files changed, 278 insertions(+), 44 deletions(-) create mode 100644 input/drivers_hid/wiiu_hid.h diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index e79fa9a82c..64dc1fd194 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -24,13 +24,18 @@ #include "joypad_connection.h" int pad_connection_find_vacant_pad(joypad_connection_t *joyconn) +{ + return pad_connection_find_vacant_pad_max(joyconn, MAX_USERS); +} + +int pad_connection_find_vacant_pad_max(joypad_connection_t *joyconn, unsigned max) { unsigned i; if (!joyconn) return -1; - for (i = 0; i < MAX_USERS; i++) + for (i = 0; i < max; i++) { joypad_connection_t *conn = &joyconn[i]; @@ -66,6 +71,16 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, void *data, send_control_t ptr) { + int pad = pad_connection_find_vacant_pad(joyconn); + return pad_connection_pad_init_with_slot(joyconn, name, + vid, pid, data, ptr, pad); +} + +int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, + const char *name, uint16_t vid, uint16_t pid, + void *data, send_control_t ptr, int slot) +{ + static const struct { const char* name; @@ -88,12 +103,11 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, { 0, 0} }; joypad_connection_t *s = NULL; - int pad = pad_connection_find_vacant_pad(joyconn); - if (pad == -1) + if (slot == -1) return -1; - s = &joyconn[pad]; + s = &joyconn[slot]; if (s) { @@ -119,7 +133,7 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; - s->data = s->iface->init(data, pad, ptr); + s->data = s->iface->init(data, slot, ptr); s->connected = true; #if 0 RARCH_LOG("%s found \n", pad_map[i].name); @@ -144,7 +158,7 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, } } - return pad; + return slot; } void pad_connection_pad_deinit(joypad_connection_t *joyconn, uint32_t pad) diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 75b6dbb633..d3cf832fe2 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -59,6 +59,9 @@ extern pad_connection_interface_t pad_connection_psxadapter; int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, void *data, send_control_t ptr); +int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, + const char* name, uint16_t vid, uint16_t pid, + void *data, send_control_t ptr, int slot); joypad_connection_t *pad_connection_init(unsigned pads); @@ -83,6 +86,7 @@ bool pad_connection_has_interface(joypad_connection_t *joyconn, unsigned idx); int pad_connection_find_vacant_pad(joypad_connection_t *joyconn); +int pad_connection_find_vacant_pad_max(joypad_connection_t *joyconn, unsigned max); bool pad_connection_rumble(joypad_connection_t *s, unsigned pad, enum retro_rumble_effect effect, uint16_t strength); diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index b66a3bad94..20b9cde356 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -20,32 +20,9 @@ #include #include -#include "../input_defines.h" -#include "../input_driver.h" -#include "../../verbosity.h" +#include "wiiu_hid.h" -#define DEVICE_UNUSED 0 -#define DEVICE_USED 1 - -typedef struct wiiu_hid -{ - HIDClient *client; - OSThread *polling_thread; - void *polling_thread_stack; - volatile bool polling_thread_quit; -} wiiu_hid_t; - -void *alloc_zeroed(size_t alignment, size_t size); -static OSThread *new_thread(void); -static wiiu_hid_t *new_hid(void); -static void delete_hid(wiiu_hid_t *hid); -static void delete_hidclient(HIDClient *client); -static HIDClient *new_hidclient(void); - -static void start_polling_thread(wiiu_hid_t *hid); -static void stop_polling_thread(wiiu_hid_t *hid); -static int wiiu_hid_polling_thread(int argc, const char **argv); -static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +static wiiu_event_list events; static bool wiiu_hid_joypad_query(void *data, unsigned pad) { @@ -100,16 +77,17 @@ static int16_t wiiu_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static void *wiiu_hid_init(void) { RARCH_LOG("[hid]: wiiu_hid: init\n"); -// HIDSetup(); wiiu_hid_t *hid = new_hid(); HIDClient *client = new_hidclient(); - if(!hid || !client) { + joypad_connection_t *connections = pad_connection_init(MAX_HID_PADS); + + if(!hid || !client || !connections) { goto error; } - RARCH_LOG("[hid]: hid: 0x%x\n", hid); - RARCH_LOG("[hid]: client: 0x%x\n", client); + hid->connections = connections; + wiiu_hid_init_event_list(); start_polling_thread(hid); if(!hid->polling_thread) goto error; @@ -118,11 +96,13 @@ static void *wiiu_hid_init(void) HIDAddClient(client, wiiu_attach_callback); hid->client = client; - RARCH_LOG("[hid]: init success"); + RARCH_LOG("[hid]: init success\n"); return hid; error: RARCH_LOG("[hid]: initialization failed. cleaning up.\n"); + if(connections) + free(connections); stop_polling_thread(hid); delete_hid(hid); delete_hidclient(client); @@ -137,8 +117,15 @@ static void wiiu_hid_free(void *data) stop_polling_thread(hid); delete_hidclient(hid->client); delete_hid(hid); + if(events.list) { + wiiu_attach_event *event; + while( (event = events.list) != NULL) { + events.list = event->next; + delete_attach_event(event); + } + memset(&events, 0, sizeof(events)); + } } - //HIDTeardown(); } static void wiiu_hid_poll(void *data) @@ -146,6 +133,15 @@ static void wiiu_hid_poll(void *data) (void)data; } +static void wiiu_hid_device_send_control(void *data, + uint8_t *buffer, + size_t buffer_size) { + struct wiiu_adapter *adapter = (struct wiiu_adapter *)data; + + if(!adapter) + return; +} + static void start_polling_thread(wiiu_hid_t *hid) { RARCH_LOG("[hid]: starting polling thread.\n"); OSThreadAttributes attributes = OS_THREAD_ATTRIB_AFFINITY_CPU2; @@ -203,7 +199,7 @@ static void stop_polling_thread(wiiu_hid_t *hid) { hid->polling_thread_stack = NULL; } -void log_device(HIDDevice *device) { +static void log_device(HIDDevice *device) { if(!device) { RARCH_LOG("NULL device.\n"); } @@ -219,20 +215,105 @@ void log_device(HIDDevice *device) { RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx); } +static void synchronized_add_event(wiiu_attach_event *event) { + OSFastMutex_Lock(&(events.lock)); + event->next = events.list; + events.list = event; + OSFastMutex_Unlock(&(events.lock)); +} + +static wiiu_attach_event *synchronized_get_events_list(void) { + wiiu_attach_event *list; + OSFastMutex_Lock(&(events.lock)); + list = events.list; + events.list = NULL; + OSFastMutex_Unlock(&(events.lock)); + + return list; +} + +static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter) { +} + static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { + wiiu_attach_event *event; + log_device(device); switch(attach) { case HID_DEVICE_ATTACH: - RARCH_LOG("USB device attach event\n"); - break; case HID_DEVICE_DETACH: - RARCH_LOG("USB device detach event\n"); - break; + event = new_attach_event(device); + if(!event) + goto error; + + event->type = attach; + synchronized_add_event(event); + return DEVICE_USED; default: break; } - log_device(device); - return DEVICE_UNUSED; + error: + delete_attach_event(event); + return DEVICE_UNUSED; +} + + +static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, + const char *name, uint16_t vid, uint16_t pid, void *data, + send_control_t ptr) { + int pad = pad_connection_find_vacant_pad_max(joyconn, MAX_HID_PADS); + return pad_connection_pad_init_with_slot(joyconn, name, vid, pid, + data, ptr, pad); +} + +static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event) { +} + + +static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { + struct wiiu_adapter *adapter = new_adapter(); + + if(!adapter) { + RARCH_ERR("[hid]: Failed to allocate adapter.\n"); + goto error; + } + + adapter->hid = hid; + adapter->handle = event->handle; + adapter->slot = wiiu_hid_pad_init(hid->connections, + "hid", event->vendor_id, event->product_id, adapter, + &wiiu_hid_device_send_control); + + if(adapter->slot < 0) { + RARCH_ERR("[hid]: No available slots.\n"); + goto error; + } + + if(!pad_connection_has_interface(hid->connections, adapter->slot)) { + RARCH_ERR("[hid]: Interface not found for HID device with vid=0x%04x pid=0x%04x\n", + event->vendor_id, event->product_id); + goto error; + } + + synchronized_add_to_adapters_list(adapter); + return; + + error: + delete_adapter(adapter); +} + +static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list) { + wiiu_attach_event *event; + if(!hid || !list) + return; + + for(event = list; event != NULL; event = event->next) { + if(event->type == HID_DEVICE_ATTACH) { + wiiu_hid_attach(hid, event); + } else { + wiiu_hid_detach(hid, event); + } + } } static int wiiu_hid_polling_thread(int argc, const char **argv) { @@ -240,6 +321,7 @@ static int wiiu_hid_polling_thread(int argc, const char **argv) { int i = 0; RARCH_LOG("[hid]: polling thread is starting\n"); while(!hid->polling_thread_quit) { + wiiu_handle_attach_events(hid, synchronized_get_events_list()); usleep(10000); i += 10000; if(i >= (1000 * 1000 * 3)) { @@ -259,6 +341,12 @@ static OSThread *new_thread(void) { return t; } +static void wiiu_hid_init_event_list(void) { + RARCH_LOG("[hid]: Initializing events list\n"); + memset(&events, 0, sizeof(events)); + OSFastMutex_Init(&(events.lock), "attach_events"); +} + static wiiu_hid_t *new_hid(void) { RARCH_LOG("[hid]: new_hid()\n"); return alloc_zeroed(4, sizeof(wiiu_hid_t)); @@ -281,6 +369,42 @@ static void delete_hidclient(HIDClient *client) { free(client); } +static struct wiiu_adapter *new_adapter(void) { + RARCH_LOG("[hid]: new_adapter()\n"); + return alloc_zeroed(4, sizeof(struct wiiu_adapter)); +} + +static void delete_adapter(struct wiiu_adapter *adapter) { + RARCH_LOG("[hid]: delete_adapter()\n"); + if(adapter) + free(adapter); +} + +static wiiu_attach_event *new_attach_event(HIDDevice *device) { + if(!device) + return NULL; + + wiiu_attach_event *event = alloc_zeroed(4, sizeof(wiiu_attach_event)); + if(!event) + return NULL; + event->handle = device->handle; + event->vendor_id = device->vid; + event->product_id = device->vid; + event->interface_index = device->interface_index; + event->is_keyboard = (device->sub_class == 1 && device->protocol == 1); + event->is_mouse = (device->sub_class == 1 && device->protocol == 2); + event->max_packet_size_rx = device->max_packet_size_rx; + event->max_packet_size_tx = device->max_packet_size_tx; + + return event; +} + +static void delete_attach_event(wiiu_attach_event *event) { + if(event) + free(event); +} + + void *alloc_zeroed(size_t alignment, size_t size) { void *result = memalign(alignment, size); if(result) { diff --git a/input/drivers_hid/wiiu_hid.h b/input/drivers_hid/wiiu_hid.h new file mode 100644 index 0000000000..ce72c29702 --- /dev/null +++ b/input/drivers_hid/wiiu_hid.h @@ -0,0 +1,92 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2013-2014 - Jason Fetters + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +#ifndef __WIIU_HID__H +#define __WIIU_HID__H +#include "../connect/joypad_connection.h" +#include "../input_defines.h" +#include "../input_driver.h" +#include "../../verbosity.h" + +#define DEVICE_UNUSED 0 +#define DEVICE_USED 1 + +#define MAX_HID_PADS 5 + +typedef struct wiiu_hid +{ + HIDClient *client; + joypad_connection_t *connections; + OSThread *polling_thread; + void *polling_thread_stack; + volatile bool polling_thread_quit; +} wiiu_hid_t; + +struct wiiu_adapter { + wiiu_hid_t *hid; + int32_t slot; + uint32_t handle; +}; + +typedef struct wiiu_attach wiiu_attach_event; + +struct wiiu_attach { + wiiu_attach_event *next; + uint32_t type; + uint32_t handle; + uint16_t vendor_id; + uint16_t product_id; + uint8_t interface_index; + uint8_t is_keyboard; + uint8_t is_mouse; + uint16_t max_packet_size_rx; + uint16_t max_packet_size_tx; +}; + +typedef struct _wiiu_event_list wiiu_event_list; + +struct _wiiu_event_list { + OSFastMutex lock; + wiiu_attach_event *list; +}; + +static void *alloc_zeroed(size_t alignment, size_t size); +static OSThread *new_thread(void); +static wiiu_hid_t *new_hid(void); +static void delete_hid(wiiu_hid_t *hid); +static void delete_hidclient(HIDClient *client); +static HIDClient *new_hidclient(void); +static struct wiiu_adapter *new_adapter(void); +static void delete_adapter(struct wiiu_adapter *adapter); +static wiiu_attach_event *new_attach_event(HIDDevice *device); +static void delete_attach_event(wiiu_attach_event *); + +static void wiiu_hid_init_event_list(void); +static void start_polling_thread(wiiu_hid_t *hid); +static void stop_polling_thread(wiiu_hid_t *hid); +static int wiiu_hid_polling_thread(int argc, const char **argv); +static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); +static wiiu_attach_event *synchronized_get_events_list(void); +static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list); +static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, + const char *name, uint16_t vid, uint16_t pid, void *data, + send_control_t ptr); +static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event); +static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event); +static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter); +static void synchronized_add_event(wiiu_attach_event *event); + +#endif // __WIIU_HID__H From c1496a860032e10c55b75c2c253a4cdf94362d84 Mon Sep 17 00:00:00 2001 From: gblues Date: Mon, 11 Dec 2017 23:48:59 -0800 Subject: [PATCH 13/26] WIP - reorganizing input data == DETAILS Looking at the apple input driver gave me an idea--moving the HID driver into the wiiu_input_t data instead of piggy-backing it off the wiiu_joypad driver. - Remove changes to wiiu_joypad - Add equivalent to wiiu_input This is probably broke as hell. Haven't tried to compile. --- input/drivers/wiiu_input.c | 17 +++++++++++++++-- input/drivers_joypad/wiiu_joypad.c | 8 -------- input/input_driver.h | 5 ++++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 8580b80d65..6c9d4a4ee8 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -44,6 +44,7 @@ typedef struct wiiu_input { bool blocked; const input_device_driver_t *joypad; + const hid_driver_t *hid_joypad; } wiiu_input_t; void kb_connection_callback(KBDKeyEvent *key) @@ -120,8 +121,13 @@ static void wiiu_input_poll(void *data) { wiiu_input_t *wiiu = (wiiu_input_t*)data; - if (wiiu && wiiu->joypad) - wiiu->joypad->poll(); + if(!wiiu) + return; + + if(wiiu->joypad) + wiiu->joypad->poll(); + if(wiiu->hid_joypad) + wiiu->hid_joypad->poll(); } static bool wiiu_key_pressed(int key) @@ -175,6 +181,12 @@ static void wiiu_input_free_input(void *data) if (wiiu && wiiu->joypad) wiiu->joypad->destroy(); + if (wiiu && wiiu->hid_joypad) + { + wiiu->hid_joypad->free(hid_driver_get_data()); + hid_driver_reset_data(); + } + KBDTeardown(); free(data); @@ -188,6 +200,7 @@ static void* wiiu_input_init(const char *joypad_driver) DEBUG_STR(joypad_driver); wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu); + wiiu->hid_joypad = input_hid_init_first(); KBDSetup(&kb_connection_callback, &kb_disconnection_callback,&kb_key_callback); diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 3a08305c37..4fb667c34d 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -43,8 +43,6 @@ #define GAMEPAD_OFFSET 0 -static const hid_driver_t *hid_driver = NULL; - static uint64_t pad_state[MAX_PADS]; static uint8_t pad_type[MAX_PADS-1] = {WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE}; @@ -301,7 +299,6 @@ static void wiiu_joypad_poll(void) static bool wiiu_joypad_init(void* data) { - hid_driver = input_hid_init_first(); wiiu_joypad_autodetect_add(0); wiiu_joypad_poll(); @@ -318,11 +315,6 @@ static bool wiiu_joypad_query_pad(unsigned pad) static void wiiu_joypad_destroy(void) { - if(hid_driver) { - hid_driver->free(hid_driver_get_data()); - hid_driver_reset_data(); - hid_driver = NULL; - } wiiu_pad_inited = false; } diff --git a/input/input_driver.h b/input/input_driver.h index bffc934816..b30436410f 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -192,8 +192,11 @@ struct hid_driver void (*poll)(void *); bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t); const char *(*name)(void *, unsigned); - const char *ident; + int32_t (*set_report)(void *, uint8_t, uint8_t, void *, uint32_t); + int32_t (*set_idle)(void *, uint8_t, uint8_t); + int32_t (*set_protocol)(void *, uint8_t, uint8_t); + }; /** From d0adbd194e0b480ec10f5c3b979d95fd1ef2f7d6 Mon Sep 17 00:00:00 2001 From: gblues Date: Tue, 12 Dec 2017 21:38:35 -0800 Subject: [PATCH 14/26] Revert changes to joypad API == DETAILS Premature. Still learning my way around the codebase. --- input/connect/joypad_connection.c | 27 +++++++-------------------- input/connect/joypad_connection.h | 4 ---- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index 64dc1fd194..62bb850ce0 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -24,18 +24,13 @@ #include "joypad_connection.h" int pad_connection_find_vacant_pad(joypad_connection_t *joyconn) -{ - return pad_connection_find_vacant_pad_max(joyconn, MAX_USERS); -} - -int pad_connection_find_vacant_pad_max(joypad_connection_t *joyconn, unsigned max) { unsigned i; if (!joyconn) return -1; - for (i = 0; i < max; i++) + for (i = 0; i < MAX_USERS; i++) { joypad_connection_t *conn = &joyconn[i]; @@ -68,17 +63,8 @@ joypad_connection_t *pad_connection_init(unsigned pads) } int32_t pad_connection_pad_init(joypad_connection_t *joyconn, - const char* name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr) -{ - int pad = pad_connection_find_vacant_pad(joyconn); - return pad_connection_pad_init_with_slot(joyconn, name, - vid, pid, data, ptr, pad); -} - -int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, const char *name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr, int slot) + void *data, send_control_t ptr) { static const struct @@ -103,11 +89,12 @@ int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, { 0, 0} }; joypad_connection_t *s = NULL; + int pad = pad_connection_find_vacant_pad(joyconn); - if (slot == -1) + if (pad == -1) return -1; - s = &joyconn[slot]; + s = &joyconn[pad]; if (s) { @@ -133,7 +120,7 @@ int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; - s->data = s->iface->init(data, slot, ptr); + s->data = s->iface->init(data, pad, ptr); s->connected = true; #if 0 RARCH_LOG("%s found \n", pad_map[i].name); @@ -158,7 +145,7 @@ int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, } } - return slot; + return pad; } void pad_connection_pad_deinit(joypad_connection_t *joyconn, uint32_t pad) diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index d3cf832fe2..75b6dbb633 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -59,9 +59,6 @@ extern pad_connection_interface_t pad_connection_psxadapter; int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, void *data, send_control_t ptr); -int32_t pad_connection_pad_init_with_slot(joypad_connection_t *joyconn, - const char* name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr, int slot); joypad_connection_t *pad_connection_init(unsigned pads); @@ -86,7 +83,6 @@ bool pad_connection_has_interface(joypad_connection_t *joyconn, unsigned idx); int pad_connection_find_vacant_pad(joypad_connection_t *joyconn); -int pad_connection_find_vacant_pad_max(joypad_connection_t *joyconn, unsigned max); bool pad_connection_rumble(joypad_connection_t *s, unsigned pad, enum retro_rumble_effect effect, uint16_t strength); From 5b37ced1968f58a0f879e243dcecfc547db1a383 Mon Sep 17 00:00:00 2001 From: gblues Date: Tue, 12 Dec 2017 22:55:10 -0800 Subject: [PATCH 15/26] Update HID pad driver architecture == DETAILS The current HID implementation assumes a very low-level USB library is being used. This causes a problem on Wii U, because the Cafe OS only exposes a high-level interface. To get these functions exposed to the HID pad drivers, I had to make three changes: 1. I added the legacy "send_control" function to the HID driver interface 2. I modified the signature of pad_connection_pad_init() to send the driver pointer instead of the function pointer 3. I updated the HID pad drivers to keep the pointer to the driver instead of the function pointer, and updated the calls into the send_control function as appropriate 4. I updated the HID drivers to use the new pad init signature == TESTING Untested, in theory it should work without a hitch because at this point all I've done is abstract things a little. I still need to update the HID pad drivers to use the Wii U-specific calls as appropriate. --- input/connect/connect_nesusb.c | 2 +- input/connect/connect_ps2adapter.c | 2 +- input/connect/connect_ps3.c | 16 ++++++++-------- input/connect/connect_ps4.c | 14 +++++++------- input/connect/connect_psxadapter.c | 2 +- input/connect/connect_snesusb.c | 2 +- input/connect/connect_wii.c | 16 ++++++++-------- input/connect/connect_wiiugca.c | 13 +++++++------ input/connect/connect_wiiupro.c | 12 ++++++------ input/connect/joypad_connection.c | 4 ++-- input/connect/joypad_connection.h | 6 +++--- input/drivers/wiiu_input.c | 2 +- input/drivers_hid/btstack_hid.c | 2 +- input/drivers_hid/iohidmanager_hid.c | 2 +- input/drivers_hid/libusb_hid.c | 2 +- input/drivers_hid/wiiu_hid.c | 11 ++--------- input/drivers_hid/wiiu_hid.h | 3 --- input/drivers_hid/wiiusb_hid.c | 2 +- input/input_driver.h | 1 + 19 files changed, 53 insertions(+), 61 deletions(-) diff --git a/input/connect/connect_nesusb.c b/input/connect/connect_nesusb.c index bf21fbb901..43f1f2d51b 100644 --- a/input/connect/connect_nesusb.c +++ b/input/connect/connect_nesusb.c @@ -30,7 +30,7 @@ struct hidpad_nesusb_data uint32_t buttons; }; -static void* hidpad_nesusb_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_nesusb_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_nesusb_data* device = (struct hidpad_nesusb_data*) diff --git a/input/connect/connect_ps2adapter.c b/input/connect/connect_ps2adapter.c index 87b174bd4e..c805cb85e2 100644 --- a/input/connect/connect_ps2adapter.c +++ b/input/connect/connect_ps2adapter.c @@ -30,7 +30,7 @@ struct hidpad_ps2adapter_data uint32_t buttons; }; -static void* hidpad_ps2adapter_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps2adapter_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_ps2adapter_data* device = (struct hidpad_ps2adapter_data*) diff --git a/input/connect/connect_ps3.c b/input/connect/connect_ps3.c index 7e96e5a7f4..b87c5e4ea6 100644 --- a/input/connect/connect_ps3.c +++ b/input/connect/connect_ps3.c @@ -25,7 +25,7 @@ struct hidpad_ps3_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; uint8_t data[512]; uint32_t slot; uint32_t buttons; @@ -54,13 +54,13 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) report_buffer[6] = device->motors[0] >> 8; #ifdef HAVE_WIIUSB_HID report_buffer[1] = 0x03; /* send control message type */ - device->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1); + device->driver->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1); #else - device->send_control(device->connection, report_buffer, sizeof(report_buffer)); + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); #endif } -static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps3_init(void *data, uint32_t slot, hid_driver_t *driver) { #ifdef HAVE_WIIUSB_HID /* Special command to enable Sixaxis, first byte defines the message type */ @@ -82,12 +82,12 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr) return NULL; } - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; #if defined(IOS) || defined(HAVE_WIIUSB_HID) - device->send_control(device->connection, magic_data, sizeof(magic_data)); + device->driver->send_control(device->connection, magic_data, sizeof(magic_data)); #endif #ifndef HAVE_WIIUSB_HID diff --git a/input/connect/connect_ps4.c b/input/connect/connect_ps4.c index ee5ead5c32..0356a91537 100644 --- a/input/connect/connect_ps4.c +++ b/input/connect/connect_ps4.c @@ -98,7 +98,7 @@ struct ps4 struct hidpad_ps4_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; struct ps4 data; uint32_t slot; bool have_led; @@ -119,11 +119,11 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device) report_buffer[11] = rgb[(device->slot % 4)][2]; #endif - device->send_control(device->connection, + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); } -static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_ps4_init(void *data, uint32_t slot, hid_driver_t *driver) { #if 0 uint8_t magic_data[0x25]; @@ -138,14 +138,14 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr) if (!connection) goto error; - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; #if 0 /* TODO - unsure of this */ /* This is needed to get full input packet over bluetooth. */ - device->send_control(device->connection, magic_data, 0x2); + device->driver->send_control(device->connection, magic_data, 0x2); (void)magic_data; #endif diff --git a/input/connect/connect_psxadapter.c b/input/connect/connect_psxadapter.c index b9d2e7f9ba..68f921b0b6 100644 --- a/input/connect/connect_psxadapter.c +++ b/input/connect/connect_psxadapter.c @@ -30,7 +30,7 @@ struct hidpad_psxadapter_data uint32_t buttons; }; -static void* hidpad_psxadapter_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_psxadapter_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_psxadapter_data* device = (struct hidpad_psxadapter_data*) diff --git a/input/connect/connect_snesusb.c b/input/connect/connect_snesusb.c index 62759b51fb..bdc9b16a05 100644 --- a/input/connect/connect_snesusb.c +++ b/input/connect/connect_snesusb.c @@ -31,7 +31,7 @@ struct hidpad_snesusb_data uint32_t buttons; }; -static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_snesusb_init(void *data, uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_snesusb_data* device = (struct hidpad_snesusb_data*) diff --git a/input/connect/connect_wii.c b/input/connect/connect_wii.c index 83ac50d736..f02e1735be 100644 --- a/input/connect/connect_wii.c +++ b/input/connect/connect_wii.c @@ -145,7 +145,7 @@ typedef struct connect_wii_wiimote_t int unid; struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; /* Various state flags. */ uint32_t state; @@ -195,7 +195,7 @@ static int wiimote_send(struct connect_wii_wiimote_t* wm, printf("\n"); #endif - wm->send_control(wm->connection, buf, len + 2); + wm->driver->send_control(wm->connection, buf, len + 2); return 1; } @@ -616,7 +616,7 @@ static void hidpad_wii_deinit(void *data) } static void* hidpad_wii_init(void *data, uint32_t slot, - send_control_t ptr) + hid_driver_t *driver) { struct pad_connection *connection = (struct pad_connection*)data; struct connect_wii_wiimote_t *device = (struct connect_wii_wiimote_t*) @@ -628,11 +628,11 @@ static void* hidpad_wii_init(void *data, uint32_t slot, if (!connection) goto error; - device->connection = connection; - device->unid = slot; - device->state = WIIMOTE_STATE_CONNECTED; - device->exp.type = EXP_NONE; - device->send_control = ptr; + device->connection = connection; + device->unid = slot; + device->state = WIIMOTE_STATE_CONNECTED; + device->exp.type = EXP_NONE; + device->driver = driver; wiimote_handshake(device, -1, NULL, -1); diff --git a/input/connect/connect_wiiugca.c b/input/connect/connect_wiiugca.c index 5705a7acdf..92423481f4 100644 --- a/input/connect/connect_wiiugca.c +++ b/input/connect/connect_wiiugca.c @@ -25,13 +25,13 @@ struct hidpad_wiiugca_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; uint8_t data[64]; uint32_t slot; uint32_t buttons; }; -static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr) +static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver) { static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */ struct pad_connection* connection = (struct pad_connection*)data; @@ -47,10 +47,11 @@ static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr) return NULL; } - device->connection = connection; - device->slot = slot; - device->send_control = ptr; - device->send_control(device->connection, magic_data, sizeof(magic_data)); + device->connection = connection; + device->slot = slot; + device->driver = driver; + + device->driver->send_control(device->connection, magic_data, sizeof(magic_data)); return device; } diff --git a/input/connect/connect_wiiupro.c b/input/connect/connect_wiiupro.c index c3787bbe3c..836f17856e 100644 --- a/input/connect/connect_wiiupro.c +++ b/input/connect/connect_wiiupro.c @@ -62,7 +62,7 @@ struct wiiupro_calib struct hidpad_wiiupro_data { struct pad_connection* connection; - send_control_t send_control; + hid_driver_t *driver; struct wiiupro data; uint32_t slot; bool have_led; @@ -75,12 +75,12 @@ static void hidpad_wiiupro_send_control(struct hidpad_wiiupro_data* device) { /* 0x12 = Set data report; 0x34 = All buttons and analogs */ static uint8_t report_buffer[4] = { 0xA2, 0x12, 0x00, 0x34 }; - device->send_control(device->connection, + device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); } static void* hidpad_wiiupro_init(void *data, - uint32_t slot, send_control_t ptr) + uint32_t slot, hid_driver_t *driver) { struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_wiiupro_data* device = (struct hidpad_wiiupro_data*) @@ -94,9 +94,9 @@ static void* hidpad_wiiupro_init(void *data, if (!connection) goto error; - device->connection = connection; - device->slot = slot; - device->send_control = ptr; + device->connection = connection; + device->slot = slot; + device->driver = driver; calib_data->calib_round = 0; /* Without this, the digital buttons won't be reported. */ diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index 62bb850ce0..a74847ed5a 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -64,7 +64,7 @@ joypad_connection_t *pad_connection_init(unsigned pads) int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char *name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr) + void *data, hid_driver_t *driver) { static const struct @@ -120,7 +120,7 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) { s->iface = pad_map[i].iface; - s->data = s->iface->init(data, pad, ptr); + s->data = s->iface->init(data, pad, driver); s->connected = true; #if 0 RARCH_LOG("%s found \n", pad_map[i].name); diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 75b6dbb633..07f221fd29 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -23,7 +23,7 @@ #include #include -typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size); +#include "../input_driver.h" struct joypad_connection { @@ -34,7 +34,7 @@ struct joypad_connection typedef struct pad_connection_interface { - void* (*init)(void *data, uint32_t slot, send_control_t ptr); + void* (*init)(void *data, uint32_t slot, hid_driver_t *driver); void (*deinit)(void* device); void (*packet_handler)(void* device, uint8_t *packet, uint16_t size); void (*set_rumble)(void* device, enum retro_rumble_effect effect, @@ -58,7 +58,7 @@ extern pad_connection_interface_t pad_connection_psxadapter; int32_t pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid, - void *data, send_control_t ptr); + void *data, hid_driver_t *driver); joypad_connection_t *pad_connection_init(unsigned pads); diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 6c9d4a4ee8..4dee87a4bb 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -127,7 +127,7 @@ static void wiiu_input_poll(void *data) if(wiiu->joypad) wiiu->joypad->poll(); if(wiiu->hid_joypad) - wiiu->hid_joypad->poll(); + wiiu->hid_joypad->poll(hid_driver_get_data()); } static bool wiiu_key_pressed(int key) diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 9946e1f6dc..f5bf2abe0e 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -1210,7 +1210,7 @@ static void btpad_packet_handler(uint8_t packet_type, RARCH_LOG("[BTpad]: Got %.200s.\n", (char*)&packet[9]); connection->slot = pad_connection_pad_init(&slots[connection->slot], - (char*)packet + 9, 0, 0, connection, &btpad_connection_send_control); + (char*)packet + 9, 0, 0, connection, &btstack_hid); connection->state = BTPAD_CONNECTED; } break; diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index ec8ec6cbd8..12c06a0157 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -510,7 +510,7 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result, adapter->slot = pad_connection_pad_init(hid->slots, adapter->name, dev_vid, dev_pid, adapter, - &iohidmanager_hid_device_send_control); + &iohidmanager_hid); if (adapter->slot == -1) goto error; diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index c03004b395..32a3a99dcd 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -308,7 +308,7 @@ static int add_adapter(void *data, struct libusb_device *dev) adapter->slot = pad_connection_pad_init(hid->slots, device_name, desc.idVendor, desc.idProduct, - adapter, &libusb_hid_device_send_control); + adapter, &libusb_hid); if (adapter->slot == -1) goto error; diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 20b9cde356..6e1f8923b8 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -258,13 +258,6 @@ static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32 } -static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, - const char *name, uint16_t vid, uint16_t pid, void *data, - send_control_t ptr) { - int pad = pad_connection_find_vacant_pad_max(joyconn, MAX_HID_PADS); - return pad_connection_pad_init_with_slot(joyconn, name, vid, pid, - data, ptr, pad); -} static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event) { } @@ -280,9 +273,9 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { adapter->hid = hid; adapter->handle = event->handle; - adapter->slot = wiiu_hid_pad_init(hid->connections, + adapter->slot = pad_connection_pad_init(hid->connections, "hid", event->vendor_id, event->product_id, adapter, - &wiiu_hid_device_send_control); + &wiiu_hid); if(adapter->slot < 0) { RARCH_ERR("[hid]: No available slots.\n"); diff --git a/input/drivers_hid/wiiu_hid.h b/input/drivers_hid/wiiu_hid.h index ce72c29702..d2f4bc0715 100644 --- a/input/drivers_hid/wiiu_hid.h +++ b/input/drivers_hid/wiiu_hid.h @@ -81,9 +81,6 @@ static int wiiu_hid_polling_thread(int argc, const char **argv); static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach); static wiiu_attach_event *synchronized_get_events_list(void); static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list); -static int32_t wiiu_hid_pad_init(joypad_connection_t *joyconn, - const char *name, uint16_t vid, uint16_t pid, void *data, - send_control_t ptr); static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event); static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event); static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter); diff --git a/input/drivers_hid/wiiusb_hid.c b/input/drivers_hid/wiiusb_hid.c index e50657c64d..f4ded13ba3 100644 --- a/input/drivers_hid/wiiusb_hid.c +++ b/input/drivers_hid/wiiusb_hid.c @@ -322,7 +322,7 @@ static int wiiusb_hid_add_adapter(void *data, usb_device_entry *dev) * control name until we get its interface */ adapter->slot = pad_connection_pad_init(hid->connections, "hid", desc.idVendor, desc.idProduct, - adapter, &wiiusb_hid_device_send_control); + adapter, &wiiusb_hid); if (adapter->slot == -1) goto error; diff --git a/input/input_driver.h b/input/input_driver.h index b30436410f..22df4b1c60 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -193,6 +193,7 @@ struct hid_driver bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t); const char *(*name)(void *, unsigned); const char *ident; + void (*send_control)(void *data, uint8_t *buf, size_t size); int32_t (*set_report)(void *, uint8_t, uint8_t, void *, uint32_t); int32_t (*set_idle)(void *, uint8_t, uint8_t); int32_t (*set_protocol)(void *, uint8_t, uint8_t); From 982d6893b077099e9669858f6958108056d95f6f Mon Sep 17 00:00:00 2001 From: gblues Date: Wed, 13 Dec 2017 23:18:02 -0800 Subject: [PATCH 16/26] Set the send_control pointer on the drivers == DETAIL One minor detail missed in the last commit: actually putting the send_control function into the driver declaration. Woops. Not doing the Wii U because it will be using the other methods. --- input/drivers_hid/btstack_hid.c | 1 + input/drivers_hid/iohidmanager_hid.c | 1 + input/drivers_hid/libusb_hid.c | 1 + input/drivers_hid/wiiusb_hid.c | 1 + 4 files changed, 4 insertions(+) diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index f5bf2abe0e..dc6ea0b645 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -1477,4 +1477,5 @@ hid_driver_t btstack_hid = { btstack_hid_joypad_rumble, btstack_hid_joypad_name, "btstack", + btpad_connection_send_control }; diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index 12c06a0157..2aa88b3a86 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -860,4 +860,5 @@ hid_driver_t iohidmanager_hid = { iohidmanager_hid_joypad_rumble, iohidmanager_hid_joypad_name, "iohidmanager", + iohidmanager_hid_device_send_control, }; diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index 32a3a99dcd..a28ee4d96e 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -655,4 +655,5 @@ hid_driver_t libusb_hid = { libusb_hid_joypad_rumble, libusb_hid_joypad_name, "libusb", + libusb_hid_device_send_control, }; diff --git a/input/drivers_hid/wiiusb_hid.c b/input/drivers_hid/wiiusb_hid.c index f4ded13ba3..031e54db8c 100644 --- a/input/drivers_hid/wiiusb_hid.c +++ b/input/drivers_hid/wiiusb_hid.c @@ -630,4 +630,5 @@ hid_driver_t wiiusb_hid = { wiiusb_hid_joypad_rumble, wiiusb_hid_joypad_name, "wiiusb", + wiiusb_hid_device_send_control, }; From 678c4093c136e0da1a085457515aa9d9a8cdc85b Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 14 Dec 2017 00:01:49 -0800 Subject: [PATCH 17/26] Start adapting the dual shock 3 driver to use the new driver format. == DETAILS The handshake stuff is derived from the old HID2VPAD, just in knowing what data goes in what report. - Added the HID_REPORT_ flags to syshid.h - Renamed the generic "REPORT_TYPE" flags to be meaningful - also fixed incorrect parameter list for set_protocol == TESTING The functions aren't implemented in wiiu_hid.c just yet, so this is gonna crash if you try to run it. --- input/connect/connect_ps3.c | 31 ++++++++++++++++++++++++++++++- input/input_driver.h | 2 +- wiiu/include/wiiu/syshid.h | 9 +++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/input/connect/connect_ps3.c b/input/connect/connect_ps3.c index b87c5e4ea6..55466d0ff8 100644 --- a/input/connect/connect_ps3.c +++ b/input/connect/connect_ps3.c @@ -22,6 +22,10 @@ #include "joypad_connection.h" #include "../input_defines.h" +#ifdef WIIU +#include +#endif + struct hidpad_ps3_data { struct pad_connection* connection; @@ -33,6 +37,13 @@ struct hidpad_ps3_data uint16_t motors[2]; }; +/* + * TODO: give these more meaningful names. + */ + +#define DS3_ACTIVATION_REPORT_ID 0xf4 +#define DS3_RUMBLE_REPORT_ID 0x01 + static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) { /* TODO: Can this be modified to turn off motion tracking? */ @@ -49,12 +60,20 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + // Turn on the appropriate LED report_buffer[11] = 1 << ((device->slot % 4) + 1); + // Set rumble state report_buffer[4] = device->motors[1] >> 8; report_buffer[6] = device->motors[0] >> 8; #ifdef HAVE_WIIUSB_HID report_buffer[1] = 0x03; /* send control message type */ device->driver->send_control(device->connection, &report_buffer[1], sizeof(report_buffer)-1); +#elif defined(WIIU) + device->driver->set_report(device->connection, + HID_REPORT_OUTPUT, + DS3_RUMBLE_REPORT_ID, + report_buffer+2, + sizeof(report_buffer) - (2*sizeof(uint8_t))); #else device->driver->send_control(device->connection, report_buffer, sizeof(report_buffer)); #endif @@ -62,7 +81,7 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device) static void* hidpad_ps3_init(void *data, uint32_t slot, hid_driver_t *driver) { -#ifdef HAVE_WIIUSB_HID +#if defined(HAVE_WIIUSB_HID) || defined(WIIU) /* Special command to enable Sixaxis, first byte defines the message type */ static uint8_t magic_data[] = {0x02, 0x42, 0x0c, 0x00, 0x00}; #elif defined(IOS) @@ -90,6 +109,16 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, hid_driver_t *driver) device->driver->send_control(device->connection, magic_data, sizeof(magic_data)); #endif +#ifdef WIIU + device->driver->set_protocol(device->connection, 1); + hidpad_ps3_send_control(device); + device->driver->set_report(device->connection, + HID_REPORT_FEATURE, + DS3_ACTIVATION_REPORT_ID, + magic_data+1, + (sizeof(magic_data) - sizeof(uint8_t))); +#endif + #ifndef HAVE_WIIUSB_HID /* Without this, the digital buttons won't be reported. */ hidpad_ps3_send_control(device); diff --git a/input/input_driver.h b/input/input_driver.h index 22df4b1c60..28711502aa 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -196,7 +196,7 @@ struct hid_driver void (*send_control)(void *data, uint8_t *buf, size_t size); int32_t (*set_report)(void *, uint8_t, uint8_t, void *, uint32_t); int32_t (*set_idle)(void *, uint8_t, uint8_t); - int32_t (*set_protocol)(void *, uint8_t, uint8_t); + int32_t (*set_protocol)(void *, uint8_t); }; diff --git a/wiiu/include/wiiu/syshid.h b/wiiu/include/wiiu/syshid.h index 2c058e6765..385f42acab 100644 --- a/wiiu/include/wiiu/syshid.h +++ b/wiiu/include/wiiu/syshid.h @@ -1,6 +1,15 @@ #pragma once #include +/* + * Report types for the report_type parameter in HIDSetReport() + */ + +// what is 1? +#define HID_REPORT_OUTPUT 2 +#define HID_REPORT_FEATURE 3 +// are there more? + typedef struct { uint32_t handle; From 661e5bf50bab879e04d83b91195d2d7ca174b98e Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 17 Dec 2017 22:15:21 -0800 Subject: [PATCH 18/26] Implement new functions in hid_driver_t in WiiU driver == DETAILS This implements the WiiU-specific functions. Since the wiiu_hid_t data structure contains the handle and interface index, the method signatures can be simplified quite a bit. And since (at least for now) we want these to be synchronous, we don't need to expose the callback parameters. --- input/drivers_hid/wiiu_hid.c | 47 +++++++++++++++++++++++++++++++----- input/input_driver.h | 2 +- wiiu/include/wiiu/syshid.h | 2 +- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 6e1f8923b8..6b53877d89 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -133,13 +133,44 @@ static void wiiu_hid_poll(void *data) (void)data; } -static void wiiu_hid_device_send_control(void *data, - uint8_t *buffer, - size_t buffer_size) { - struct wiiu_adapter *adapter = (struct wiiu_adapter *)data; +static int32_t wiiu_hid_set_report(void *data, uint8_t report_type, report_id, + void *report_data, uint32_t report_length) +{ + wiiu_hid_t *hid = (wiiu_hid_t)data; - if(!adapter) - return; + if(!hid) + return -1; + + return HIDSetReport(hid->handle, + report_type, + report_id, + report_data, + report_length, + NULL, NULL); +} + +static int32_t wiiu_hid_set_idle(void *data, uint8_t duration) +{ + wiiu_hid_t *hid = (wiiu_hid_t)data; + if(!hid) + return -1; + + return HIDSetIdle(hid->handle, + hid->interface_index, + duration, + NULL, NULL); +} + +static int32_t wiiu_hid_set_protocol(void *data, uint8_t protocol) +{ + wiiu_hid_t *hid = (wiiu_hid_t)data; + if(!hid) + return -1; + + return HIDSetProtocol(hid->handle, + hid->interface_index, + protocol, + NULL, NULL); } static void start_polling_thread(wiiu_hid_t *hid) { @@ -419,4 +450,8 @@ hid_driver_t wiiu_hid = { wiiu_hid_joypad_rumble, wiiu_hid_joypad_name, "wiiu", + NULL, // send_control + wiiu_hid_set_report, + wiiu_hid_set_idle, + wiiu_hid_set_protocol }; diff --git a/input/input_driver.h b/input/input_driver.h index 28711502aa..38d1401d67 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -195,7 +195,7 @@ struct hid_driver const char *ident; void (*send_control)(void *data, uint8_t *buf, size_t size); int32_t (*set_report)(void *, uint8_t, uint8_t, void *, uint32_t); - int32_t (*set_idle)(void *, uint8_t, uint8_t); + int32_t (*set_idle)(void *, uint8_t); int32_t (*set_protocol)(void *, uint8_t); }; diff --git a/wiiu/include/wiiu/syshid.h b/wiiu/include/wiiu/syshid.h index 385f42acab..a940225dfa 100644 --- a/wiiu/include/wiiu/syshid.h +++ b/wiiu/include/wiiu/syshid.h @@ -104,7 +104,7 @@ HIDSetIdle(uint32_t handle, int32_t HIDSetProtocol(uint32_t handle, - uint8_t int32_terface_index, + uint8_t interface_index, uint8_t protocol, HIDCallback hc, void *p_user); From 7954dab835833f252095fe48843b129dba0ced84 Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 21 Dec 2017 15:56:03 -0800 Subject: [PATCH 19/26] Progress on I/O handling == DETAILS Starting to implement the I/O handling on the HID driver. The old implementation basically had a never-ending HIDRead() callback set up, so that callback N would start the read process for invocation N+1. We will take the same approach here; but now that the I/O thread is happenning on its own core, we should be able to let it run full- throttle without impacting emulator performance. Of course, this hinges on the callback actually running on the same core as the syscall was initiated on. == TESTING Can confirm that the read_loop_callback gets invoked on the same core that the HIDRead() was invoked on. --- input/connect/connect_wiiugca.c | 4 + input/drivers_hid/wiiu_hid.c | 138 ++++++++++++++++++++++++++------ input/drivers_hid/wiiu_hid.h | 29 ++++++- wiiu/system/imports.h | 3 + 4 files changed, 145 insertions(+), 29 deletions(-) diff --git a/input/connect/connect_wiiugca.c b/input/connect/connect_wiiugca.c index 92423481f4..9f4b0fbb7d 100644 --- a/input/connect/connect_wiiugca.c +++ b/input/connect/connect_wiiugca.c @@ -33,7 +33,11 @@ struct hidpad_wiiugca_data static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver) { +#ifdef WIIU + static uint8_t magic_data[] = {0x13}; /* Special command to enable reading */ +#else static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */ +#endif struct pad_connection* connection = (struct pad_connection*)data; struct hidpad_wiiugca_data* device = (struct hidpad_wiiugca_data*) calloc(1, sizeof(struct hidpad_wiiugca_data)); diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 6b53877d89..ca9d9970d5 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -19,10 +19,12 @@ #include #include #include +#include #include "wiiu_hid.h" static wiiu_event_list events; +static wiiu_adapter_list adapters; static bool wiiu_hid_joypad_query(void *data, unsigned pad) { @@ -87,7 +89,7 @@ static void *wiiu_hid_init(void) hid->connections = connections; - wiiu_hid_init_event_list(); + wiiu_hid_init_lists(); start_polling_thread(hid); if(!hid->polling_thread) goto error; @@ -133,15 +135,23 @@ static void wiiu_hid_poll(void *data) (void)data; } -static int32_t wiiu_hid_set_report(void *data, uint8_t report_type, report_id, - void *report_data, uint32_t report_length) +static void wiiu_hid_send_control(void *data, uint8_t *buf, size_t size) { - wiiu_hid_t *hid = (wiiu_hid_t)data; + wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; + if(!adapter) + return; - if(!hid) + HIDWrite(adapter->handle, buf, size, NULL, NULL); +} + +static int32_t wiiu_hid_set_report(void *data, uint8_t report_type, + uint8_t report_id, void *report_data, uint32_t report_length) +{ + wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; + if(!adapter) return -1; - return HIDSetReport(hid->handle, + return HIDSetReport(adapter->handle, report_type, report_id, report_data, @@ -151,24 +161,24 @@ static int32_t wiiu_hid_set_report(void *data, uint8_t report_type, report_id, static int32_t wiiu_hid_set_idle(void *data, uint8_t duration) { - wiiu_hid_t *hid = (wiiu_hid_t)data; - if(!hid) + wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; + if(!adapter) return -1; - return HIDSetIdle(hid->handle, - hid->interface_index, + return HIDSetIdle(adapter->handle, + adapter->interface_index, duration, NULL, NULL); } static int32_t wiiu_hid_set_protocol(void *data, uint8_t protocol) { - wiiu_hid_t *hid = (wiiu_hid_t)data; - if(!hid) + wiiu_adapter_t *adapter = (wiiu_adapter_t *)data; + if(!adapter) return -1; - return HIDSetProtocol(hid->handle, - hid->interface_index, + return HIDSetProtocol(adapter->handle, + adapter->interface_index, protocol, NULL, NULL); } @@ -200,6 +210,8 @@ static void start_polling_thread(wiiu_hid_t *hid) { goto error; } + OSSetThreadCleanupCallback(thread, wiiu_hid_polling_thread_cleanup); + hid->polling_thread = thread; hid->polling_thread_stack = stack; OSResumeThread(thread); @@ -246,6 +258,7 @@ static void log_device(HIDDevice *device) { RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx); } + static void synchronized_add_event(wiiu_attach_event *event) { OSFastMutex_Lock(&(events.lock)); event->next = events.list; @@ -263,7 +276,11 @@ static wiiu_attach_event *synchronized_get_events_list(void) { return list; } -static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter) { +static void synchronized_add_to_adapters_list(wiiu_adapter_t *adapter) { + OSFastMutex_Lock(&(adapters.lock)); + adapter->next = adapters.list; + adapters.list = adapter; + OSFastMutex_Unlock(&(adapters.lock)); } static int32_t wiiu_attach_callback(HIDClient *client, HIDDevice *device, uint32_t attach) { @@ -295,7 +312,7 @@ static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event) { static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { - struct wiiu_adapter *adapter = new_adapter(); + wiiu_adapter_t *adapter = new_adapter(event); if(!adapter) { RARCH_ERR("[hid]: Failed to allocate adapter.\n"); @@ -303,9 +320,11 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { } adapter->hid = hid; - adapter->handle = event->handle; + + RARCH_LOG("[hid]: pad_connection_pad_init\n"); adapter->slot = pad_connection_pad_init(hid->connections, - "hid", event->vendor_id, event->product_id, adapter, +// "hid", event->vendor_id, event->product_id, adapter, + "hid", SWAP16(event->vendor_id), SWAP16(event->product_id), adapter, &wiiu_hid); if(adapter->slot < 0) { @@ -313,19 +332,72 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { goto error; } + RARCH_LOG("[hid]: got slot %d\n", adapter->slot); + if(!pad_connection_has_interface(hid->connections, adapter->slot)) { RARCH_ERR("[hid]: Interface not found for HID device with vid=0x%04x pid=0x%04x\n", event->vendor_id, event->product_id); goto error; } + RARCH_LOG("[hid]: adding to adapter list\n"); synchronized_add_to_adapters_list(adapter); + RARCH_LOG("[hid]: starting read loop\n"); + wiiu_start_read_loop(adapter); return; error: delete_adapter(adapter); } +void wiiu_start_read_loop(wiiu_adapter_t *adapter) +{ + adapter->state = ADAPTER_STATE_READING; + HIDRead(adapter->handle, adapter->rx_buffer, adapter->rx_size, wiiu_hid_read_loop_callback, adapter); +} + +static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, + uint8_t *buffer, uint32_t buffer_size, void *userdata) +{ + uint32_t coreId = OSGetCoreId(); + wiiu_adapter_t *adapter = (wiiu_adapter_t *)userdata; + if(!adapter) + { + RARCH_ERR("read_loop_callback: bad userdata\n"); + return; + } + + RARCH_LOG("read_loop_callback running on core %d\n", coreId); + usleep(5000); + if(!adapter->hid->polling_thread_quit) { + adapter->state = ADAPTER_STATE_READING; + HIDRead(adapter->handle, adapter->rx_buffer, adapter->rx_size, + wiiu_hid_read_loop_callback, adapter); + return; + } + + adapter->state = ADAPTER_STATE_DONE; +} + +/** + * Block until all the HIDRead() calls have returned. + */ +static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack) { + int not_done = 0; + wiiu_adapter_t *adapter; + do { + OSFastMutex_Lock(&(adapters.lock)); + not_done = 0; + for(adapter = adapters.list; adapter != NULL; adapter = adapter->next) { + if(adapter->state != ADAPTER_STATE_DONE) { + not_done++; + } + } + OSFastMutex_Unlock(&(adapters.lock)); + usleep(1000); + } while(not_done); +} + static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list) { wiiu_attach_event *event; if(!hid || !list) @@ -365,10 +437,13 @@ static OSThread *new_thread(void) { return t; } -static void wiiu_hid_init_event_list(void) { +static void wiiu_hid_init_lists(void) { RARCH_LOG("[hid]: Initializing events list\n"); memset(&events, 0, sizeof(events)); OSFastMutex_Init(&(events.lock), "attach_events"); + RARCH_LOG("[hid]: Initializing adapters list\n"); + memset(&adapters, 0, sizeof(adapters)); + OSFastMutex_Init(&(adapters.lock), "adapters"); } static wiiu_hid_t *new_hid(void) { @@ -393,15 +468,27 @@ static void delete_hidclient(HIDClient *client) { free(client); } -static struct wiiu_adapter *new_adapter(void) { +static wiiu_adapter_t *new_adapter(wiiu_attach_event *event) { RARCH_LOG("[hid]: new_adapter()\n"); - return alloc_zeroed(4, sizeof(struct wiiu_adapter)); + + wiiu_adapter_t *adapter = alloc_zeroed(64, sizeof(wiiu_adapter_t)); + adapter->handle = event->handle; + adapter->interface_index = event->interface_index; + adapter->rx_size = event->max_packet_size_rx; + adapter->rx_buffer = alloc_zeroed(64, adapter->rx_size); + + return adapter; } -static void delete_adapter(struct wiiu_adapter *adapter) { +static void delete_adapter(wiiu_adapter_t *adapter) { RARCH_LOG("[hid]: delete_adapter()\n"); - if(adapter) + if(adapter) { + if(adapter->rx_buffer) { + free(adapter->rx_buffer); + adapter->rx_buffer = NULL; + } free(adapter); + } } static wiiu_attach_event *new_attach_event(HIDDevice *device) { @@ -413,7 +500,7 @@ static wiiu_attach_event *new_attach_event(HIDDevice *device) { return NULL; event->handle = device->handle; event->vendor_id = device->vid; - event->product_id = device->vid; + event->product_id = device->pid; event->interface_index = device->interface_index; event->is_keyboard = (device->sub_class == 1 && device->protocol == 1); event->is_mouse = (device->sub_class == 1 && device->protocol == 2); @@ -450,8 +537,9 @@ hid_driver_t wiiu_hid = { wiiu_hid_joypad_rumble, wiiu_hid_joypad_name, "wiiu", - NULL, // send_control + wiiu_hid_send_control, wiiu_hid_set_report, wiiu_hid_set_idle, wiiu_hid_set_protocol }; + diff --git a/input/drivers_hid/wiiu_hid.h b/input/drivers_hid/wiiu_hid.h index d2f4bc0715..2609ff73b7 100644 --- a/input/drivers_hid/wiiu_hid.h +++ b/input/drivers_hid/wiiu_hid.h @@ -26,6 +26,10 @@ #define MAX_HID_PADS 5 +#define ADAPTER_STATE_NEW 0 +#define ADAPTER_STATE_READING 1 +#define ADAPTER_STATE_DONE 2 + typedef struct wiiu_hid { HIDClient *client; @@ -35,10 +39,17 @@ typedef struct wiiu_hid volatile bool polling_thread_quit; } wiiu_hid_t; +typedef struct wiiu_adapter wiiu_adapter_t; + struct wiiu_adapter { + wiiu_adapter_t *next; wiiu_hid_t *hid; + uint8_t state; + uint8_t *rx_buffer; + uint32_t rx_size; int32_t slot; uint32_t handle; + uint8_t interface_index; }; typedef struct wiiu_attach wiiu_attach_event; @@ -57,24 +68,30 @@ struct wiiu_attach { }; typedef struct _wiiu_event_list wiiu_event_list; +typedef struct _wiiu_adapter_list wiiu_adapter_list; struct _wiiu_event_list { OSFastMutex lock; wiiu_attach_event *list; }; +struct _wiiu_adapter_list { + OSFastMutex lock; + wiiu_adapter_t *list; +}; + static void *alloc_zeroed(size_t alignment, size_t size); static OSThread *new_thread(void); static wiiu_hid_t *new_hid(void); static void delete_hid(wiiu_hid_t *hid); static void delete_hidclient(HIDClient *client); static HIDClient *new_hidclient(void); -static struct wiiu_adapter *new_adapter(void); -static void delete_adapter(struct wiiu_adapter *adapter); +static wiiu_adapter_t *new_adapter(wiiu_attach_event *event); +static void delete_adapter(wiiu_adapter_t *adapter); static wiiu_attach_event *new_attach_event(HIDDevice *device); static void delete_attach_event(wiiu_attach_event *); -static void wiiu_hid_init_event_list(void); +static void wiiu_hid_init_lists(void); static void start_polling_thread(wiiu_hid_t *hid); static void stop_polling_thread(wiiu_hid_t *hid); static int wiiu_hid_polling_thread(int argc, const char **argv); @@ -83,7 +100,11 @@ static wiiu_attach_event *synchronized_get_events_list(void); static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list); static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event); static void wiiu_hid_detach(wiiu_hid_t *hid, wiiu_attach_event *event); -static void synchronized_add_to_adapters_list(struct wiiu_adapter *adapter); +static void synchronized_add_to_adapters_list(wiiu_adapter_t *adapter); static void synchronized_add_event(wiiu_attach_event *event); +static void wiiu_start_read_loop(wiiu_adapter_t *adapter); +static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, + uint8_t *buffer, uint32_t buffer_size, void *userdata); +static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack); #endif // __WIIU_HID__H diff --git a/wiiu/system/imports.h b/wiiu/system/imports.h index 11dc810352..12acb41878 100644 --- a/wiiu/system/imports.h +++ b/wiiu/system/imports.h @@ -24,11 +24,14 @@ IMPORT(OSGetTitleID); IMPORT(OSIsThreadTerminated); IMPORT(OSSetThreadPriority); IMPORT(OSCreateThread); +IMPORT(OSSetThreadCleanupCallback); IMPORT(OSResumeThread); IMPORT(OSIsThreadSuspended); IMPORT(OSSuspendThread); IMPORT(OSJoinThread); IMPORT(OSYieldThread); +IMPORT(OSGetCoreId); +IMPORT(OSIsMainCore); IMPORT(OSGetSystemTime); IMPORT(OSGetSystemTick); IMPORT(OSGetSymbolName); From 0f66bc3297dc98325a9b52c8de95659310a397a4 Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 24 Dec 2017 14:58:48 -0800 Subject: [PATCH 20/26] Implement HID read loop, add debug logging == DETAILS I haven't figured out how I'm going to get the data read via HIDRead() funneled back to the adapter--the handle_packet() method doesn't actually get called anywhere. I'm probably going to need to do more tweaking to the function pointer list. This commit also adds logging for the data read via HIDRead. == TESTING I used my "stress test" (which I used to reproduce the crash caused by the old HID implementation), and it did not crash. --- input/connect/connect_wiiugca.c | 26 +++++----- input/drivers_hid/wiiu_hid.c | 88 ++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 26 deletions(-) diff --git a/input/connect/connect_wiiugca.c b/input/connect/connect_wiiugca.c index 9f4b0fbb7d..156ab8bb87 100644 --- a/input/connect/connect_wiiugca.c +++ b/input/connect/connect_wiiugca.c @@ -70,13 +70,13 @@ static void hidpad_wiiugca_deinit(void *data) static void hidpad_wiiugca_get_buttons(void *data, retro_bits_t *state) { - struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data; - if (device) - { - BITS_COPY16_PTR(state, device->buttons); - } - else - BIT256_CLEAR_ALL_PTR(state); + struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data; + if (device) + { + BITS_COPY16_PTR(state, device->buttons); + } + else + BIT256_CLEAR_ALL_PTR(state); } static int16_t hidpad_wiiugca_get_axis(void *data, unsigned axis) @@ -134,16 +134,16 @@ static void hidpad_wiiugca_packet_handler(void *data, uint8_t *packet, uint16_t static void hidpad_wiiugca_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength) { - (void)data; - (void)effect; - (void)strength; + (void)data; + (void)effect; + (void)strength; } const char * hidpad_wiiugca_get_name(void *data) { - (void)data; - /* For now we return a single static name */ - return "Wii U GC Controller Adapter"; + (void)data; + /* For now we return a single static name */ + return "Wii U GC Controller Adapter"; } pad_connection_interface_t pad_connection_wiiugca = { diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index ca9d9970d5..f2e9577de5 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -356,10 +356,57 @@ void wiiu_start_read_loop(wiiu_adapter_t *adapter) HIDRead(adapter->handle, adapter->rx_buffer, adapter->rx_size, wiiu_hid_read_loop_callback, adapter); } +/** + * Takes a buffer and formats it for the log file, 16 bytes per line. + * + * When the end of the buffer is reached, it is padded out with 0xff. So e.g. + * a 5-byte buffer might look like: + * + * 5 bytes read fro HIDRead: + * 0102030405ffffff ffffffffffffffff + * ================================== + */ +static void log_buffer(uint8_t *data, uint32_t len) { +(uint8_t *)data; +(uint32_t)len; + + int i, o; + int padding = len % 16; + uint8_t buf[16]; + + RARCH_LOG("%d bytes read from HIDRead:\n", len); + for(i = 0, o = 0; i < len; i++) { + buf[o] = data[i]; + o++; + if(o == 16) { + o = 0; + RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %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], + buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); + } + } + if(padding) { + for(i = padding; i < 16; i++) + buf[i] = 0xff; + + RARCH_LOG("%02x%02x%02x%02x%02x%02x%02x%02x %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], + buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); + } + RARCH_LOG("==================================\n"); + +} + +static void wiiu_hid_do_read(wiiu_adapter_t *adapter, uint8_t *data, uint32_t length) +{ + log_buffer(data, length); + // do_sampling() + // do other stuff? +} + static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, uint8_t *buffer, uint32_t buffer_size, void *userdata) { - uint32_t coreId = OSGetCoreId(); wiiu_adapter_t *adapter = (wiiu_adapter_t *)userdata; if(!adapter) { @@ -367,35 +414,50 @@ static void wiiu_hid_read_loop_callback(uint32_t handle, int32_t error, return; } - RARCH_LOG("read_loop_callback running on core %d\n", coreId); - usleep(5000); - if(!adapter->hid->polling_thread_quit) { - adapter->state = ADAPTER_STATE_READING; - HIDRead(adapter->handle, adapter->rx_buffer, adapter->rx_size, - wiiu_hid_read_loop_callback, adapter); + if(adapter->hid->polling_thread_quit) { + RARCH_LOG("Shutting down read loop for slot %d\n", adapter->slot); + adapter->state = ADAPTER_STATE_DONE; return; } - adapter->state = ADAPTER_STATE_DONE; + wiiu_hid_do_read(adapter, buffer, buffer_size); + + adapter->state = ADAPTER_STATE_READING; + HIDRead(adapter->handle, adapter->rx_buffer, adapter->rx_size, + wiiu_hid_read_loop_callback, adapter); } /** * Block until all the HIDRead() calls have returned. */ static void wiiu_hid_polling_thread_cleanup(OSThread *thread, void *stack) { - int not_done = 0; + int incomplete = 0; wiiu_adapter_t *adapter; + RARCH_LOG("Waiting for in-flight reads to finish.\n"); do { OSFastMutex_Lock(&(adapters.lock)); - not_done = 0; + incomplete = 0; for(adapter = adapters.list; adapter != NULL; adapter = adapter->next) { if(adapter->state != ADAPTER_STATE_DONE) { - not_done++; + incomplete++; + } + } + // We are clear for shutdown. Clean up the list while we are holding + // the lock. + if(incomplete == 0) { + while(adapters.list != NULL) { + adapter = adapters.list; + adapters.list = adapter->next; + delete_adapter(adapter); } } OSFastMutex_Unlock(&(adapters.lock)); - usleep(1000); - } while(not_done); + if(incomplete) { + RARCH_LOG("%d unfinished adapters found, waiting 1ms\n", incomplete); + usleep(1000); + } + } while(incomplete); + RARCH_LOG("All in-flight reads complete.\n"); } static void wiiu_handle_attach_events(wiiu_hid_t *hid, wiiu_attach_event *list) { From 8f900de65ee81e7144f97e6f2a7cb5fe7c502580 Mon Sep 17 00:00:00 2001 From: gblues Date: Sun, 24 Dec 2017 18:29:00 -0800 Subject: [PATCH 21/26] Clean up USB VID/PID declarations == DETAILS USB Vendor and Product IDs are in little-endian byte order, and they need to be byteswapped on big-endian systems. This approach allows us to use the standard hex notation for the VID/HID values, and give them meaningful names, and only swap on the platforms that need it. Also prevents having to abuse SWAP16() in the platform- specific code. --- input/connect/joypad_connection.c | 29 ++++++++++++++++------------- input/connect/joypad_connection.h | 19 ++++++++++++++++++- input/drivers_hid/wiiu_hid.c | 3 +-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index a74847ed5a..dcc6000bdf 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -20,6 +20,7 @@ #include #include "../input_driver.h" +#include "../../verbosity.h" #include "joypad_connection.h" @@ -75,16 +76,16 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, pad_connection_interface_t *iface; } pad_map[] = { - { "Nintendo RVL-CNT-01", 1406, 816, &pad_connection_wii }, - { "Nintendo RVL-CNT-01-UC", 1406, 816, &pad_connection_wiiupro }, - { "Wireless Controller", 1356, 1476, &pad_connection_ps4 }, - { "PLAYSTATION(R)3 Controller", 1356, 616, &pad_connection_ps3 }, - { "PLAYSTATION(R)3 Controller", 787, 8406, &pad_connection_ps3 }, - { "Generic SNES USB Controller", 2079, 58369, &pad_connection_snesusb }, - { "Generic NES USB Controller", 121, 17, &pad_connection_nesusb }, - { "Wii U GC Controller Adapter", 1406, 823, &pad_connection_wiiugca }, - { "PS2/PSX Controller Adapter", 2064, 1, &pad_connection_ps2adapter }, - { "PSX to PS3 Controller Adapter", 2064, 3, &pad_connection_psxadapter }, + { "Nintendo RVL-CNT-01", VID_NINTENDO, PID_NINTENDO_PRO, &pad_connection_wii }, + { "Nintendo RVL-CNT-01-UC", VID_NINTENDO, PID_NINTENDO_PRO, &pad_connection_wiiupro }, + { "Wireless Controller", VID_SONY, PID_SONY_DS4, &pad_connection_ps4 }, + { "PLAYSTATION(R)3 Controller", VID_SONY, PID_SONY_DS3, &pad_connection_ps3 }, + { "PLAYSTATION(R)3 Controller", VID_PS3_CLONE, PID_DS3_CLONE, &pad_connection_ps3 }, + { "Generic SNES USB Controller", VID_SNES_CLONE, PID_SNES_CLONE, &pad_connection_snesusb }, + { "Generic NES USB Controller", VID_MICRONTEK, PID_MICRONTEK_NES, &pad_connection_nesusb }, + { "Wii U GC Controller Adapter", VID_NINTENDO, PID_NINTENDO_GCA, &pad_connection_wiiugca }, + { "PS2/PSX Controller Adapter", VID_PCS, PID_PCS_PS2PSX, &pad_connection_ps2adapter }, + { "PSX to PS3 Controller Adapter", VID_PCS, PID_PCS_PSX2PS3, &pad_connection_psxadapter }, { "Mayflash DolphinBar", 1406, 774, &pad_connection_wii }, { 0, 0} }; @@ -112,9 +113,11 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn, } #if 0 - RARCH_LOG("name: %s\n", name); - RARCH_LOG("%d VID, PID %d (config)\n", vid, pid); - RARCH_LOG("%d VID, PID %d\n", pad_map[i].vid, pad_map[i].pid); + RARCH_LOG("[connect] %s\n", pad_map[i].name); + RARCH_LOG("[connect] VID: Expected: %04x got: %04x\n", + pad_map[i].vid, vid); + RARCH_LOG("[connect] PID: Expected: %04x got: %04x\n", + pad_map[i].pid, pid); #endif if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid)) diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 07f221fd29..2bbf2ad438 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -22,9 +22,26 @@ #include #include - +#include #include "../input_driver.h" +#define VID_NINTENDO swap_if_big16(0x057e) +#define VID_SONY swap_if_big16(0x054c) +#define VID_MICRONTEK swap_if_big16(0x0079) +#define VID_PCS swap_if_big16(0x0810) +#define VID_PS3_CLONE swap_if_big16(0x0313) +#define VID_SNES_CLONE swap_if_big16(0x081f) + +#define PID_NINTENDO_PRO swap_if_big16(0x0330) +#define PID_SONY_DS3 swap_if_big16(0x0268) +#define PID_SONY_DS4 swap_if_big16(0x05c4) +#define PID_DS3_CLONE swap_if_big16(0x20d6) +#define PID_SNES_CLONE swap_if_big16(0xe401) +#define PID_MICRONTEK_NES swap_if_big16(0x0011) +#define PID_NINTENDO_GCA swap_if_big16(0x0337) +#define PID_PCS_PS2PSX swap_if_big16(0x0001) +#define PID_PCS_PSX2PS3 swap_if_big16(0x0003) + struct joypad_connection { bool connected; diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index f2e9577de5..1545a7544e 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -323,8 +323,7 @@ static void wiiu_hid_attach(wiiu_hid_t *hid, wiiu_attach_event *event) { RARCH_LOG("[hid]: pad_connection_pad_init\n"); adapter->slot = pad_connection_pad_init(hid->connections, -// "hid", event->vendor_id, event->product_id, adapter, - "hid", SWAP16(event->vendor_id), SWAP16(event->product_id), adapter, + "hid", event->vendor_id, event->product_id, adapter, &wiiu_hid); if(adapter->slot < 0) { From 52c754cfa83bbab1f2bdc2bea36c9ac0673fd3ce Mon Sep 17 00:00:00 2001 From: gblues Date: Wed, 27 Dec 2017 15:15:01 -0800 Subject: [PATCH 22/26] Split wiiu_gamepad into three sub-drivers == DETAILS Well, after a lot of code analysis, this seems like the best way to handle things on the Wii U without also completely re-architecting the I/O handling in RetroArch. How it works: - the top-level wiiu_joypad driver is now nothing more than a delegator. - the wiiu-specific drivers live in `wiiu/input/` - wpad_driver.c handles the WiiU gamepad - kpad_driver.c handles the wiimotes - hidpad_driver.c will handle HID devices like the GC adapter, DS3/DS4, etc. (I say "will" because this isn't implemented yet) == TESTING Haven't actually tried the build to see if it works, but it does compile. --- Makefile.wiiu | 4 + input/connect/joypad_connection.h | 2 + input/drivers_hid/wiiu_hid.c | 2 +- input/drivers_joypad/wiiu_joypad.c | 385 ++++++++--------------------- wiiu/include/wiiu/pad_driver.h | 102 ++++++++ wiiu/input/hidpad_driver.c | 99 ++++++++ wiiu/input/kpad_driver.c | 195 +++++++++++++++ wiiu/input/pad_functions.c | 98 ++++++++ wiiu/input/wpad_driver.c | 208 ++++++++++++++++ 9 files changed, 807 insertions(+), 288 deletions(-) create mode 100644 wiiu/include/wiiu/pad_driver.h create mode 100644 wiiu/input/hidpad_driver.c create mode 100644 wiiu/input/kpad_driver.c create mode 100644 wiiu/input/pad_functions.c create mode 100644 wiiu/input/wpad_driver.c diff --git a/Makefile.wiiu b/Makefile.wiiu index 4f8dfa3e9b..cdbdd7c6ef 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -15,6 +15,10 @@ PC_DEVELOPMENT_TCP_PORT ?=4405 OBJ := OBJ += input/drivers_hid/wiiu_hid.o +OBJ += wiiu/input/wpad_driver.o +OBJ += wiiu/input/kpad_driver.o +OBJ += wiiu/input/hidpad_driver.o +OBJ += wiiu/input/pad_functions.o OBJ += wiiu/system/memory.o OBJ += wiiu/system/exception_handler.o OBJ += wiiu/system/missing_libc_functions.o diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 2bbf2ad438..ec78b3c4df 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -25,6 +25,7 @@ #include #include "../input_driver.h" +#define VID_NONE 0x0000 #define VID_NINTENDO swap_if_big16(0x057e) #define VID_SONY swap_if_big16(0x054c) #define VID_MICRONTEK swap_if_big16(0x0079) @@ -32,6 +33,7 @@ #define VID_PS3_CLONE swap_if_big16(0x0313) #define VID_SNES_CLONE swap_if_big16(0x081f) +#define PID_NONE 0x0000 #define PID_NINTENDO_PRO swap_if_big16(0x0330) #define PID_SONY_DS3 swap_if_big16(0x0268) #define PID_SONY_DS4 swap_if_big16(0x05c4) diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 1545a7544e..a08937e628 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -398,7 +398,7 @@ static void log_buffer(uint8_t *data, uint32_t len) { static void wiiu_hid_do_read(wiiu_adapter_t *adapter, uint8_t *data, uint32_t length) { - log_buffer(data, length); + // log_buffer(data, length); // do_sampling() // do other stuff? } diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 4fb667c34d..5418c215f2 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -14,320 +14,131 @@ * If not, see . */ -#ifdef HAVE_CONFIG_H -#include "../../config.h" -#endif - -#include -#include - -#include "../input_driver.h" - -#include "../../tasks/tasks_internal.h" -#include "../../retroarch.h" -#include "../../command.h" -#include "../../gfx/video_driver.h" -#include "string.h" +#include #include "wiiu_dbg.h" -#ifndef MAX_PADS -#define MAX_PADS 5 -#endif +static input_device_driver_t *pad_drivers[MAX_USERS]; +static bool ready = false; -#define WIIUINPUT_TYPE_WIIMOTE 0x00 -#define WIIUINPUT_TYPE_NUNCHUK 0x01 -#define WIIUINPUT_TYPE_CLASSIC_CONTROLLER 0x02 -#define WIIUINPUT_TYPE_PRO_CONTROLLER 0x1F -#define WIIUINPUT_TYPE_NONE 0xFD +static bool wiiu_joypad_init(void *data); +static bool wiiu_joypad_query_pad(unsigned pad); +static void wiiu_joypad_destroy(void); +static bool wiiu_joypad_button(unsigned pad, uint16_t button); +static void wiiu_joypad_get_buttons(unsigned pad, retro_bits_t *state); +static int16_t wiiu_joypad_axis(unsigned pad, uint32_t axis); +static void wiiu_joypad_poll(void); +static const char *wiiu_joypad_name(unsigned pad); -#define GAMEPAD_OFFSET 0 - -static uint64_t pad_state[MAX_PADS]; -static uint8_t pad_type[MAX_PADS-1] = {WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE, WIIUINPUT_TYPE_NONE}; - -/* 3 axis - one for touch/future IR support? */ -static int16_t analog_state[MAX_PADS][3][2]; -static bool wiiu_pad_inited = false; - -static const char* wiiu_joypad_name(unsigned pad) +/** + * Translates a pad to its appropriate driver. + * Note that this is a helper for build_pad_map and shouldn't be + * used directly. + */ +static input_device_driver_t *get_driver_for_pad(unsigned pad) { - if (pad > MAX_PADS) return "N/A"; + if(wpad_driver.query_pad(pad)) + return &wpad_driver; + if(kpad_driver.query_pad(pad)) + return &kpad_driver; - if (pad == GAMEPAD_OFFSET) - return "WIIU Gamepad"; - - if (pad < MAX_PADS) - { - switch (pad_type[pad-1]) - { - case WIIUINPUT_TYPE_PRO_CONTROLLER: - return "WIIU Pro Controller"; - - case WIIUINPUT_TYPE_WIIMOTE: - return "Wiimote Controller"; - - case WIIUINPUT_TYPE_NUNCHUK: - return "Nunchuk Controller"; - - case WIIUINPUT_TYPE_CLASSIC_CONTROLLER: - return "Classic Controller"; - - case WIIUINPUT_TYPE_NONE: - default: - return "N/A"; - } - } - - return "unknown"; + return &hidpad_driver; } -static void wiiu_joypad_autodetect_add(unsigned autoconf_pad) +/** + * Populates the pad_driver array. We do this once at init time so + * that lookups at runtime are constant time. + */ +static void build_pad_map(void) { - if (!input_autoconfigure_connect( - wiiu_joypad_name(autoconf_pad), - NULL, - wiiu_joypad.ident, - autoconf_pad, - 0, - 0 - )) - input_config_set_device_name(autoconf_pad, wiiu_joypad_name(autoconf_pad)); -} + unsigned i; -static bool wiiu_joypad_button(unsigned port_num, uint16_t key) -{ - if (port_num >= MAX_PADS) - return false; - - return (pad_state[port_num] & (UINT64_C(1) << key)); -} - -static void wiiu_joypad_get_buttons(unsigned port_num, retro_bits_t *state) -{ - if (port_num < MAX_PADS) - { - BITS_COPY16_PTR( state, pad_state[port_num] ); - } - else - BIT256_CLEAR_ALL_PTR(state); -} - -static int16_t wiiu_joypad_axis(unsigned port_num, uint32_t joyaxis) -{ - int val = 0; - int axis = -1; - bool is_neg = false; - bool is_pos = false; - - if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) - return 0; - - if (AXIS_NEG_GET(joyaxis) < 6) - { - axis = AXIS_NEG_GET(joyaxis); - is_neg = true; - } - else if (AXIS_POS_GET(joyaxis) < 6) - { - axis = AXIS_POS_GET(joyaxis); - is_pos = true; - } - - switch (axis) - { - case 0: - val = analog_state[port_num][0][0]; - break; - - case 1: - val = analog_state[port_num][0][1]; - break; - - case 2: - val = analog_state[port_num][1][0]; - break; - - case 3: - val = analog_state[port_num][1][1]; - break; - - //For position data; just return the unmodified value - case 4: - return analog_state[port_num][2][0]; - - case 5: - return analog_state[port_num][2][1]; - } - - if (is_neg && val > 0) - val = 0; - else if (is_pos && val < 0) - val = 0; - - return val; -} - -static int16_t scaleTP(int16_t oldMin, int16_t oldMax, int16_t newMin, int16_t newMax, int16_t val) { - int32_t oldRange = oldMax - oldMin; - int32_t newRange = newMax - newMin; - return (((val - oldMin) * newRange) / oldRange) + newMin; -} - -static void wiiu_joypad_poll(void) -{ - int i, c; - VPADStatus vpad; - VPADReadError vpadError; - #if defined(ENABLE_CONTROLLER_PATCHER) - int result; - #endif - - VPADRead(0, &vpad, 1, &vpadError); - - if (!vpadError) - { - pad_state[0] = vpad.hold & VPAD_MASK_BUTTONS; /* buttons only */ - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = vpad.leftStick.x * 0x7FF0; - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = vpad.leftStick.y * 0x7FF0; - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = vpad.rightStick.x * 0x7FF0; - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = vpad.rightStick.y * 0x7FF0; - - /* You can only call VPADData once every loop, else the second one - won't get any data. Thus; I had to hack touch support into the existing - joystick API. Woo-hoo? Misplaced requests for touch axis are filtered - out in wiiu_input. - */ - if (vpad.tpNormal.touched && vpad.tpNormal.validity == VPAD_VALID) { - struct video_viewport vp = {0}; - video_driver_get_viewport_info(&vp); - VPADTouchData cal720p = {0}; - /* Calibrates data to a 720p screen, seems to clamp outer 12px */ - VPADGetTPCalibratedPoint(0, &cal720p, &(vpad.tpNormal)); - /* Recalibrate to match video driver's coordinate system */ - VPADTouchData calNative = {0}; - calNative.x = scaleTP(12, 1268, 0, vp.full_width, cal720p.x); - calNative.y = scaleTP(12, 708, 0, vp.full_height, cal720p.y); - /* Clamp to actual game image */ - VPADTouchData calClamped = calNative; - bool touchClamped = false; - if (calClamped.x < vp.x) { - calClamped.x = vp.x; - touchClamped = true; - } else if (calClamped.x > vp.x + vp.width) { - calClamped.x = vp.x + vp.width; - touchClamped = true; - } - if (calClamped.y < vp.y) { - calClamped.y = vp.y; - touchClamped = true; - } else if (calClamped.y > vp.y + vp.height) { - calClamped.y = vp.y + vp.height; - touchClamped = true; - } - /* Calibrate to libretro spec and save as axis 2 (idx 4,5) */ - analog_state[0][2][0] = scaleTP(vp.x, vp.x + vp.width, -0x7fff, 0x7fff, calClamped.x); - analog_state[0][2][1] = scaleTP(vp.y, vp.y + vp.height, -0x7fff, 0x7fff, calClamped.y); - - /* Emulating a button (#19) for touch; lets people assign it to menu - for that traditional RetroArch Wii U feel */ - if (!touchClamped) { - pad_state[0] |= VPAD_BUTTON_TOUCH; - } else { - pad_state[0] &= ~VPAD_BUTTON_TOUCH; - } - } else { - /* This is probably 0 anyway */ - pad_state[0] &= ~VPAD_BUTTON_TOUCH; - } - - /* panic button */ - if ((vpad.hold & (VPAD_BUTTON_R | VPAD_BUTTON_L | VPAD_BUTTON_STICK_R | VPAD_BUTTON_STICK_L)) - == (VPAD_BUTTON_R | VPAD_BUTTON_L | VPAD_BUTTON_STICK_R | VPAD_BUTTON_STICK_L)) - command_event(CMD_EVENT_QUIT, NULL); - } - - for (c = 0; c < 4; c++) - { - KPADData kpad; - - if (!KPADRead(c, &kpad, 1)) - continue; - - if (pad_type[c] != kpad.device_type) - { - pad_type[c] = kpad.device_type; - wiiu_joypad_autodetect_add(c + 1); - } - - switch (kpad.device_type) - { - case WIIUINPUT_TYPE_WIIMOTE: - pad_state[c + 1] = kpad.btns_h; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = 0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = 0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = 0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = 0; - break; - - case WIIUINPUT_TYPE_NUNCHUK: - pad_state[c + 1] = kpad.btns_h; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = kpad.nunchuck.stick_x * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = kpad.nunchuck.stick_y * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = 0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = 0; - break; - - case WIIUINPUT_TYPE_PRO_CONTROLLER: - pad_state[c + 1] = kpad.classic.btns_h & ~0x3FC0000; /* clear out emulated analog sticks */ - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = kpad.classic.lstick_x * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = kpad.classic.lstick_y * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = kpad.classic.rstick_x * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = kpad.classic.rstick_y * 0x7FF0; - break; - - case WIIUINPUT_TYPE_CLASSIC_CONTROLLER: - pad_state[c + 1] = kpad.classic.btns_h & ~0xFF0000; /* clear out emulated analog sticks */ - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = kpad.classic.lstick_x * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = kpad.classic.lstick_y * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = kpad.classic.rstick_x * 0x7FF0; - analog_state[c + 1][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = kpad.classic.rstick_y * 0x7FF0; - break; - } - } + for(i = 0; i < MAX_USERS; i++) + { + pad_drivers[i] = get_driver_for_pad(i); + } } static bool wiiu_joypad_init(void* data) { - wiiu_joypad_autodetect_add(0); + // the sub-drivers have to init first, otherwise + // build_pad_map will fail (because all lookups will return false). + wpad_driver.init(data); + kpad_driver.init(data); + hidpad_driver.init(data); - wiiu_joypad_poll(); - wiiu_pad_inited = true; - (void)data; + build_pad_map(); - return true; + ready = true; + (void)data; + + return true; } static bool wiiu_joypad_query_pad(unsigned pad) { - return pad < MAX_PADS && wiiu_pad_inited; + return ready && pad < MAX_USERS; } static void wiiu_joypad_destroy(void) { - wiiu_pad_inited = false; + ready = false; + + wpad_driver.destroy(); + kpad_driver.destroy(); + hidpad_driver.destroy(); +} + +static bool wiiu_joypad_button(unsigned pad, uint16_t key) +{ + if(!wiiu_joypad_query_pad(pad)) + return false; + + return pad_drivers[pad]->button(pad, key); +} + +static void wiiu_joypad_get_buttons(unsigned pad, retro_bits_t *state) +{ + if(!wiiu_joypad_query_pad(pad)) + return; + + pad_drivers[pad]->get_buttons(pad, state); +} + +static int16_t wiiu_joypad_axis(unsigned pad, uint32_t joyaxis) +{ + if(!wiiu_joypad_query_pad(pad)) + return 0; + + return pad_drivers[pad]->axis(pad, joyaxis); +} + +static void wiiu_joypad_poll(void) +{ + wpad_driver.poll(); + kpad_driver.poll(); + hidpad_driver.poll(); +} + +static const char* wiiu_joypad_name(unsigned pad) +{ + if(!wiiu_joypad_query_pad(pad)) + return "N/A"; + + return pad_drivers[pad]->name(pad); } input_device_driver_t wiiu_joypad = { - wiiu_joypad_init, - wiiu_joypad_query_pad, - wiiu_joypad_destroy, - wiiu_joypad_button, - wiiu_joypad_get_buttons, - wiiu_joypad_axis, - wiiu_joypad_poll, - NULL, - wiiu_joypad_name, - "wiiu", + wiiu_joypad_init, + wiiu_joypad_query_pad, + wiiu_joypad_destroy, + wiiu_joypad_button, + wiiu_joypad_get_buttons, + wiiu_joypad_axis, + wiiu_joypad_poll, + NULL, + wiiu_joypad_name, + "wiiu", }; + diff --git a/wiiu/include/wiiu/pad_driver.h b/wiiu/include/wiiu/pad_driver.h new file mode 100644 index 0000000000..c91104c249 --- /dev/null +++ b/wiiu/include/wiiu/pad_driver.h @@ -0,0 +1,102 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +#ifndef __PAD_DRIVER__H +#define __PAD_DRIVER__H + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif // HAVE_CONFIG_H + +#include +#include +#include + +#include "../../input/input_driver.h" +#include "../../input/connect/joypad_connection.h" +#include "../../tasks/tasks_internal.h" +#include "../../retroarch.h" +#include "../../verbosity.h" +#include "../../command.h" +#include "../../gfx/video_driver.h" + +/** + * Magic button sequence that triggers an exit. Useful for if the visuals are + * corrupted, but won't work in the case of a hard lock. + */ +#define PANIC_BUTTON_MASK (VPAD_BUTTON_R | VPAD_BUTTON_L | VPAD_BUTTON_STICK_R | VPAD_BUTTON_STICK_L) + +/** + * Applies a standard transform to the Wii U gamepad's analog stick. + * No idea where 0x7ff0 comes from. + */ + +#define WIIU_ANALOG_FACTOR 0x7ff0 +#define WIIU_READ_STICK(stick) ((stick) * WIIU_ANALOG_FACTOR) + +/** + * the wiimote driver uses these to delimit which pads correspond to the + * wiimotes. + */ +#define PAD_GAMEPAD 0 +#define WIIU_WIIMOTE_CHANNELS 4 + +/** + * These are used by the wiimote driver to identify the wiimote configuration + * attached to the channel. + */ +// wiimote with Wii U Pro controller +#define WIIMOTE_TYPE_PRO 0x1f +// wiimote with Classic Controller +#define WIIMOTE_TYPE_CLASSIC 0x02 +// wiimote with nunchuk +#define WIIMOTE_TYPE_NUNCHUK 0x01 +// wiimote plus (no accessory attached) +#define WIIMOTE_TYPE_WIIPLUS 0x00 +// wiimote not attached on this channel +#define WIIMOTE_TYPE_NONE 0xFD + +/** + * The Wii U gamepad and wiimotes have 3 sets of x/y axes. The third + * is used by the gamepad for the touchpad driver; the wiimotes is + * currently unimplemented, but could be used for future IR pointer + * support. + */ +#define WIIU_DEVICE_INDEX_TOUCHPAD 2 + +typedef struct _axis_data axis_data; + +struct _axis_data { + int32_t axis; + bool is_negative; +}; + +typedef struct _wiiu_pad_functions wiiu_pad_functions_t; + +struct _wiiu_pad_functions { + int16_t (*get_axis_value)(int32_t axis, int16_t state[3][2], bool is_negative); + void (*set_axis_value)(int16_t state[3][2], int16_t left_x, int16_t left_y, + int16_t right_x, int16_t right_y, int16_t touch_x, int16_t touch_y); + void (*read_axis_data)(uint32_t axis, axis_data *data); + void (*connect)(unsigned pad, input_device_driver_t *driver); +}; + +extern wiiu_pad_functions_t pad_functions; +extern input_device_driver_t wpad_driver; +extern input_device_driver_t kpad_driver; +extern input_device_driver_t hidpad_driver; + +#endif // __PAD_DRIVER__H diff --git a/wiiu/input/hidpad_driver.c b/wiiu/input/hidpad_driver.c new file mode 100644 index 0000000000..18682aa6ab --- /dev/null +++ b/wiiu/input/hidpad_driver.c @@ -0,0 +1,99 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +#include + +static bool hidpad_init(void *data); +static bool hidpad_query_pad(unsigned pad); +static void hidpad_destroy(void); +static bool hidpad_button(unsigned pad, uint16_t button); +static void hidpad_get_buttons(unsigned pad, retro_bits_t *state); +static int16_t hidpad_axis(unsigned pad, uint32_t axis); +static void hidpad_poll(void); +static const char *hidpad_name(unsigned pad); + +static bool ready = false; + +// if the GameCube adapter is attached, this will be the offset +// of the first pad. +static unsigned gca_pad = 0; +static joypad_connection_t *hid_pads; + +static bool hidpad_init(void *data) +{ + (void *)data; + hid_pads = pad_connection_init(MAX_USERS-(WIIU_WIIMOTE_CHANNELS+1)); + + hidpad_poll(); + ready = true; + + return true; +} + +static bool hidpad_query_pad(unsigned pad) +{ + return (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS); +} + +static void hidpad_destroy(void) +{ + ready = false; + if(hid_pads) { + pad_connection_destroy(hid_pads); + hid_pads = NULL; + } +} + +static bool hidpad_button(unsigned pad, uint16_t button) +{ + return false; +} + +static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) +{ + BIT256_CLEAR_ALL_PTR(state); +} + +static int16_t hidpad_axis(unsigned pad, uint32_t axis) +{ + return 0; +} + +static void hidpad_poll(void) +{ +} + +static const char *hidpad_name(unsigned pad) +{ + if(!hidpad_query_pad(pad)) + return "n/a"; + + return "Unknown"; +} + +input_device_driver_t hidpad_driver = +{ + hidpad_init, + hidpad_query_pad, + hidpad_destroy, + hidpad_button, + hidpad_get_buttons, + hidpad_axis, + hidpad_poll, + NULL, + hidpad_name, + "hid" +}; diff --git a/wiiu/input/kpad_driver.c b/wiiu/input/kpad_driver.c new file mode 100644 index 0000000000..e2d9363c5d --- /dev/null +++ b/wiiu/input/kpad_driver.c @@ -0,0 +1,195 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +/** + * This sub-driver handles the wiimotes. The Wii U has 4 channels available. + * This also handles wiimote attachments such as the nunchuk and classic/pro + * controllers. + */ + +#include + +static bool kpad_init(void *data); +static bool kpad_query_pad(unsigned pad); +static void kpad_destroy(void); +static bool kpad_button(unsigned pad, uint16_t button); +static void kpad_get_buttons(unsigned pad, retro_bits_t *state); +static int16_t kpad_axis(unsigned pad, uint32_t axis); +static void kpad_poll(void); +static const char *kpad_name(unsigned pad); + +typedef struct _wiimote_state wiimote_state; + +struct _wiimote_state { + uint64_t button_state; + int16_t analog_state[3][2]; + uint8_t type; +}; + +static bool ready = false; + +wiimote_state wiimotes[WIIU_WIIMOTE_CHANNELS]; + +static unsigned to_wiimote_channel(unsigned pad) { + if(pad == PAD_GAMEPAD || pad > WIIU_WIIMOTE_CHANNELS) + return 0xffffffff; + + return pad-1; +} + +static unsigned to_retro_pad(unsigned channel) { + return channel+1; +} + +static bool kpad_init(void *data) +{ + (void *)data; + + kpad_poll(); + ready = true; +} + +static bool kpad_query_pad(unsigned pad) +{ + return ready && pad <= WIIU_WIIMOTE_CHANNELS && pad > PAD_GAMEPAD; +} + +static void kpad_destroy(void) +{ + ready = false; +} + +static bool kpad_button(unsigned pad, uint16_t button_bit) +{ + if(!kpad_query_pad(pad)) + return false; + + return wiimotes[to_wiimote_channel(pad)].button_state & (UINT64_C(1) << button_bit); +} + +static void kpad_get_buttons(unsigned pad, retro_bits_t *state) +{ + if(!kpad_query_pad(pad)) + BIT256_CLEAR_ALL_PTR(state); + else + BITS_COPY16_PTR(state, wiimotes[to_wiimote_channel(pad)].button_state); +} + +static int16_t kpad_axis(unsigned pad, uint32_t axis) +{ + axis_data data; + if(!kpad_query_pad(pad) || axis == AXIS_NONE) + return 0; + + pad_functions.read_axis_data(axis, &data); + return pad_functions.get_axis_value(data.axis, wiimotes[to_wiimote_channel(pad)].analog_state, data.is_negative); +} + +static void kpad_register(unsigned channel, uint8_t device_type) +{ + if(wiimotes[channel].type != device_type) { + wiimotes[channel].type = device_type; + pad_functions.connect(to_retro_pad(channel), &kpad_driver); + } +} + +#define WIIU_PRO_BUTTON_MASK 0x3FC0000; +#define CLASSIC_BUTTON_MASK 0xFF0000; + +static void kpad_poll_one_channel(unsigned channel, KPADData *kpad) +{ + kpad_register(channel, kpad->device_type); + switch(kpad->device_type) + { + case WIIMOTE_TYPE_PRO: + wiimotes[channel].button_state = kpad->classic.btns_h & ~WIIU_PRO_BUTTON_MASK; + pad_functions.set_axis_value(wiimotes[channel].analog_state, + WIIU_READ_STICK(kpad->classic.lstick_x), + WIIU_READ_STICK(kpad->classic.lstick_y), + WIIU_READ_STICK(kpad->classic.rstick_x), + WIIU_READ_STICK(kpad->classic.rstick_y), 0, 0); + break; + case WIIMOTE_TYPE_CLASSIC: + wiimotes[channel].button_state = kpad->classic.btns_h & ~CLASSIC_BUTTON_MASK; + pad_functions.set_axis_value(wiimotes[channel].analog_state, + WIIU_READ_STICK(kpad->classic.lstick_x), + WIIU_READ_STICK(kpad->classic.lstick_y), + WIIU_READ_STICK(kpad->classic.rstick_x), + WIIU_READ_STICK(kpad->classic.rstick_y), 0, 0); + break; + case WIIMOTE_TYPE_NUNCHUK: + wiimotes[channel].button_state = kpad->btns_h; + pad_functions.set_axis_value(wiimotes[channel].analog_state, + WIIU_READ_STICK(kpad->nunchuck.stick_x), + WIIU_READ_STICK(kpad->nunchuck.stick_y), 0, 0, 0, 0); + break; + case WIIMOTE_TYPE_WIIPLUS: + wiimotes[channel].button_state = kpad->btns_h; + pad_functions.set_axis_value(wiimotes[channel].analog_state, 0, 0, 0, 0, 0, 0); + break; + } +} + +static void kpad_poll(void) +{ + unsigned channel; + + for(channel = 0; channel < WIIU_WIIMOTE_CHANNELS; channel++) + { + KPADData kpad; + + if(!KPADRead(channel, &kpad, 1)) + continue; + + kpad_poll_one_channel(channel, &kpad); + } +} + +static const char *kpad_name(unsigned pad) +{ + pad = to_wiimote_channel(pad); + if(pad >= WIIU_WIIMOTE_CHANNELS) + return "unknown"; + + switch(wiimotes[pad].type) + { + case WIIMOTE_TYPE_PRO: + return "WiiU Pro Controller"; + case WIIMOTE_TYPE_CLASSIC: + return "Classic Controller"; + case WIIMOTE_TYPE_NUNCHUK: + return "Wiimote+Nunchuk Controller"; + case WIIMOTE_TYPE_WIIPLUS: + return "Wiimote Controller"; + case WIIMOTE_TYPE_NONE: + default: + return "N/A"; + } +} + +input_device_driver_t kpad_driver = +{ + kpad_init, + kpad_query_pad, + kpad_destroy, + kpad_button, + kpad_get_buttons, + kpad_axis, + kpad_poll, + NULL, + kpad_name, + "wiimote", +}; diff --git a/wiiu/input/pad_functions.c b/wiiu/input/pad_functions.c new file mode 100644 index 0000000000..b0203d088b --- /dev/null +++ b/wiiu/input/pad_functions.c @@ -0,0 +1,98 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +#include + +enum wiiu_pad_axes { + AXIS_LEFT_ANALOG_X, + AXIS_LEFT_ANALOG_Y, + AXIS_RIGHT_ANALOG_X, + AXIS_RIGHT_ANALOG_Y, + AXIS_TOUCH_X, + AXIS_TOUCH_Y, + AXIS_INVALID +}; + +static int16_t clamp_axis(int16_t value, bool is_negative) { + if(is_negative && value > 0) + return 0; + if(!is_negative && value < 0) + return 0; + + return value; +} + +static int16_t wiiu_pad_get_axis_value(int32_t axis, int16_t state[3][2], bool is_negative) { + int16_t value = 0; + + switch(axis) { + case AXIS_LEFT_ANALOG_X: + value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X]; + break; + case AXIS_LEFT_ANALOG_Y: + value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y]; + break; + case AXIS_RIGHT_ANALOG_X: + value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X]; + break; + case AXIS_RIGHT_ANALOG_Y: + value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y]; + break; + case AXIS_TOUCH_X: + return state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X]; + case AXIS_TOUCH_Y: + return state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y]; + } + + return clamp_axis(value, is_negative); +} + +void wiiu_pad_set_axis_value(int16_t state[3][2], int16_t left_x, int16_t left_y, + int16_t right_x, int16_t right_y, int16_t touch_x, int16_t touch_y) +{ + state[RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = left_x; + state[RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = left_y; + state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = right_x; + state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = right_y; + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X] = touch_x; + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = touch_y; +} + + +void wiiu_pad_read_axis_data(uint32_t axis, axis_data *data) { + data->axis = AXIS_POS_GET(axis); + data->is_negative = false; + + if(data->axis >= AXIS_INVALID) { + data->axis = AXIS_NEG_GET(axis); + data->is_negative = true; + } +} + +void wiiu_pad_connect(unsigned pad, input_device_driver_t *driver) { + if(!input_autoconfigure_connect(driver->name(pad), NULL, driver->ident, + pad, VID_NONE, PID_NONE)) + { + input_config_set_device_name(pad, driver->name(pad)); + } +} + +wiiu_pad_functions_t pad_functions = { + wiiu_pad_get_axis_value, + wiiu_pad_set_axis_value, + wiiu_pad_read_axis_data, + wiiu_pad_connect +}; diff --git a/wiiu/input/wpad_driver.c b/wiiu/input/wpad_driver.c new file mode 100644 index 0000000000..8ba7a5cb92 --- /dev/null +++ b/wiiu/input/wpad_driver.c @@ -0,0 +1,208 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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 RetroArch. + * If not, see . + */ + +/** + * This driver handles the Wii U Gamepad. + * + * - For wiimote and wiimote attachments, see kpad_driver.c + * - For HID controllers, see hid_driver.c + */ + +#include + +static bool wpad_init(void *data); +static bool wpad_query_pad(unsigned pad); +static void wpad_destroy(void); +static bool wpad_button(unsigned pad, uint16_t button); +static void wpad_get_buttons(unsigned pad, retro_bits_t *state); +static int16_t wpad_axis(unsigned pad, uint32_t axis); +static void wpad_poll(void); +static const char *wpad_name(unsigned pad); + +static void update_button_state(uint64_t *state, uint32_t held_buttons); +static void update_analog_state(int16_t state[3][2], VPADStatus *vpad); +static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatus *vpad); +static void get_touch_coordinates(VPADTouchData *point, VPADStatus *vpad, bool *clamped); +static void get_calibrated_point(VPADTouchData *point, struct video_viewport *viewport, VPADStatus *vpad); +static void apply_clamping(VPADTouchData *point, struct video_viewport *viewport, bool *clamped); +static void check_panic_button(uint32_t held_buttons); + +static int16_t scale_touchpad(int16_t from_min, int16_t from_max, + int16_t to_min, int16_t to_max, int16_t value ); + +static bool ready = false; +static uint64_t button_state = 0; +static int16_t analog_state[3][2]; + +static bool wpad_init(void *data) { + pad_functions.connect(PAD_GAMEPAD, &wpad_driver); + wpad_poll(); + ready = true; + + return true; +} + +static bool wpad_query_pad(unsigned pad) { + return ready && pad == PAD_GAMEPAD; +} + +static void wpad_destroy(void) { + ready = false; +} + +static bool wpad_button(unsigned pad, uint16_t button_bit) { + if(!wpad_query_pad(pad)) + return false; + + return button_state & (UINT64_C(1) << button_bit); +} + +static void wpad_get_buttons(unsigned pad, retro_bits_t *state) { + if(!wpad_query_pad(pad)) + BIT256_CLEAR_ALL_PTR(state); + else + BITS_COPY16_PTR(state, button_state); +} + +static int16_t wpad_axis(unsigned pad, uint32_t axis) { + axis_data data; + + if(!wpad_query_pad(pad) || axis == AXIS_NONE) + return 0; + + pad_functions.read_axis_data(axis, &data); + return pad_functions.get_axis_value(data.axis, analog_state, data.is_negative); +} + +static void wpad_poll(void) { + VPADStatus vpad; + VPADReadError error; + + VPADRead(PAD_GAMEPAD, &vpad, 1, &error); + + if(!error) { + update_button_state(&button_state, vpad.hold); + update_analog_state(analog_state, &vpad); + update_touch_state(analog_state, &button_state, &vpad); + check_panic_button(vpad.hold); + } +} + +static void update_button_state(uint64_t *state, uint32_t held_buttons) +{ + *state = held_buttons & VPAD_MASK_BUTTONS; +} + +static void update_analog_state(int16_t state[3][2], VPADStatus *vpad) +{ + state[RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = WIIU_READ_STICK(vpad->leftStick.x); + state[RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = WIIU_READ_STICK(vpad->leftStick.y); + state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = WIIU_READ_STICK(vpad->rightStick.x); + state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = WIIU_READ_STICK(vpad->rightStick.y); +} + +static void update_touch_state(int16_t state[3][2], uint64_t *buttons, VPADStatus *vpad) +{ + VPADTouchData point = {0}; + bool touch_clamped = false; + + if(!vpad->tpNormal.touched || vpad->tpNormal.validity != VPAD_VALID) + { + *buttons &= ~VPAD_BUTTON_TOUCH; + return; + } + + get_touch_coordinates(&point, vpad, &touch_clamped); + + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_X] = point.x; + state[WIIU_DEVICE_INDEX_TOUCHPAD][RETRO_DEVICE_ID_ANALOG_Y] = point.y; + + if(!touch_clamped) { + *buttons |= VPAD_BUTTON_TOUCH; + } else { + *buttons &= ~VPAD_BUTTON_TOUCH; + } +} + +static void get_touch_coordinates(VPADTouchData *point, VPADStatus *vpad, bool *clamped) +{ + struct video_viewport viewport = {0}; + + video_driver_get_viewport_info(&viewport); + get_calibrated_point(point, &viewport, vpad); + apply_clamping(point, &viewport, clamped); +} + +static void get_calibrated_point(VPADTouchData *point, struct video_viewport *viewport, VPADStatus *vpad) { + VPADTouchData calibrated720p = {0}; + + VPADGetTPCalibratedPoint(PAD_GAMEPAD, &calibrated720p, &(vpad->tpNormal)); + point->x = scale_touchpad(12, 1268, 0, viewport->full_width, calibrated720p.x); + point->y = scale_touchpad(12, 708, 0, viewport->full_height, calibrated720p.y); +} + +static void apply_clamping(VPADTouchData *point, struct video_viewport *viewport, bool *clamped) { + // clamp the x domain to the viewport + if(point->x < viewport->x) { + point->x = viewport->x; + *clamped = true; + } else if(point->x > (viewport->x + viewport->width)) { + point->x = viewport->x + viewport->width; + *clamped = true; + } + // clamp the y domain to the viewport + if(point->y < viewport->y) { + point->y = viewport->y; + *clamped = true; + } else if(point->y > (viewport->y + viewport->height)) { + point->y = viewport->y + viewport->height; + *clamped = true; + } +} + +static void check_panic_button(uint32_t held_buttons) { + if( (held_buttons & PANIC_BUTTON_MASK) == PANIC_BUTTON_MASK) + { + command_event(CMD_EVENT_QUIT, NULL); + } +} + +static int16_t scale_touchpad(int16_t from_min, int16_t from_max, + int16_t to_min, int16_t to_max, int16_t value ) +{ + int32_t from_range = from_max - from_min; + int32_t to_range = to_max - to_min; + + return (((value - from_min) * to_range) / from_range) + to_min; +} + +static const char *wpad_name(unsigned pad) { + return "WiiU Gamepad"; +} + +input_device_driver_t wpad_driver = +{ + wpad_init, + wpad_query_pad, + wpad_destroy, + wpad_button, + wpad_get_buttons, + wpad_axis, + wpad_poll, + NULL, + wpad_name, + "gamepad", +}; From 0ae7ffe0d340b95bc2aa3cbe91f3839a7a5e3e0d Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 28 Dec 2017 13:01:38 -0800 Subject: [PATCH 23/26] Clean up dumb compile warnings, fix crash bug == DETAILS - the free() method of the hid_driver_t interface needs its parameter defined as const in order for the compiler to stop complaining about losing const-ness. - if a joypad list is created with connected = false; + entry->iface = NULL; + entry->data = (void *)0xdeadbeef; +} + +static bool joypad_is_end_of_list(joypad_connection_t *pad) { + return pad && !pad->connected && !pad->iface && pad->data == (void *)0xdeadbeef; +} + +/** + * Since the pad_connection_destroy() call needs to iterate through this + * list, we allocate pads+1 entries and use the extra spot to store a + * marker. + */ joypad_connection_t *pad_connection_init(unsigned pads) { unsigned i; joypad_connection_t *joyconn = (joypad_connection_t*) - calloc(pads, sizeof(joypad_connection_t)); + calloc(pads+1, sizeof(joypad_connection_t)); if (!joyconn) return NULL; @@ -60,6 +77,8 @@ joypad_connection_t *pad_connection_init(unsigned pads) conn->data = NULL; } + set_end_of_list(joyconn, pads); + return joyconn; } @@ -208,7 +227,12 @@ void pad_connection_destroy(joypad_connection_t *joyconn) unsigned i; for (i = 0; i < MAX_USERS; i ++) - pad_connection_pad_deinit(&joyconn[i], i); + { + if(joypad_is_end_of_list(&joyconn[i])) + break; + + pad_connection_pad_deinit(&joyconn[i], i); + } free(joyconn); } diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 4dee87a4bb..0017f8d633 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -44,7 +44,6 @@ typedef struct wiiu_input { bool blocked; const input_device_driver_t *joypad; - const hid_driver_t *hid_joypad; } wiiu_input_t; void kb_connection_callback(KBDKeyEvent *key) @@ -126,8 +125,6 @@ static void wiiu_input_poll(void *data) if(wiiu->joypad) wiiu->joypad->poll(); - if(wiiu->hid_joypad) - wiiu->hid_joypad->poll(hid_driver_get_data()); } static bool wiiu_key_pressed(int key) @@ -181,12 +178,6 @@ static void wiiu_input_free_input(void *data) if (wiiu && wiiu->joypad) wiiu->joypad->destroy(); - if (wiiu && wiiu->hid_joypad) - { - wiiu->hid_joypad->free(hid_driver_get_data()); - hid_driver_reset_data(); - } - KBDTeardown(); free(data); @@ -200,7 +191,6 @@ static void* wiiu_input_init(const char *joypad_driver) DEBUG_STR(joypad_driver); wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu); - wiiu->hid_joypad = input_hid_init_first(); KBDSetup(&kb_connection_callback, &kb_disconnection_callback,&kb_key_callback); diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index dc6ea0b645..1d277484aa 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -1424,7 +1424,7 @@ static int16_t btstack_hid_joypad_axis(void *data, unsigned port, uint32_t joyax return val; } -static void btstack_hid_free(void *data) +static void btstack_hid_free(const void *data) { btstack_hid_t *hid = (btstack_hid_t*)data; diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index 2aa88b3a86..98a53901db 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -830,7 +830,7 @@ error: return NULL; } -static void iohidmanager_hid_free(void *data) +static void iohidmanager_hid_free(const void *data) { iohidmanager_hid_t *hid_apple = (iohidmanager_hid_t*)data; diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index a28ee4d96e..44580359fa 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -509,7 +509,7 @@ static int16_t libusb_hid_joypad_axis(void *data, return val; } -static void libusb_hid_free(void *data) +static void libusb_hid_free(const void *data) { libusb_hid_t *hid = (libusb_hid_t*)data; diff --git a/input/drivers_hid/null_hid.c b/input/drivers_hid/null_hid.c index ce657d8b90..70a34d4bf8 100644 --- a/input/drivers_hid/null_hid.c +++ b/input/drivers_hid/null_hid.c @@ -80,7 +80,7 @@ static void *null_hid_init(void) return (null_hid_t*)calloc(1, sizeof(null_hid_t)); } -static void null_hid_free(void *data) +static void null_hid_free(const void *data) { null_hid_t *hid_null = (null_hid_t*)data; diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index a08937e628..5a61f2273e 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -111,7 +111,7 @@ static void *wiiu_hid_init(void) return NULL; } -static void wiiu_hid_free(void *data) +static void wiiu_hid_free(const void *data) { wiiu_hid_t *hid = (wiiu_hid_t*)data; diff --git a/input/drivers_hid/wiiusb_hid.c b/input/drivers_hid/wiiusb_hid.c index 031e54db8c..397f0a0a64 100644 --- a/input/drivers_hid/wiiusb_hid.c +++ b/input/drivers_hid/wiiusb_hid.c @@ -546,7 +546,7 @@ static int16_t wiiusb_hid_joypad_axis(void *data, return val; } -static void wiiusb_hid_free(void *data) +static void wiiusb_hid_free(const void *data) { struct wiiusb_adapter *adapter = NULL; struct wiiusb_adapter *next_adapter = NULL; diff --git a/input/input_driver.h b/input/input_driver.h index 38d1401d67..f9795e087a 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -185,7 +185,7 @@ struct hid_driver { void *(*init)(void); bool (*query_pad)(void *, unsigned); - void (*free)(void *); + void (*free)(const void *); bool (*button)(void *, unsigned, uint16_t); void (*get_buttons)(void *, unsigned, retro_bits_t *); int16_t (*axis)(void *, unsigned, uint32_t); diff --git a/wiiu/include/wiiu/pad_driver.h b/wiiu/include/wiiu/pad_driver.h index c91104c249..9cdcb47f41 100644 --- a/wiiu/include/wiiu/pad_driver.h +++ b/wiiu/include/wiiu/pad_driver.h @@ -69,6 +69,18 @@ // wiimote not attached on this channel #define WIIMOTE_TYPE_NONE 0xFD +/** + * These are used to map pad names to controller mappings. You can + * change these relatively free-form. + */ + +#define PAD_NAME_WIIU_GAMEPAD "WiiU Gamepad" +#define PAD_NAME_WIIU_PRO "WiiU Pro Controller" +#define PAD_NAME_WIIMOTE "Wiimote Controller" +#define PAD_NAME_NUNCHUK "Wiimote+Nunchuk Controller" +#define PAD_NAME_CLASSIC "Classic Controller" +#define PAD_NAME_HID "HID Controller" + /** * The Wii U gamepad and wiimotes have 3 sets of x/y axes. The third * is used by the gamepad for the touchpad driver; the wiimotes is @@ -95,6 +107,7 @@ struct _wiiu_pad_functions { }; extern wiiu_pad_functions_t pad_functions; +extern input_device_driver_t wiiu_joypad; extern input_device_driver_t wpad_driver; extern input_device_driver_t kpad_driver; extern input_device_driver_t hidpad_driver; From 704cc61fd8cf55537c111bf649286de15ad0b82c Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 28 Dec 2017 15:06:39 -0800 Subject: [PATCH 24/26] Fix bug in autodetect macro, gamepad now works properly == DETAILS The gamepad didn't work because I had tried to rename the pad from 'WIIU Gamepad' to 'WiiU Gamepad'. I added some debug logging and (to cut out a lot of trial-and-error) discovered that the reason it didn't work was because a bug in a macro was using the define literally instead of substituting it (so e.g. the autodetect handler was trying to match 'WiiU Gamepad' against the literal string 'PAD_NAME_WIIU_GAMEPAD'). - Fixed the macro bug - Left a minimal amount of the debug logging in place; may come in handy for someone else. - Updated wpad/kpad/hidpad to use the define constants == TESTING Did a test build and confirmed the gamepad responded. --- input/input_autodetect_builtin.c | 20 +++++++++++--------- tasks/task_autodetect.c | 21 +++++++++++++++++---- wiiu/input/hidpad_driver.c | 2 +- wiiu/input/kpad_driver.c | 8 ++++---- wiiu/input/wpad_driver.c | 2 +- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/input/input_autodetect_builtin.c b/input/input_autodetect_builtin.c index e9fb439510..32c723b4ac 100644 --- a/input/input_autodetect_builtin.c +++ b/input/input_autodetect_builtin.c @@ -28,12 +28,16 @@ #include #endif +#ifdef WIIU +#include +#endif + #define DECL_BTN(btn, bind) "input_" #btn "_btn = " #bind "\n" #define DECL_BTN_EX(btn, bind, name) "input_" #btn "_btn = " #bind "\ninput_" #btn "_btn_label = \"" name "\"\n" #define DECL_AXIS(axis, bind) "input_" #axis "_axis = " #bind "\n" #define DECL_AXIS_EX(axis, bind, name) "input_" #axis "_axis = " #bind "\ninput_" #axis "_axis_label = \"" name "\"\n" #define DECL_MENU(btn) "input_menu_toggle_btn = " #btn "\n" -#define DECL_AUTOCONF_DEVICE(device, driver, binds) "input_device = \"" #device "\" \ninput_driver = \"" #driver "\" \n" binds +#define DECL_AUTOCONF_DEVICE(device, driver, binds) "input_device = \"" device "\" \ninput_driver = \"" driver "\" \n" binds /* TODO/FIXME - Missing L2/R2 */ @@ -546,14 +550,12 @@ const char* const input_builtin_autoconfs[] = #endif #endif #ifdef WIIU - DECL_AUTOCONF_DEVICE("WIIU Gamepad", "wiiu", WIIUINPUT_GAMEPAD_DEFAULT_BINDS), - DECL_AUTOCONF_DEVICE("WIIU Pro Controller", "wiiu", WIIUINPUT_PRO_CONTROLLER_DEFAULT_BINDS), - DECL_AUTOCONF_DEVICE("Wiimote Controller", "wiiu", WIIUINPUT_WIIMOTE_DEFAULT_BINDS), - DECL_AUTOCONF_DEVICE("Nunchuk Controller", "wiiu", WIIUINPUT_NUNCHUK_DEFAULT_BINDS), - DECL_AUTOCONF_DEVICE("Classic Controller", "wiiu", WIIUINPUT_CLASSIC_CONTROLLER_DEFAULT_BINDS), - #if defined(ENABLE_CONTROLLER_PATCHER) - DECL_AUTOCONF_DEVICE("HID Controller", "wiiu", WIIUINPUT_GAMEPAD_DEFAULT_BINDS), - #endif + DECL_AUTOCONF_DEVICE(PAD_NAME_WIIU_GAMEPAD, "wiiu", WIIUINPUT_GAMEPAD_DEFAULT_BINDS), + DECL_AUTOCONF_DEVICE(PAD_NAME_WIIU_PRO, "wiiu", WIIUINPUT_PRO_CONTROLLER_DEFAULT_BINDS), + DECL_AUTOCONF_DEVICE(PAD_NAME_WIIMOTE, "wiiu", WIIUINPUT_WIIMOTE_DEFAULT_BINDS), + DECL_AUTOCONF_DEVICE(PAD_NAME_NUNCHUK, "wiiu", WIIUINPUT_NUNCHUK_DEFAULT_BINDS), + DECL_AUTOCONF_DEVICE(PAD_NAME_CLASSIC, "wiiu", WIIUINPUT_CLASSIC_CONTROLLER_DEFAULT_BINDS), + DECL_AUTOCONF_DEVICE(PAD_NAME_HID, "wiiu", WIIUINPUT_GAMEPAD_DEFAULT_BINDS), #endif #ifdef __CELLOS_LV2__ DECL_AUTOCONF_DEVICE("SixAxis Controller", "ps3", PS3INPUT_DEFAULT_BINDS), diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index f29dd82e7f..b0f6cb7224 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -194,7 +194,17 @@ static int input_autoconfigure_joypad_try_from_conf(config_file_t *conf, if (!string_is_empty(params->name) && !string_is_empty(ident) && string_is_equal(ident, params->name)) + { score += 2; + } else { + if(string_is_empty(params->name)) + RARCH_LOG("[autoconf]: failed match because params->name was empty\n"); + else if(string_is_empty(ident)) + RARCH_LOG("[autoconf]: failed match because ident was empty\n"); + else + RARCH_LOG("[autoconf]: failed match because ident '%s' != param->name '%s'\n", + ident, params->name); + } return score; } @@ -274,8 +284,9 @@ static int input_autoconfigure_joypad_from_conf( int ret = input_autoconfigure_joypad_try_from_conf(conf, params); - if (ret) + if (ret) { input_autoconfigure_joypad_add(conf, params, task); + } config_file_free(conf); @@ -312,8 +323,10 @@ static bool input_autoconfigure_joypad_from_conf_dir( DIR_LIST_AUTOCONFIG, "cfg"); } - if(!list) + if(!list) { + RARCH_LOG("[autoconf]: No profiles found.\n"); return false; + } if (list) { @@ -347,7 +360,7 @@ static bool input_autoconfigure_joypad_from_conf_dir( config_get_config_path(conf, conf_path, sizeof(conf_path)); - RARCH_LOG("[Autoconf]: selected configuration: %s\n", conf_path); + RARCH_LOG("[autoconf]: selected configuration: %s\n", conf_path); input_autoconfigure_joypad_add(conf, params, task); config_file_free(conf); ret = 1; @@ -374,7 +387,7 @@ static bool input_autoconfigure_joypad_from_conf_internal( config_file_t *conf = config_file_new_from_string( input_builtin_autoconfs[i]); if (conf && input_autoconfigure_joypad_from_conf(conf, params, task)) - return true; + return true; } if (string_is_empty(params->autoconfig_directory)) diff --git a/wiiu/input/hidpad_driver.c b/wiiu/input/hidpad_driver.c index 18682aa6ab..e8ed2452ad 100644 --- a/wiiu/input/hidpad_driver.c +++ b/wiiu/input/hidpad_driver.c @@ -81,7 +81,7 @@ static const char *hidpad_name(unsigned pad) if(!hidpad_query_pad(pad)) return "n/a"; - return "Unknown"; + return PAD_NAME_HID; } input_device_driver_t hidpad_driver = diff --git a/wiiu/input/kpad_driver.c b/wiiu/input/kpad_driver.c index e2d9363c5d..a4097981e8 100644 --- a/wiiu/input/kpad_driver.c +++ b/wiiu/input/kpad_driver.c @@ -167,13 +167,13 @@ static const char *kpad_name(unsigned pad) switch(wiimotes[pad].type) { case WIIMOTE_TYPE_PRO: - return "WiiU Pro Controller"; + return PAD_NAME_WIIU_PRO; case WIIMOTE_TYPE_CLASSIC: - return "Classic Controller"; + return PAD_NAME_CLASSIC; case WIIMOTE_TYPE_NUNCHUK: - return "Wiimote+Nunchuk Controller"; + return PAD_NAME_NUNCHUK; case WIIMOTE_TYPE_WIIPLUS: - return "Wiimote Controller"; + return PAD_NAME_WIIMOTE; case WIIMOTE_TYPE_NONE: default: return "N/A"; diff --git a/wiiu/input/wpad_driver.c b/wiiu/input/wpad_driver.c index 8ba7a5cb92..79d671e7e8 100644 --- a/wiiu/input/wpad_driver.c +++ b/wiiu/input/wpad_driver.c @@ -190,7 +190,7 @@ static int16_t scale_touchpad(int16_t from_min, int16_t from_max, } static const char *wpad_name(unsigned pad) { - return "WiiU Gamepad"; + return PAD_NAME_WIIU_GAMEPAD; } input_device_driver_t wpad_driver = From 65c177a0ee5ba01e09475ae939abab07433fd8c6 Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 28 Dec 2017 22:30:46 -0800 Subject: [PATCH 25/26] Move HID driver into wiiu/ code == DETAILS RetroArch's general HID drivers are intended as a full-on substitute for other input drivers such as XInput, DInput, SDL, etc. The Wii U port is, to my knowledge, the first case of heterogenous input drivers working concurrently. As such, I've moved things around: - The HID driver source is moved into the wiiu/input/ directory alongside the joypad subdrivers. - We no longer use the input_hid_init_first() method to instantiate; instead we just init the wiiu HID driver directly. - The HID pad driver and HID subsystem driver enjoy a tighter coupling, mainly having to do with the initialization of the joypad connections list, because there's no way to inform the HID driver's init() method how many slots to allocate. == TESTING Will test in a moment, but at least it compiles cleanly. ;) --- Makefile.wiiu | 2 +- input/input_driver.c | 3 - wiiu/include/wiiu/pad_driver.h | 66 +++++++++++++++++ wiiu/input/hidpad_driver.c | 78 ++++++++++++++++---- {input/drivers_hid => wiiu/input}/wiiu_hid.c | 32 ++++---- {input/drivers_hid => wiiu/input}/wiiu_hid.h | 58 +-------------- 6 files changed, 146 insertions(+), 93 deletions(-) rename {input/drivers_hid => wiiu/input}/wiiu_hid.c (96%) rename {input/drivers_hid => wiiu/input}/wiiu_hid.h (68%) diff --git a/Makefile.wiiu b/Makefile.wiiu index cdbdd7c6ef..4635c6faf3 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -14,7 +14,7 @@ PC_DEVELOPMENT_IP_ADDRESS ?=192.168.29.137 PC_DEVELOPMENT_TCP_PORT ?=4405 OBJ := -OBJ += input/drivers_hid/wiiu_hid.o +OBJ += wiiu/input/wiiu_hid.o OBJ += wiiu/input/wpad_driver.o OBJ += wiiu/input/kpad_driver.o OBJ += wiiu/input/hidpad_driver.o diff --git a/input/input_driver.c b/input/input_driver.c index f0d63cbb46..af88927b33 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -199,9 +199,6 @@ static hid_driver_t *hid_drivers[] = { #endif #ifdef HW_RVL &wiiusb_hid, -#endif -#ifdef WIIU - &wiiu_hid, #endif &null_hid, NULL, diff --git a/wiiu/include/wiiu/pad_driver.h b/wiiu/include/wiiu/pad_driver.h index 9cdcb47f41..7721077726 100644 --- a/wiiu/include/wiiu/pad_driver.h +++ b/wiiu/include/wiiu/pad_driver.h @@ -21,6 +21,11 @@ #include "../../config.h" #endif // HAVE_CONFIG_H +#include +#include +#include +#include +#include #include #include #include @@ -106,10 +111,71 @@ struct _wiiu_pad_functions { void (*connect)(unsigned pad, input_device_driver_t *driver); }; +/** + * HID driver data structures + */ + +typedef struct wiiu_hid { + // used to register for HID notifications + HIDClient *client; + // list of HID pads + joypad_connection_t *connections; + // size of connections list + unsigned connections_size; + // thread state data for HID polling thread + OSThread *polling_thread; + // stack space for polling thread + void *polling_thread_stack; + // watch variable to tell the polling thread to terminate + volatile bool polling_thread_quit; +} wiiu_hid_t; + +typedef struct wiiu_adapter wiiu_adapter_t; + +struct wiiu_adapter { + wiiu_adapter_t *next; + wiiu_hid_t *hid; + uint8_t state; + uint8_t *rx_buffer; + int32_t rx_size; + int32_t slot; + uint32_t handle; + uint8_t interface_index; +}; + +typedef struct wiiu_attach wiiu_attach_event; + +struct wiiu_attach { + wiiu_attach_event *next; + uint32_t type; + uint32_t handle; + uint16_t vendor_id; + uint16_t product_id; + uint8_t interface_index; + uint8_t is_keyboard; + uint8_t is_mouse; + uint16_t max_packet_size_rx; + uint16_t max_packet_size_tx; +}; + +typedef struct _wiiu_event_list wiiu_event_list; +typedef struct _wiiu_adapter_list wiiu_adapter_list; + +struct _wiiu_event_list { + OSFastMutex lock; + wiiu_attach_event *list; +}; + +struct _wiiu_adapter_list { + OSFastMutex lock; + wiiu_adapter_t *list; +}; + extern wiiu_pad_functions_t pad_functions; extern input_device_driver_t wiiu_joypad; extern input_device_driver_t wpad_driver; extern input_device_driver_t kpad_driver; extern input_device_driver_t hidpad_driver; +extern hid_driver_t wiiu_hid; #endif // __PAD_DRIVER__H diff --git a/wiiu/input/hidpad_driver.c b/wiiu/input/hidpad_driver.c index e8ed2452ad..a36ab50b70 100644 --- a/wiiu/input/hidpad_driver.c +++ b/wiiu/input/hidpad_driver.c @@ -27,15 +27,51 @@ static const char *hidpad_name(unsigned pad); static bool ready = false; -// if the GameCube adapter is attached, this will be the offset -// of the first pad. -static unsigned gca_pad = 0; -static joypad_connection_t *hid_pads; +static wiiu_hid_t *hid_data; +static hid_driver_t *hid_driver; + +static unsigned to_slot(unsigned pad) { + return pad - (WIIU_WIIMOTE_CHANNELS+1); +} + +const void *get_hid_data(void) { + return hid_data; +} + +static hid_driver_t *init_hid_driver(void) +{ + unsigned connections_size = MAX_USERS - (WIIU_WIIMOTE_CHANNELS+1); + hid_data = (wiiu_hid_t *)wiiu_hid.init(); + joypad_connection_t *connections = pad_connection_init(connections_size); + + if(!hid_data || !connections) + goto error; + + hid_data->connections = connections; + hid_data->connections_size = connections_size; + return &wiiu_hid; + + error: + if(connections) + free(connections); + if(hid_data) + { + wiiu_hid.free(hid_data); + free(hid_data); + hid_data = NULL; + } + return NULL; +} static bool hidpad_init(void *data) { (void *)data; - hid_pads = pad_connection_init(MAX_USERS-(WIIU_WIIMOTE_CHANNELS+1)); + hid_driver = init_hid_driver(); + if(!hid_driver) + { + RARCH_ERR("Failed to initialize HID driver.\n"); + return false; + } hidpad_poll(); ready = true; @@ -45,43 +81,57 @@ static bool hidpad_init(void *data) static bool hidpad_query_pad(unsigned pad) { - return (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS); + return ready && (pad > WIIU_WIIMOTE_CHANNELS && pad < MAX_USERS); } static void hidpad_destroy(void) { ready = false; - if(hid_pads) { - pad_connection_destroy(hid_pads); - hid_pads = NULL; + + if(hid_driver) + { + hid_driver->free(get_hid_data()); + free(hid_data); + hid_data = NULL; } } static bool hidpad_button(unsigned pad, uint16_t button) { - return false; + if(!hidpad_query_pad(pad)) + return false; + + return hid_driver->button(hid_data, to_slot(pad), button); } static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) { - BIT256_CLEAR_ALL_PTR(state); + if(!hidpad_query_pad(pad)) + BIT256_CLEAR_ALL_PTR(state); + + hid_driver->get_buttons(hid_data, to_slot(pad), state); } static int16_t hidpad_axis(unsigned pad, uint32_t axis) { - return 0; + if(!hidpad_query_pad(pad)); + return 0; + + return hid_driver->axis(hid_data, to_slot(pad), axis); } static void hidpad_poll(void) { + if(ready) + hid_driver->poll(hid_data); } static const char *hidpad_name(unsigned pad) { if(!hidpad_query_pad(pad)) - return "n/a"; + return "N/A"; - return PAD_NAME_HID; + return hid_driver->name(hid_data, to_slot(pad)); } input_device_driver_t hidpad_driver = diff --git a/input/drivers_hid/wiiu_hid.c b/wiiu/input/wiiu_hid.c similarity index 96% rename from input/drivers_hid/wiiu_hid.c rename to wiiu/input/wiiu_hid.c index 5a61f2273e..1c93c3cde9 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/wiiu/input/wiiu_hid.c @@ -14,29 +14,28 @@ * If not, see . */ -#include -#include -#include -#include -#include -#include - #include "wiiu_hid.h" static wiiu_event_list events; static wiiu_adapter_list adapters; -static bool wiiu_hid_joypad_query(void *data, unsigned pad) +static bool wiiu_hid_joypad_query(void *data, unsigned slot) { - return pad < MAX_USERS; + wiiu_hid_t *hid = (wiiu_hid_t *)data; + if(!hid) + return false; + + return slot < hid->connections_size; } -static const char *wiiu_hid_joypad_name(void *data, unsigned pad) +static const char *wiiu_hid_joypad_name(void *data, unsigned slot) { - if (pad >= MAX_USERS) - return NULL; + if(!wiiu_hid_joypad_query(data, slot)) + return NULL; - return NULL; + wiiu_hid_t *hid = (wiiu_hid_t *)data; + + return hid->connections[slot].iface->get_name(data); } static void wiiu_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state) @@ -81,14 +80,11 @@ static void *wiiu_hid_init(void) RARCH_LOG("[hid]: wiiu_hid: init\n"); wiiu_hid_t *hid = new_hid(); HIDClient *client = new_hidclient(); - joypad_connection_t *connections = pad_connection_init(MAX_HID_PADS); - if(!hid || !client || !connections) { + if(!hid || !client) { goto error; } - hid->connections = connections; - wiiu_hid_init_lists(); start_polling_thread(hid); if(!hid->polling_thread) @@ -103,8 +99,6 @@ static void *wiiu_hid_init(void) error: RARCH_LOG("[hid]: initialization failed. cleaning up.\n"); - if(connections) - free(connections); stop_polling_thread(hid); delete_hid(hid); delete_hidclient(client); diff --git a/input/drivers_hid/wiiu_hid.h b/wiiu/input/wiiu_hid.h similarity index 68% rename from input/drivers_hid/wiiu_hid.h rename to wiiu/input/wiiu_hid.h index 2609ff73b7..68d66e156e 100644 --- a/input/drivers_hid/wiiu_hid.h +++ b/wiiu/input/wiiu_hid.h @@ -16,70 +16,16 @@ #ifndef __WIIU_HID__H #define __WIIU_HID__H -#include "../connect/joypad_connection.h" -#include "../input_defines.h" -#include "../input_driver.h" -#include "../../verbosity.h" + +#include #define DEVICE_UNUSED 0 #define DEVICE_USED 1 -#define MAX_HID_PADS 5 - #define ADAPTER_STATE_NEW 0 #define ADAPTER_STATE_READING 1 #define ADAPTER_STATE_DONE 2 -typedef struct wiiu_hid -{ - HIDClient *client; - joypad_connection_t *connections; - OSThread *polling_thread; - void *polling_thread_stack; - volatile bool polling_thread_quit; -} wiiu_hid_t; - -typedef struct wiiu_adapter wiiu_adapter_t; - -struct wiiu_adapter { - wiiu_adapter_t *next; - wiiu_hid_t *hid; - uint8_t state; - uint8_t *rx_buffer; - uint32_t rx_size; - int32_t slot; - uint32_t handle; - uint8_t interface_index; -}; - -typedef struct wiiu_attach wiiu_attach_event; - -struct wiiu_attach { - wiiu_attach_event *next; - uint32_t type; - uint32_t handle; - uint16_t vendor_id; - uint16_t product_id; - uint8_t interface_index; - uint8_t is_keyboard; - uint8_t is_mouse; - uint16_t max_packet_size_rx; - uint16_t max_packet_size_tx; -}; - -typedef struct _wiiu_event_list wiiu_event_list; -typedef struct _wiiu_adapter_list wiiu_adapter_list; - -struct _wiiu_event_list { - OSFastMutex lock; - wiiu_attach_event *list; -}; - -struct _wiiu_adapter_list { - OSFastMutex lock; - wiiu_adapter_t *list; -}; - static void *alloc_zeroed(size_t alignment, size_t size); static OSThread *new_thread(void); static wiiu_hid_t *new_hid(void); From ec45df79f46578bb1b1b2554df538ed074014fca Mon Sep 17 00:00:00 2001 From: gblues Date: Thu, 28 Dec 2017 23:08:08 -0800 Subject: [PATCH 26/26] Dummy out calls into HID driver == DETAILS Got system memory error. Probably because the calls aren't properly implemented. So dummy them out for now. --- wiiu/input/hidpad_driver.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/wiiu/input/hidpad_driver.c b/wiiu/input/hidpad_driver.c index a36ab50b70..393eb5b10f 100644 --- a/wiiu/input/hidpad_driver.c +++ b/wiiu/input/hidpad_driver.c @@ -101,7 +101,8 @@ static bool hidpad_button(unsigned pad, uint16_t button) if(!hidpad_query_pad(pad)) return false; - return hid_driver->button(hid_data, to_slot(pad), button); +// return hid_driver->button(hid_data, to_slot(pad), button); + return false; } static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) @@ -109,7 +110,8 @@ static void hidpad_get_buttons(unsigned pad, retro_bits_t *state) if(!hidpad_query_pad(pad)) BIT256_CLEAR_ALL_PTR(state); - hid_driver->get_buttons(hid_data, to_slot(pad), state); +// hid_driver->get_buttons(hid_data, to_slot(pad), state); + BIT256_CLEAR_ALL_PTR(state); } static int16_t hidpad_axis(unsigned pad, uint32_t axis) @@ -117,13 +119,14 @@ static int16_t hidpad_axis(unsigned pad, uint32_t axis) if(!hidpad_query_pad(pad)); return 0; - return hid_driver->axis(hid_data, to_slot(pad), axis); +// return hid_driver->axis(hid_data, to_slot(pad), axis); + return 0; } static void hidpad_poll(void) { - if(ready) - hid_driver->poll(hid_data); +// if(ready) +// hid_driver->poll(hid_data); } static const char *hidpad_name(unsigned pad) @@ -131,7 +134,8 @@ static const char *hidpad_name(unsigned pad) if(!hidpad_query_pad(pad)) return "N/A"; - return hid_driver->name(hid_data, to_slot(pad)); + return PAD_NAME_HID; + //return hid_driver->name(hid_data, to_slot(pad)); } input_device_driver_t hidpad_driver =