2017-03-30 17:53:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file ControllerPatcher.hpp
|
|
|
|
* @author Maschell
|
|
|
|
* @date 30 Mar 2017
|
|
|
|
* \brief This files contain all public accessible functions of the controller patcher engine
|
|
|
|
*
|
|
|
|
* @see https://github.com/Maschell/controller_patcher
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CONTROLLER_PATCHER_H_
|
|
|
|
#define _CONTROLLER_PATCHER_H_
|
|
|
|
|
|
|
|
#include <gctypes.h>
|
|
|
|
|
|
|
|
#include "./patcher/ControllerPatcherHID.hpp"
|
|
|
|
|
|
|
|
#include "./patcher/ControllerPatcherDefs.h"
|
|
|
|
#include "./utils/PadConst.hpp"
|
|
|
|
|
|
|
|
#include "./ConfigReader.hpp"
|
|
|
|
#include "./config/ConfigValues.hpp"
|
|
|
|
#include "network/TCPServer.hpp"
|
|
|
|
#include "network/UDPServer.hpp"
|
2017-04-13 15:30:40 +02:00
|
|
|
#include "network/UDPClient.hpp"
|
2017-03-30 17:53:36 +02:00
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
#include "dynamic_libs/sys_functions.h"
|
2017-03-30 17:53:36 +02:00
|
|
|
#include "dynamic_libs/syshid_functions.h"
|
|
|
|
#include "dynamic_libs/socket_functions.h"
|
|
|
|
#include "dynamic_libs/padscore_functions.h"
|
|
|
|
#include "dynamic_libs/vpad_functions.h"
|
|
|
|
#include "dynamic_libs/padscore_functions.h"
|
|
|
|
|
|
|
|
#include "./utils/CPRetainVars.hpp"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include "./utils/CPStringTools.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#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.
|
|
|
|
**/
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR setProControllerDataFromHID(void * data,s32 chan,s32 mode = PRO_CONTROLLER_MODE_KPADDATA);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the data in a given VPADData 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(VPADData * 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.
|
|
|
|
**/
|
2017-04-10 11:00:55 +02:00
|
|
|
static s32 getActiveMappingSlot(UController_Type type);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
@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.
|
|
|
|
**/
|
2017-04-10 11:00:55 +02:00
|
|
|
static ControllerMappingPADInfo * getControllerMappingInfo(UController_Type type,s32 mapping_slot);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
**/
|
2017-04-10 11:00:55 +02:00
|
|
|
static bool isControllerConnectedAndActive(UController_Type type,s32 mapping_slot = 0);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
**/
|
2017-04-10 11:00:55 +02:00
|
|
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Remaps the buttons in the given \p VPADData 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.
|
|
|
|
**/
|
2017-04-10 11:00:55 +02:00
|
|
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR buttonRemapping(VPADData * buffer, s32 buffer_count);
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Prints the current pressed down buttons of the given \p VPADData 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(VPADData * buffer);
|
|
|
|
|
|
|
|
static std::string getIdentifierByVIDPID(u16 vid,u16 pid);
|
|
|
|
|
|
|
|
static void destroyConfigHelper();
|
2017-04-23 15:19:21 +02:00
|
|
|
|
|
|
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR doSamplingForDeviceSlot(u16 device_slot);
|
2017-05-07 14:29:19 +02:00
|
|
|
|
|
|
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR setRumbleActivated(bool value);
|
|
|
|
|
|
|
|
static bool isRumbleActivated();
|
2017-03-30 17:53:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _CONTROLLER_PATCHER_H_ */
|