mirror of
https://github.com/Maschell/hid_to_vpad.git
synced 2024-11-27 16:54:14 +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.cbp
|
||||
hidtovpad.wps
|
||||
cmake-build-debug/
|
||||
.idea/
|
||||
CMakeLists.txt
|
||||
|
@ -19,15 +19,72 @@
|
||||
#include <wups/config.h>
|
||||
#include <wups/config/WUPSConfigItemBoolean.h>
|
||||
#include <controller_patcher/ControllerPatcher.hpp>
|
||||
#include <utils/logger.h>
|
||||
#include "utils/logger.h"
|
||||
#include "utils/StringTools.h"
|
||||
#include "WUPSConfigItemPadMapping.h"
|
||||
|
||||
void rumbleChanged(WUPSConfigItemBoolean * item, bool newValue) {
|
||||
DEBUG_FUNCTION_LINE("rumbleChanged %d ",newValue);
|
||||
ControllerPatcher::setRumbleActivated(newValue);
|
||||
int32_t runNetworkClient = true;
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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 networkClient(WUPSConfigItemBoolean * item, bool newValue) {
|
||||
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);
|
||||
ControllerPatcher::setNetworkControllerActivated(newValue);
|
||||
if(newValue) {
|
||||
@ -35,22 +92,61 @@ void networkClient(WUPSConfigItemBoolean * item, bool newValue) {
|
||||
} else {
|
||||
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() {
|
||||
WUPSConfig* config = new WUPSConfig("HID to VPAD");
|
||||
WUPSConfigCategory* catOther = config->addCategory("Other");
|
||||
WUPSConfigCategory* catMapping = config->addCategory("Controller Mapping");
|
||||
WUPS_OpenStorage();
|
||||
|
||||
// item Type config id displayed name default value onChangeCallback.
|
||||
catOther->addItem(new WUPSConfigItemBoolean("rumble", "Enable rumble", ControllerPatcher::isRumbleActivated(), rumbleChanged));
|
||||
catOther->addItem(new WUPSConfigItemBoolean("networkclient", "Enable network client", true, networkClient));
|
||||
WUPSConfigHandle config;
|
||||
if (WUPSConfig_Create(&config, "HID to VPAD") < 0) {
|
||||
return 0;
|
||||
}
|
||||
WUPSConfigCategoryHandle catOther;
|
||||
if (WUPSConfig_AddCategoryByName(config, "Other", &catOther) < 0) {
|
||||
WUPSConfig_Destroy(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
catMapping->addItem(new WUPSConfigItemPadMapping("gamepadmapping", "Gamepad", UController_Type_Gamepad));
|
||||
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("propad3mapping", "Pro Controller 3", UController_Type_Pro3));
|
||||
catMapping->addItem(new WUPSConfigItemPadMapping("propad4mapping", "Pro Controller 4", UController_Type_Pro4));
|
||||
// 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("propad1mapping", "Pro Controller 1", UController_Type_Pro1));
|
||||
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("propad4mapping", "Pro Controller 4", UController_Type_Pro4));
|
||||
*/
|
||||
|
||||
return config;
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
#include <wups.h>
|
||||
|
||||
#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) {
|
||||
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!
|
||||
}
|
||||
|
||||
if(error != NULL) {
|
||||
if(error != nullptr) {
|
||||
*error = VPAD_READ_SUCCESS;
|
||||
}
|
||||
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_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||
if(result != NULL) {
|
||||
if(result != nullptr) {
|
||||
*result = WPAD_EXT_PRO_CONTROLLER;
|
||||
}
|
||||
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_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||
if(callback != NULL) {
|
||||
if(callback != nullptr) {
|
||||
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_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||
if(callback != NULL) {
|
||||
if(callback != nullptr) {
|
||||
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_2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
|
||||
(chan == WPAD_CHAN_3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))) {
|
||||
if(callback != NULL) {
|
||||
if(callback != nullptr) {
|
||||
callback(chan,0);
|
||||
}
|
||||
}
|
||||
|
@ -25,46 +25,53 @@
|
||||
#include <padscore/wpad.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)
|
||||
typedef int32_t (*VPADReadFunction) (VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error);
|
||||
extern VPADReadFunction real_VPADRead;
|
||||
|
||||
WUPSConfigItemPadMapping::WUPSConfigItemPadMapping(std::string configID, std::string displayName, UController_Type controller) : WUPSConfigItem(configID,displayName) {
|
||||
this->controllerType = controller;
|
||||
bool WUPSConfigItemPadMapping_callCallback(void *context) {
|
||||
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() {
|
||||
int32_t found = ControllerPatcher::getActiveMappingSlot(controllerType);
|
||||
bool updatePadInfo(ConfigItemPadMapping *item) {
|
||||
int32_t found = ControllerPatcher::getActiveMappingSlot(item->controllerType);
|
||||
if(found != -1) {
|
||||
ControllerMappingPADInfo * info = ControllerPatcher::getControllerMappingInfo(controllerType,found);
|
||||
if(info != NULL) {
|
||||
memcpy(&mappedPadInfo,info,sizeof(mappedPadInfo));
|
||||
ControllerMappingPADInfo * info = ControllerPatcher::getControllerMappingInfo(item->controllerType,found);
|
||||
if(info != nullptr) {
|
||||
memcpy(&item->mappedPadInfo,info,sizeof(item->mappedPadInfo));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
this->restoreDefault();
|
||||
restoreDefault(item);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string WUPSConfigItemPadMapping::getCurrentValueDisplay() {
|
||||
if(!updatePadInfo()) {
|
||||
return "No Device";
|
||||
int32_t WUPSConfigItemPadMapping_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
auto *item = (ConfigItemPadMapping *) context;
|
||||
if(!updatePadInfo(item)) {
|
||||
snprintf(out_buf, out_size, "No Device");
|
||||
return 0;
|
||||
}
|
||||
std::string name = "";
|
||||
std::string name;
|
||||
std::string isConnectedString = "attached";
|
||||
|
||||
if(!ControllerPatcher::isControllerConnectedAndActive(controllerType)) {
|
||||
if(!ControllerPatcher::isControllerConnectedAndActive(item->controllerType)) {
|
||||
isConnectedString = "detached";
|
||||
}
|
||||
|
||||
ControllerMappingPADInfo * info = &mappedPadInfo;
|
||||
ControllerMappingPADInfo * info = &item->mappedPadInfo;
|
||||
|
||||
if(info->type == CM_Type_Controller) {
|
||||
std::string titleString = ControllerPatcher::getIdentifierByVIDPID(info->vidpid.vid,info->vidpid.pid);
|
||||
@ -82,20 +89,14 @@ std::string WUPSConfigItemPadMapping::getCurrentValueDisplay() {
|
||||
name = "Mouse / Keyboard";
|
||||
}
|
||||
|
||||
return name.c_str();
|
||||
strncpy(out_buf, name.c_str(), out_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string WUPSConfigItemPadMapping::getCurrentValueSelectedDisplay() {
|
||||
return getCurrentValueDisplay();
|
||||
}
|
||||
|
||||
void WUPSConfigItemPadMapping::onSelected(bool isSelected) {
|
||||
|
||||
}
|
||||
|
||||
void WUPSConfigItemPadMapping::checkForInput() {
|
||||
void checkForInput(ConfigItemPadMapping *item) {
|
||||
int32_t inputsize = gHIDMaxDevices;
|
||||
InputData * hiddata = (InputData * ) malloc(sizeof(InputData)*inputsize);
|
||||
auto * hiddata = (InputData * ) malloc(sizeof(InputData)*inputsize);
|
||||
memset(hiddata,0,sizeof(InputData)*inputsize);
|
||||
|
||||
ControllerMappingPADInfo pad_result;
|
||||
@ -139,76 +140,66 @@ void WUPSConfigItemPadMapping::checkForInput() {
|
||||
}
|
||||
}
|
||||
if(gotPress) {
|
||||
// TODO: Save the choice and use a callback??!??!
|
||||
ControllerPatcher::addControllerMapping(this->controllerType,pad_result);
|
||||
updatePadInfo();
|
||||
ControllerPatcher::addControllerMapping(item->controllerType,pad_result);
|
||||
updatePadInfo(item);
|
||||
WUPSConfigItemPadMapping_callCallback(item);
|
||||
}
|
||||
|
||||
free(hiddata);
|
||||
}
|
||||
|
||||
void WUPSConfigItemPadMapping::onButtonPressed(WUPSConfigButtons buttons) {
|
||||
void WUPSConfigItemPadMapping_onButtonPressed(void *context, WUPSConfigButtons buttons) {
|
||||
auto *item = (ConfigItemPadMapping *) context;
|
||||
if(buttons & WUPS_CONFIG_BUTTON_A) {
|
||||
// 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.
|
||||
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();
|
||||
checkForInput(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool WUPSConfigItemPadMapping::isMovementAllowed() {
|
||||
bool WUPSConfigItemPadMapping_isMovementAllowed(void *context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string WUPSConfigItemPadMapping::persistValue() {
|
||||
updatePadInfo();
|
||||
if(mappedPadInfo.type == CM_Type_Controller){
|
||||
return StringTools::strfmt("%d,%d,%d,%d",mappedPadInfo.vidpid.vid,mappedPadInfo.vidpid.pid,mappedPadInfo.pad,mappedPadInfo.type);
|
||||
}
|
||||
return "0";
|
||||
void WUPSConfigItemPadMapping_onDelete(void *context) {
|
||||
auto *item = (ConfigItemPadMapping *) context;
|
||||
|
||||
free(item);
|
||||
}
|
||||
|
||||
void WUPSConfigItemPadMapping::loadValue(std::string persistedValue) {
|
||||
if(persistedValue.compare("0") == 0) {
|
||||
// No device mapped.
|
||||
return;
|
||||
extern "C" bool WUPSConfigItemPadMapping_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, UController_Type controllerType, ConfigItemPadMappingChangedCallback callback) {
|
||||
if (cat == 0 || displayName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> result = StringTools::stringSplit(persistedValue, ",");
|
||||
if(result.size() != 4) {
|
||||
return;
|
||||
auto *item = (ConfigItemPadMapping *) malloc(sizeof(ConfigItemPadMapping));
|
||||
if (item == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
updatePadInfo();
|
||||
strncpy(item->configId, configID, sizeof(item->configId));
|
||||
item->controllerType = controllerType;
|
||||
item->callback = (void *) callback;
|
||||
memset(&item->mappedPadInfo,0, sizeof(item->mappedPadInfo));
|
||||
|
||||
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());
|
||||
WUPSConfigCallbacks_t callbacks = {
|
||||
.getCurrentValueDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay,
|
||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemPadMapping_getCurrentValueDisplay,
|
||||
.onSelected = nullptr,
|
||||
.restoreDefault = &restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemPadMapping_isMovementAllowed,
|
||||
.callCallback = nullptr,
|
||||
.onButtonPressed = &WUPSConfigItemPadMapping_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemPadMapping_onDelete
|
||||
};
|
||||
|
||||
ControllerPatcher::resetControllerMapping(this->controllerType);
|
||||
// TODO: Save the choice and use a callback??!??!
|
||||
ControllerPatcher::addControllerMapping(this->controllerType,this->mappedPadInfo);
|
||||
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
|
||||
free(item);
|
||||
return false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void WUPSConfigItemPadMapping::restoreDefault() {
|
||||
memset(&mappedPadInfo,0,sizeof(mappedPadInfo));
|
||||
}
|
||||
|
||||
bool WUPSConfigItemPadMapping::callCallback() {
|
||||
// Currently we don't use a callback.
|
||||
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
|
||||
* 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/>.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _WUPS_CONFIG_ITEM_PAD_MAPPING_H_
|
||||
#define _WUPS_CONFIG_ITEM_PAD_MAPPING_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <wups/config/WUPSConfigItem.h>
|
||||
#include <wups.h>
|
||||
#include <controller_patcher/ControllerPatcher.hpp>
|
||||
|
||||
class WUPSConfigItemPadMapping;
|
||||
|
||||
typedef void (*PadMappingChangedCallback)(WUPSConfigItemPadMapping *, bool);
|
||||
|
||||
class WUPSConfigItemPadMapping : public WUPSConfigItem {
|
||||
public:
|
||||
WUPSConfigItemPadMapping(std::string configID, std::string displayName, UController_Type controller);
|
||||
|
||||
void checkForInput();
|
||||
|
||||
virtual ~WUPSConfigItemPadMapping();
|
||||
|
||||
void resetMappingAndDetachController();
|
||||
|
||||
bool updatePadInfo();
|
||||
|
||||
virtual std::string getCurrentValueDisplay();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ConfigItemPadMapping {
|
||||
WUPSConfigItemHandle handle;
|
||||
char configId[32];
|
||||
UController_Type controllerType;
|
||||
ControllerMappingPADInfo mappedPadInfo;
|
||||
void* callback;
|
||||
} ConfigItemPadMapping;
|
||||
|
||||
typedef void (*ConfigItemPadMappingChangedCallback)(ConfigItemPadMapping *);
|
||||
|
||||
bool WUPSConfigItemPadMapping_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, UController_Type controllerType, ConfigItemPadMappingChangedCallback callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -17,45 +17,55 @@
|
||||
|
||||
#include <wups.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <controller_patcher/ControllerPatcher.hpp>
|
||||
#include <utils/logger.h>
|
||||
|
||||
#include <nsysnet/socket.h>
|
||||
#include "WUPSConfigItemPadMapping.h"
|
||||
|
||||
WUPS_PLUGIN_ID("hid_to_vpad");
|
||||
WUPS_PLUGIN_NAME("HID to VPAD lite");
|
||||
WUPS_PLUGIN_DESCRIPTION("Enables HID devices as controllers on your Wii U");
|
||||
WUPS_PLUGIN_VERSION("v1.0");
|
||||
WUPS_PLUGIN_AUTHOR("Maschell");
|
||||
WUPS_PLUGIN_LICENSE("GPL");
|
||||
|
||||
// We want access to the SDCard!
|
||||
WUPS_USE_WUT_CRT()
|
||||
WUPS_USE_WUT_DEVOPTAB()
|
||||
WUPS_USE_STORAGE()
|
||||
|
||||
#define SD_PATH "sd:"
|
||||
#define WIIU_PATH "/wiiu"
|
||||
#define DEFAULT_HID_TO_VPAD_PATH SD_PATH WIIU_PATH "/apps/hidtovpad"
|
||||
|
||||
ON_APPLICATION_START(args) {
|
||||
socket_lib_init();
|
||||
log_init();
|
||||
extern int32_t runNetworkClient;
|
||||
|
||||
|
||||
void ConfigLoad();
|
||||
ON_APPLICATION_START() {
|
||||
WHBLogUdpInit();
|
||||
|
||||
DEBUG_FUNCTION_LINE("Initializing the controller data");
|
||||
ControllerPatcher::Init(CONTROLLER_PATCHER_PATH);
|
||||
ControllerPatcher::enableControllerMapping();
|
||||
DEBUG_FUNCTION_LINE("Starting HID to VPAD network server");
|
||||
ControllerPatcher::startNetworkServer();
|
||||
|
||||
ConfigLoad();
|
||||
|
||||
if (runNetworkClient){
|
||||
DEBUG_FUNCTION_LINE("Starting HID to VPAD network server");
|
||||
ControllerPatcher::startNetworkServer();
|
||||
}
|
||||
ControllerPatcher::disableWiiUEnergySetting();
|
||||
}
|
||||
|
||||
INITIALIZE_PLUGIN(){
|
||||
WHBLogUdpInit();
|
||||
}
|
||||
|
||||
DEINITIALIZE_PLUGIN() {
|
||||
//CursorDrawer::destroyInstance();
|
||||
ControllerPatcher::DeInit();
|
||||
ControllerPatcher::stopNetworkServer();
|
||||
}
|
||||
|
||||
ON_APPLICATION_END() {
|
||||
ON_APPLICATION_REQUESTS_EXIT() {
|
||||
//CursorDrawer::destroyInstance();
|
||||
DEBUG_FUNCTION_LINE("ON_APPLICATION_ENDING");
|
||||
ControllerPatcher::destroyConfigHelper();
|
||||
|
@ -11,12 +11,6 @@ extern "C" {
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#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 { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0);
|
||||
@ -25,16 +19,6 @@ extern "C" {
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} 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
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user