mirror of
https://github.com/Maschell/hid_to_vpad.git
synced 2024-11-30 18:04:15 +01:00
WIP
This commit is contained in:
parent
462c0d3e70
commit
a1a99861d3
3
.gitignore
vendored
3
.gitignore
vendored
@ -56,3 +56,6 @@ hidtopad.cbp
|
|||||||
hidtopad.layout
|
hidtopad.layout
|
||||||
hidtopad.cbp
|
hidtopad.cbp
|
||||||
hidtovpad.wps
|
hidtovpad.wps
|
||||||
|
cmake-build-debug/
|
||||||
|
.idea/
|
||||||
|
CMakeLists.txt
|
||||||
|
@ -19,15 +19,72 @@
|
|||||||
#include <wups/config.h>
|
#include <wups/config.h>
|
||||||
#include <wups/config/WUPSConfigItemBoolean.h>
|
#include <wups/config/WUPSConfigItemBoolean.h>
|
||||||
#include <controller_patcher/ControllerPatcher.hpp>
|
#include <controller_patcher/ControllerPatcher.hpp>
|
||||||
#include <utils/logger.h>
|
#include "utils/logger.h"
|
||||||
|
#include "utils/StringTools.h"
|
||||||
#include "WUPSConfigItemPadMapping.h"
|
#include "WUPSConfigItemPadMapping.h"
|
||||||
|
|
||||||
void rumbleChanged(WUPSConfigItemBoolean * item, bool newValue) {
|
int32_t runNetworkClient = true;
|
||||||
DEBUG_FUNCTION_LINE("rumbleChanged %d ",newValue);
|
|
||||||
ControllerPatcher::setRumbleActivated(newValue);
|
|
||||||
|
void loadMapping(std::string& persistedValue, UController_Type type);
|
||||||
|
|
||||||
|
void ConfigLoad() {
|
||||||
|
WUPS_OpenStorage();
|
||||||
|
|
||||||
|
int32_t rumble = 0;
|
||||||
|
|
||||||
|
if(WUPS_GetInt(nullptr, "rumble", &rumble) == WUPS_STORAGE_ERROR_SUCCESS){
|
||||||
|
ControllerPatcher::setRumbleActivated(rumble);
|
||||||
|
}else{
|
||||||
|
WUPS_StoreInt(nullptr, "rumble", ControllerPatcher::isRumbleActivated());
|
||||||
}
|
}
|
||||||
|
|
||||||
void networkClient(WUPSConfigItemBoolean * item, bool newValue) {
|
if(WUPS_GetInt(nullptr, "networkclient", &runNetworkClient) != WUPS_STORAGE_ERROR_SUCCESS){
|
||||||
|
WUPS_StoreInt(nullptr, "networkclient", runNetworkClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[512];
|
||||||
|
if(WUPS_GetString(nullptr, "gamepadmapping", buffer, sizeof(buffer)) == WUPS_STORAGE_ERROR_SUCCESS){
|
||||||
|
DEBUG_FUNCTION_LINE("%s", buffer);
|
||||||
|
std::string test = buffer;
|
||||||
|
loadMapping(test, UController_Type_Gamepad);
|
||||||
|
}
|
||||||
|
|
||||||
|
WUPS_CloseStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadMapping(std::string &persistedValue, UController_Type controllerType){
|
||||||
|
if(persistedValue.empty()) {
|
||||||
|
// No device mapped.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<std::string> result = StringTools::stringSplit(persistedValue, ",");
|
||||||
|
if(result.size() != 4) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ControllerMappingPADInfo mappedPadInfo;
|
||||||
|
mappedPadInfo.vidpid.vid = atoi(result.at(0).c_str());
|
||||||
|
mappedPadInfo.vidpid.pid = atoi(result.at(1).c_str());
|
||||||
|
mappedPadInfo.pad = atoi(result.at(2).c_str());
|
||||||
|
mappedPadInfo.type = CM_Type_Controller; //atoi(result.at(3).c_str());
|
||||||
|
|
||||||
|
DEBUG_FUNCTION_LINE("%d",mappedPadInfo.vidpid.vid);
|
||||||
|
DEBUG_FUNCTION_LINE("%d",mappedPadInfo.vidpid.pid);
|
||||||
|
DEBUG_FUNCTION_LINE("%d",mappedPadInfo.pad);
|
||||||
|
DEBUG_FUNCTION_LINE("%d",mappedPadInfo.type);
|
||||||
|
|
||||||
|
ControllerPatcher::resetControllerMapping(controllerType);
|
||||||
|
ControllerPatcher::addControllerMapping(controllerType,mappedPadInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rumbleChanged(ConfigItemBoolean * item, bool newValue) {
|
||||||
|
DEBUG_FUNCTION_LINE("rumbleChanged %d ",newValue);
|
||||||
|
ControllerPatcher::setRumbleActivated(newValue);
|
||||||
|
WUPS_StoreInt(nullptr, "rumble", newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void networkClientChanged(ConfigItemBoolean * item, bool newValue) {
|
||||||
DEBUG_FUNCTION_LINE("Trigger network %d",newValue);
|
DEBUG_FUNCTION_LINE("Trigger network %d",newValue);
|
||||||
ControllerPatcher::setNetworkControllerActivated(newValue);
|
ControllerPatcher::setNetworkControllerActivated(newValue);
|
||||||
if(newValue) {
|
if(newValue) {
|
||||||
@ -35,22 +92,61 @@ void networkClient(WUPSConfigItemBoolean * item, bool newValue) {
|
|||||||
} else {
|
} else {
|
||||||
ControllerPatcher::stopNetworkServer();
|
ControllerPatcher::stopNetworkServer();
|
||||||
}
|
}
|
||||||
|
WUPS_StoreInt(nullptr, "networkclient", newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PadMappingUpdated(ConfigItemPadMapping * item) {
|
||||||
|
if(item->mappedPadInfo.active && item->mappedPadInfo.type == CM_Type_Controller){
|
||||||
|
auto res = StringTools::strfmt("%d,%d,%d,%d",item->mappedPadInfo.vidpid.vid,item->mappedPadInfo.vidpid.pid,item->mappedPadInfo.pad,item->mappedPadInfo.type);
|
||||||
|
DEBUG_FUNCTION_LINE("Persist config for %s: %s", item->configId, res.c_str());
|
||||||
|
WUPS_StoreString(nullptr, item->configId, res.c_str());
|
||||||
|
} else {
|
||||||
|
WUPS_StoreString(nullptr, item->configId, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WUPS_CONFIG_CLOSED(){
|
||||||
|
WUPS_CloseStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPS_GET_CONFIG() {
|
WUPS_GET_CONFIG() {
|
||||||
WUPSConfig* config = new WUPSConfig("HID to VPAD");
|
WUPS_OpenStorage();
|
||||||
WUPSConfigCategory* catOther = config->addCategory("Other");
|
|
||||||
WUPSConfigCategory* catMapping = config->addCategory("Controller Mapping");
|
|
||||||
|
|
||||||
// item Type config id displayed name default value onChangeCallback.
|
WUPSConfigHandle config;
|
||||||
catOther->addItem(new WUPSConfigItemBoolean("rumble", "Enable rumble", ControllerPatcher::isRumbleActivated(), rumbleChanged));
|
if (WUPSConfig_Create(&config, "HID to VPAD") < 0) {
|
||||||
catOther->addItem(new WUPSConfigItemBoolean("networkclient", "Enable network client", true, networkClient));
|
return 0;
|
||||||
|
}
|
||||||
|
WUPSConfigCategoryHandle catOther;
|
||||||
|
if (WUPSConfig_AddCategoryByName(config, "Other", &catOther) < 0) {
|
||||||
|
WUPSConfig_Destroy(config);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WUPSConfigCategory* catMapping = config->addCategory("Controller Mapping");
|
||||||
|
|
||||||
|
if (!WUPSConfigItemBoolean_AddToCategoryEx(catOther, "rumble", "Rumble", ControllerPatcher::isRumbleActivated(), &rumbleChanged, "On", "Off")) {
|
||||||
|
WUPSConfig_Destroy(config);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WUPSConfigItemBoolean_AddToCategoryEx(catOther, "networkclient", "Network Client", runNetworkClient, &networkClientChanged, "On", "Off")) {
|
||||||
|
WUPSConfig_Destroy(config);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WUPSConfigItemPadMapping_AddToCategory(catOther, "gamepadmapping", "Gamepad", UController_Type_Gamepad, &PadMappingUpdated)) {
|
||||||
|
WUPSConfig_Destroy(config);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
catMapping->addItem(new WUPSConfigItemPadMapping("gamepadmapping", "Gamepad", UController_Type_Gamepad));
|
catMapping->addItem(new WUPSConfigItemPadMapping("gamepadmapping", "Gamepad", UController_Type_Gamepad));
|
||||||
catMapping->addItem(new WUPSConfigItemPadMapping("propad1mapping", "Pro Controller 1", UController_Type_Pro1));
|
catMapping->addItem(new WUPSConfigItemPadMapping("propad1mapping", "Pro Controller 1", UController_Type_Pro1));
|
||||||
catMapping->addItem(new WUPSConfigItemPadMapping("propad2mapping", "Pro Controller 2", UController_Type_Pro2));
|
catMapping->addItem(new WUPSConfigItemPadMapping("propad2mapping", "Pro Controller 2", UController_Type_Pro2));
|
||||||
catMapping->addItem(new WUPSConfigItemPadMapping("propad3mapping", "Pro Controller 3", UController_Type_Pro3));
|
catMapping->addItem(new WUPSConfigItemPadMapping("propad3mapping", "Pro Controller 3", UController_Type_Pro3));
|
||||||
catMapping->addItem(new WUPSConfigItemPadMapping("propad4mapping", "Pro Controller 4", UController_Type_Pro4));
|
catMapping->addItem(new WUPSConfigItemPadMapping("propad4mapping", "Pro Controller 4", UController_Type_Pro4));
|
||||||
|
*/
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
|
||||||
#include <controller_patcher/ControllerPatcher.hpp>
|
#include <controller_patcher/ControllerPatcher.hpp>
|
||||||
#include <vpad/input.h>
|
|
||||||
#include <padscore/wpad.h>
|
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) {
|
DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) {
|
||||||
int32_t result = real_VPADRead(chan, buffer, buffer_size, error);
|
int32_t result = real_VPADRead(chan, buffer, buffer_size, error);
|
||||||
@ -38,7 +36,7 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
|
|||||||
//OSSendAppSwitchRequest(5,0,0); //Open the home menu!
|
//OSSendAppSwitchRequest(5,0,0); //Open the home menu!
|
||||||
}
|
}
|
||||||
|
|
||||||
if(error != NULL) {
|
if(error != nullptr) {
|
||||||
*error = VPAD_READ_SUCCESS;
|
*error = VPAD_READ_SUCCESS;
|
||||||
}
|
}
|
||||||
result = 1; // We want the WiiU to ignore everything else.
|
result = 1; // We want the WiiU to ignore everything else.
|
||||||
@ -58,7 +56,7 @@ DECL_FUNCTION(int32_t, WPADProbe, WPADChan chan, uint32_t * result ) {
|
|||||||
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
||||||
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||||
if(result != NULL) {
|
if(result != nullptr) {
|
||||||
*result = WPAD_EXT_PRO_CONTROLLER;
|
*result = WPAD_EXT_PRO_CONTROLLER;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -76,7 +74,7 @@ DECL_FUNCTION(WPADConnectCallback,WPADSetConnectCallback,WPADChan chan, WPADConn
|
|||||||
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
||||||
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||||
if(callback != NULL) {
|
if(callback != nullptr) {
|
||||||
callback(chan,0);
|
callback(chan,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +90,7 @@ DECL_FUNCTION(WPADExtensionCallback,WPADSetExtensionCallback,WPADChan chan, WPAD
|
|||||||
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
||||||
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||||
if(callback != NULL) {
|
if(callback != nullptr) {
|
||||||
callback(chan,WPAD_EXT_PRO_CONTROLLER);
|
callback(chan,WPAD_EXT_PRO_CONTROLLER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +106,7 @@ DECL_FUNCTION(WPADConnectCallback,KPADSetConnectCallback,WPADChan chan, WPADConn
|
|||||||
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
(chan == WPAD_CHAN_1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
|
||||||
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
(chan == WPAD_CHAN_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||||
if(callback != NULL) {
|
if(callback != nullptr) {
|
||||||
callback(chan,0);
|
callback(chan,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,46 +25,53 @@
|
|||||||
#include <padscore/wpad.h>
|
#include <padscore/wpad.h>
|
||||||
#include <utils/StringTools.h>
|
#include <utils/StringTools.h>
|
||||||
|
|
||||||
|
|
||||||
// At this point the VPADRead function is already patched. But we want to use the original function (note: this could be patched by a different plugin)
|
// At this point the VPADRead function is already patched. But we want to use the original function (note: this could be patched by a different plugin)
|
||||||
typedef int32_t (*VPADReadFunction) (VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error);
|
typedef int32_t (*VPADReadFunction) (VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error);
|
||||||
extern VPADReadFunction real_VPADRead;
|
extern VPADReadFunction real_VPADRead;
|
||||||
|
|
||||||
WUPSConfigItemPadMapping::WUPSConfigItemPadMapping(std::string configID, std::string displayName, UController_Type controller) : WUPSConfigItem(configID,displayName) {
|
bool WUPSConfigItemPadMapping_callCallback(void *context) {
|
||||||
this->controllerType = controller;
|
auto *item = (ConfigItemPadMapping *) context;
|
||||||
|
if (item->callback != nullptr) {
|
||||||
|
((ConfigItemPadMappingChangedCallback) (item->callback))(item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPSConfigItemPadMapping::~WUPSConfigItemPadMapping() {
|
void restoreDefault(void *context) {
|
||||||
|
auto *item = (ConfigItemPadMapping *) context;
|
||||||
|
memset(&item->mappedPadInfo,0,sizeof(item->mappedPadInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WUPSConfigItemPadMapping::updatePadInfo() {
|
bool updatePadInfo(ConfigItemPadMapping *item) {
|
||||||
int32_t found = ControllerPatcher::getActiveMappingSlot(controllerType);
|
int32_t found = ControllerPatcher::getActiveMappingSlot(item->controllerType);
|
||||||
if(found != -1) {
|
if(found != -1) {
|
||||||
ControllerMappingPADInfo * info = ControllerPatcher::getControllerMappingInfo(controllerType,found);
|
ControllerMappingPADInfo * info = ControllerPatcher::getControllerMappingInfo(item->controllerType,found);
|
||||||
if(info != NULL) {
|
if(info != nullptr) {
|
||||||
memcpy(&mappedPadInfo,info,sizeof(mappedPadInfo));
|
memcpy(&item->mappedPadInfo,info,sizeof(item->mappedPadInfo));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->restoreDefault();
|
restoreDefault(item);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WUPSConfigItemPadMapping::getCurrentValueDisplay() {
|
int32_t WUPSConfigItemPadMapping_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||||
if(!updatePadInfo()) {
|
auto *item = (ConfigItemPadMapping *) context;
|
||||||
return "No Device";
|
if(!updatePadInfo(item)) {
|
||||||
|
snprintf(out_buf, out_size, "No Device");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
std::string name = "";
|
std::string name;
|
||||||
std::string isConnectedString = "attached";
|
std::string isConnectedString = "attached";
|
||||||
|
|
||||||
if(!ControllerPatcher::isControllerConnectedAndActive(controllerType)) {
|
if(!ControllerPatcher::isControllerConnectedAndActive(item->controllerType)) {
|
||||||
isConnectedString = "detached";
|
isConnectedString = "detached";
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerMappingPADInfo * info = &mappedPadInfo;
|
ControllerMappingPADInfo * info = &item->mappedPadInfo;
|
||||||
|
|
||||||
if(info->type == CM_Type_Controller) {
|
if(info->type == CM_Type_Controller) {
|
||||||
std::string titleString = ControllerPatcher::getIdentifierByVIDPID(info->vidpid.vid,info->vidpid.pid);
|
std::string titleString = ControllerPatcher::getIdentifierByVIDPID(info->vidpid.vid,info->vidpid.pid);
|
||||||
@ -82,20 +89,14 @@ std::string WUPSConfigItemPadMapping::getCurrentValueDisplay() {
|
|||||||
name = "Mouse / Keyboard";
|
name = "Mouse / Keyboard";
|
||||||
}
|
}
|
||||||
|
|
||||||
return name.c_str();
|
strncpy(out_buf, name.c_str(), out_size);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WUPSConfigItemPadMapping::getCurrentValueSelectedDisplay() {
|
void checkForInput(ConfigItemPadMapping *item) {
|
||||||
return getCurrentValueDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WUPSConfigItemPadMapping::onSelected(bool isSelected) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WUPSConfigItemPadMapping::checkForInput() {
|
|
||||||
int32_t inputsize = gHIDMaxDevices;
|
int32_t inputsize = gHIDMaxDevices;
|
||||||
InputData * hiddata = (InputData * ) malloc(sizeof(InputData)*inputsize);
|
auto * hiddata = (InputData * ) malloc(sizeof(InputData)*inputsize);
|
||||||
memset(hiddata,0,sizeof(InputData)*inputsize);
|
memset(hiddata,0,sizeof(InputData)*inputsize);
|
||||||
|
|
||||||
ControllerMappingPADInfo pad_result;
|
ControllerMappingPADInfo pad_result;
|
||||||
@ -139,76 +140,66 @@ void WUPSConfigItemPadMapping::checkForInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(gotPress) {
|
if(gotPress) {
|
||||||
// TODO: Save the choice and use a callback??!??!
|
ControllerPatcher::addControllerMapping(item->controllerType,pad_result);
|
||||||
ControllerPatcher::addControllerMapping(this->controllerType,pad_result);
|
updatePadInfo(item);
|
||||||
updatePadInfo();
|
WUPSConfigItemPadMapping_callCallback(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(hiddata);
|
free(hiddata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPSConfigItemPadMapping::onButtonPressed(WUPSConfigButtons buttons) {
|
void WUPSConfigItemPadMapping_onButtonPressed(void *context, WUPSConfigButtons buttons) {
|
||||||
|
auto *item = (ConfigItemPadMapping *) context;
|
||||||
if(buttons & WUPS_CONFIG_BUTTON_A) {
|
if(buttons & WUPS_CONFIG_BUTTON_A) {
|
||||||
// Lets remove the old mapping.
|
// Lets remove the old mapping.
|
||||||
ControllerPatcher::resetControllerMapping(this->controllerType);
|
ControllerPatcher::resetControllerMapping(item->controllerType);
|
||||||
|
|
||||||
// And draw the text on the screen the config menu is drawn to.
|
checkForInput(item);
|
||||||
wups_overlay_options_type_t screen = this->lastVisibleOnScreen();
|
|
||||||
|
|
||||||
WUPS_Overlay_OSScreenClear(screen);
|
|
||||||
|
|
||||||
// TODO: Add more information about the target (e.g. is the mapping for the gamepad or pro controller 1/2/3/4)
|
|
||||||
WUPS_Overlay_PrintTextOnScreen(screen, 0,0,"Press a button on the HID controller to map it.");
|
|
||||||
WUPS_Overlay_PrintTextOnScreen(screen, 0,10,"Press HOME or B on the gamepad to abort.");
|
|
||||||
|
|
||||||
WUPS_Overlay_FlipBuffers(screen);
|
|
||||||
|
|
||||||
checkForInput();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WUPSConfigItemPadMapping::isMovementAllowed() {
|
bool WUPSConfigItemPadMapping_isMovementAllowed(void *context) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WUPSConfigItemPadMapping::persistValue() {
|
void WUPSConfigItemPadMapping_onDelete(void *context) {
|
||||||
updatePadInfo();
|
auto *item = (ConfigItemPadMapping *) context;
|
||||||
if(mappedPadInfo.type == CM_Type_Controller){
|
|
||||||
return StringTools::strfmt("%d,%d,%d,%d",mappedPadInfo.vidpid.vid,mappedPadInfo.vidpid.pid,mappedPadInfo.pad,mappedPadInfo.type);
|
free(item);
|
||||||
}
|
|
||||||
return "0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPSConfigItemPadMapping::loadValue(std::string persistedValue) {
|
extern "C" bool WUPSConfigItemPadMapping_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, UController_Type controllerType, ConfigItemPadMappingChangedCallback callback) {
|
||||||
if(persistedValue.compare("0") == 0) {
|
if (cat == 0 || displayName == nullptr) {
|
||||||
// No device mapped.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::vector<std::string> result = StringTools::stringSplit(persistedValue, ",");
|
|
||||||
if(result.size() != 4) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePadInfo();
|
|
||||||
|
|
||||||
this->mappedPadInfo.vidpid.vid = atoi(result.at(0).c_str());
|
|
||||||
this->mappedPadInfo.vidpid.pid = atoi(result.at(1).c_str());
|
|
||||||
this->mappedPadInfo.pad = atoi(result.at(2).c_str());
|
|
||||||
//Currently only persisting mapped controllers is supported.
|
|
||||||
this->mappedPadInfo.type = CM_Type_Controller; //atoi(result.at(3).c_str());
|
|
||||||
|
|
||||||
ControllerPatcher::resetControllerMapping(this->controllerType);
|
|
||||||
// TODO: Save the choice and use a callback??!??!
|
|
||||||
ControllerPatcher::addControllerMapping(this->controllerType,this->mappedPadInfo);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WUPSConfigItemPadMapping::restoreDefault() {
|
|
||||||
memset(&mappedPadInfo,0,sizeof(mappedPadInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WUPSConfigItemPadMapping::callCallback() {
|
|
||||||
// Currently we don't use a callback.
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
auto *item = (ConfigItemPadMapping *) malloc(sizeof(ConfigItemPadMapping));
|
||||||
|
if (item == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(item->configId, configID, sizeof(item->configId));
|
||||||
|
item->controllerType = controllerType;
|
||||||
|
item->callback = (void *) callback;
|
||||||
|
memset(&item->mappedPadInfo,0, sizeof(item->mappedPadInfo));
|
||||||
|
|
||||||
|
WUPSConfigCallbacks_t callbacks = {
|
||||||
|
.getCurrentValueDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay,
|
||||||
|
.getCurrentValueSelectedDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay,
|
||||||
|
.onSelected = nullptr,
|
||||||
|
.restoreDefault = &restoreDefault,
|
||||||
|
.isMovementAllowed = &WUPSConfigItemPadMapping_isMovementAllowed,
|
||||||
|
.callCallback = nullptr,
|
||||||
|
.onButtonPressed = &WUPSConfigItemPadMapping_onButtonPressed,
|
||||||
|
.onDelete = &WUPSConfigItemPadMapping_onDelete
|
||||||
|
};
|
||||||
|
|
||||||
|
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
|
||||||
|
free(item);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WUPSConfigCategory_AddItem(cat, item->handle) < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Copyright (C) 2018 Maschell
|
* Copyright (C) 2021 Maschell
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -15,51 +15,25 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef _WUPS_CONFIG_ITEM_PAD_MAPPING_H_
|
#include <wups.h>
|
||||||
#define _WUPS_CONFIG_ITEM_PAD_MAPPING_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <wups/config/WUPSConfigItem.h>
|
|
||||||
#include <controller_patcher/ControllerPatcher.hpp>
|
#include <controller_patcher/ControllerPatcher.hpp>
|
||||||
|
|
||||||
class WUPSConfigItemPadMapping;
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
typedef void (*PadMappingChangedCallback)(WUPSConfigItemPadMapping *, bool);
|
#endif
|
||||||
|
|
||||||
class WUPSConfigItemPadMapping : public WUPSConfigItem {
|
typedef struct ConfigItemPadMapping {
|
||||||
public:
|
WUPSConfigItemHandle handle;
|
||||||
WUPSConfigItemPadMapping(std::string configID, std::string displayName, UController_Type controller);
|
char configId[32];
|
||||||
|
UController_Type controllerType;
|
||||||
void checkForInput();
|
ControllerMappingPADInfo mappedPadInfo;
|
||||||
|
void* callback;
|
||||||
virtual ~WUPSConfigItemPadMapping();
|
} ConfigItemPadMapping;
|
||||||
|
|
||||||
void resetMappingAndDetachController();
|
typedef void (*ConfigItemPadMappingChangedCallback)(ConfigItemPadMapping *);
|
||||||
|
|
||||||
bool updatePadInfo();
|
bool WUPSConfigItemPadMapping_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, UController_Type controllerType, ConfigItemPadMappingChangedCallback callback);
|
||||||
|
|
||||||
virtual std::string getCurrentValueDisplay();
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
virtual std::string getCurrentValueSelectedDisplay();
|
|
||||||
|
|
||||||
virtual void onSelected(bool isSelected);
|
|
||||||
|
|
||||||
virtual void onButtonPressed(WUPSConfigButtons buttons);
|
|
||||||
|
|
||||||
virtual bool isMovementAllowed();
|
|
||||||
|
|
||||||
virtual std::string persistValue();
|
|
||||||
|
|
||||||
virtual void loadValue(std::string persistedValue);
|
|
||||||
|
|
||||||
virtual void restoreDefault();
|
|
||||||
|
|
||||||
virtual bool callCallback();
|
|
||||||
|
|
||||||
private:
|
|
||||||
UController_Type controllerType = UController_Type_Gamepad;
|
|
||||||
ControllerMappingPADInfo mappedPadInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
30
src/main.cpp
30
src/main.cpp
@ -17,45 +17,55 @@
|
|||||||
|
|
||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
#include <controller_patcher/ControllerPatcher.hpp>
|
#include <controller_patcher/ControllerPatcher.hpp>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
|
|
||||||
#include <nsysnet/socket.h>
|
WUPS_PLUGIN_ID("hid_to_vpad");
|
||||||
#include "WUPSConfigItemPadMapping.h"
|
|
||||||
|
|
||||||
WUPS_PLUGIN_NAME("HID to VPAD lite");
|
WUPS_PLUGIN_NAME("HID to VPAD lite");
|
||||||
WUPS_PLUGIN_DESCRIPTION("Enables HID devices as controllers on your Wii U");
|
WUPS_PLUGIN_DESCRIPTION("Enables HID devices as controllers on your Wii U");
|
||||||
WUPS_PLUGIN_VERSION("v1.0");
|
WUPS_PLUGIN_VERSION("v1.0");
|
||||||
WUPS_PLUGIN_AUTHOR("Maschell");
|
WUPS_PLUGIN_AUTHOR("Maschell");
|
||||||
WUPS_PLUGIN_LICENSE("GPL");
|
WUPS_PLUGIN_LICENSE("GPL");
|
||||||
|
|
||||||
// We want access to the SDCard!
|
WUPS_USE_WUT_DEVOPTAB()
|
||||||
WUPS_USE_WUT_CRT()
|
WUPS_USE_STORAGE()
|
||||||
|
|
||||||
#define SD_PATH "sd:"
|
#define SD_PATH "sd:"
|
||||||
#define WIIU_PATH "/wiiu"
|
#define WIIU_PATH "/wiiu"
|
||||||
#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad"
|
#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad"
|
||||||
|
|
||||||
ON_APPLICATION_START(args) {
|
extern int32_t runNetworkClient;
|
||||||
socket_lib_init();
|
|
||||||
log_init();
|
|
||||||
|
void ConfigLoad();
|
||||||
|
ON_APPLICATION_START() {
|
||||||
|
WHBLogUdpInit();
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("Initializing the controller data");
|
DEBUG_FUNCTION_LINE("Initializing the controller data");
|
||||||
ControllerPatcher::Init(CONTROLLER_PATCHER_PATH);
|
ControllerPatcher::Init(CONTROLLER_PATCHER_PATH);
|
||||||
ControllerPatcher::enableControllerMapping();
|
ControllerPatcher::enableControllerMapping();
|
||||||
|
|
||||||
|
ConfigLoad();
|
||||||
|
|
||||||
|
if (runNetworkClient){
|
||||||
DEBUG_FUNCTION_LINE("Starting HID to VPAD network server");
|
DEBUG_FUNCTION_LINE("Starting HID to VPAD network server");
|
||||||
ControllerPatcher::startNetworkServer();
|
ControllerPatcher::startNetworkServer();
|
||||||
|
}
|
||||||
ControllerPatcher::disableWiiUEnergySetting();
|
ControllerPatcher::disableWiiUEnergySetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INITIALIZE_PLUGIN(){
|
||||||
|
WHBLogUdpInit();
|
||||||
|
}
|
||||||
|
|
||||||
DEINITIALIZE_PLUGIN() {
|
DEINITIALIZE_PLUGIN() {
|
||||||
//CursorDrawer::destroyInstance();
|
//CursorDrawer::destroyInstance();
|
||||||
ControllerPatcher::DeInit();
|
ControllerPatcher::DeInit();
|
||||||
ControllerPatcher::stopNetworkServer();
|
ControllerPatcher::stopNetworkServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ON_APPLICATION_END() {
|
ON_APPLICATION_REQUESTS_EXIT() {
|
||||||
//CursorDrawer::destroyInstance();
|
//CursorDrawer::destroyInstance();
|
||||||
DEBUG_FUNCTION_LINE("ON_APPLICATION_ENDING");
|
DEBUG_FUNCTION_LINE("ON_APPLICATION_ENDING");
|
||||||
ControllerPatcher::destroyConfigHelper();
|
ControllerPatcher::destroyConfigHelper();
|
||||||
|
@ -11,12 +11,6 @@ extern "C" {
|
|||||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||||
|
|
||||||
#ifdef __LOGGING__
|
|
||||||
|
|
||||||
#define log_init() WHBLogUdpInit()
|
|
||||||
#define log_print(str) WHBLogPrint(str)
|
|
||||||
#define log_printf(FMT, ARGS...) WHBLogPrintf(FMT, ## ARGS);
|
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||||
} while (0);
|
} while (0);
|
||||||
@ -25,16 +19,6 @@ extern "C" {
|
|||||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define log_init()
|
|
||||||
#define log_print(str)
|
|
||||||
#define log_printf(FMT, ARGS...)
|
|
||||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)
|
|
||||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user