Saving the order in which the controllers were connected

This commit is contained in:
Maschell 2017-05-20 19:22:16 +02:00
parent bd4a10baa6
commit 0d419a0064
8 changed files with 78 additions and 135 deletions

View File

@ -78,8 +78,8 @@ void ControllerPatcher::InitButtonMapping(){
} }
void ControllerPatcher::ResetConfig(){ void ControllerPatcher::ResetConfig(){
memset(&gControllerMapping,0,sizeof(gControllerMapping)); memset(connectionOrderHelper,0,sizeof(connectionOrderHelper));
disableControllerMapping(); memset(&gControllerMapping,0,sizeof(gControllerMapping)); // Init / Invalid everything
memset(config_controller,CONTROLLER_PATCHER_INVALIDVALUE,sizeof(config_controller)); // 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(config_controller_hidmask,0,sizeof(config_controller_hidmask)); // Init / Invalid everything
memset(gNetworkController,0,sizeof(gNetworkController)); // Init / Invalid everything memset(gNetworkController,0,sizeof(gNetworkController)); // Init / Invalid everything
@ -564,6 +564,7 @@ void ControllerPatcher::DeInit(){
memset(config_controller,0,sizeof(config_controller)); memset(config_controller,0,sizeof(config_controller));
memset(config_controller_hidmask,0,sizeof(config_controller_hidmask)); memset(config_controller_hidmask,0,sizeof(config_controller_hidmask));
memset(gNetworkController,0,sizeof(gNetworkController)); memset(gNetworkController,0,sizeof(gNetworkController));
memset(connectionOrderHelper,0,sizeof(connectionOrderHelper));
memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback)); memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback));
memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback)); memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback));
@ -762,44 +763,40 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type
return CONTROLLER_PATCHER_ERROR_NONE; return CONTROLLER_PATCHER_ERROR_NONE;
} }
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevicesEx(InputDataEx * output,s32 array_size){ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){
s32 hid = gHIDCurrentDevice;
HID_Data * data_cur; HID_Data * data_cur;
VPADStatus pad_buffer; VPADStatus pad_buffer;
VPADStatus * buffer = &pad_buffer; VPADStatus * buffer = &pad_buffer;
s32 result = CONTROLLER_PATCHER_ERROR_NONE; s32 result = CONTROLLER_PATCHER_ERROR_NONE;
for(s32 i = 0;i< gHIDMaxDevices;i++){ std::map<my_cb_user *,s32> pad_count;
if(result > array_size){ //printf("fill in data\n");
break; for(s32 i = 0;i < gHIDMaxDevices;i++){
} u8 * status = &output[result].status;
if((hid & (1 << i)) != 0){ *status = 0;
memset(buffer,0,sizeof(*buffer)); if(connectionOrderHelper[i] != NULL){
*status = 1;
s32 newhid = (1 << i); my_cb_user * usr = connectionOrderHelper[i];
pad_count[usr] = pad_count[usr] +1;
s32 hid = usr->slotdata.hidmask;
//printf("result[%d] usr: %08X\n",result,usr);
s32 realpad = pad_count[usr] - 1;
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; s32 buttons_hold = 0;
buttondata->hold = 0;
buttondata->trigger = 0;
buttondata->release = 0;
for(s32 pad = 0;pad<HID_MAX_PADS_COUNT;pad++){ s32 res;
InputButtonData * buttondata = &output[result].button_data; if((res = ControllerPatcherHID::getHIDData(hid,realpad,&data_cur)) == 0){
InputStickData * stickdata = &output[result].stick_data;
u8 * status = &output[result].status;
buttons_hold = 0;
buttondata->hold = 0;
buttondata->trigger = 0;
buttondata->release = 0;
result++;
if(result > array_size){
break;
}
s32 res;
if((res = ControllerPatcherHID::getHIDData(newhid,pad,&data_cur)) < 0){
*status = 0;
continue;
}
*status = 1;
res = ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_A); 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_B);
ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_X); ControllerPatcherUtils::getButtonPressed(data_cur,&buttons_hold,VPAD_BUTTON_X);
@ -840,89 +837,15 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevicesEx(I
stickdata->rightStickX = buffer->rightStick.x; stickdata->rightStickX = buffer->rightStick.x;
stickdata->rightStickY = buffer->rightStick.y; stickdata->rightStickY = buffer->rightStick.y;
//printf("result[%d] buttons %08X\n",result,buttons_hold);
data_cur->last_buttons = buttons_hold; data_cur->last_buttons = buttons_hold;
} }
} }
}
return array_size; result++;
} if(result >= array_size){
break;
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){
s32 hid = gHIDCurrentDevice;
HID_Data * data_cur;
VPADStatus pad_buffer;
VPADStatus * buffer = &pad_buffer;
s32 result = CONTROLLER_PATCHER_ERROR_NONE;
for(s32 i = 0;i< gHIDMaxDevices;i++){
if((hid & (1 << i)) != 0){
memset(buffer,0,sizeof(*buffer));
s32 newhid = (1 << i);
s32 deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid);
if(deviceslot < 0) continue;
DeviceInfo * deviceinfo = &(output[result].device_info);
InputButtonData * buttondata = output[result].button_data;
deviceinfo->slotdata.deviceslot = deviceslot;
deviceinfo->slotdata.hidmask = newhid;
deviceinfo->vidpid.vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1];
deviceinfo->vidpid.pid = config_controller[deviceslot][CONTRPS_PID][0] * 0x100 + config_controller[deviceslot][CONTRPS_PID][1];
/* not needed
if(config_controller[deviceslot][CONTRPS_PAD_COUNT][0] != CONTROLLER_PATCHER_INVALIDVALUE){
deviceinfo->pad_count = config_controller[deviceslot][CONTRPS_PAD_COUNT][1];
}else{
deviceinfo->pad_count = HID_MAX_PADS_COUNT;
}*/
s32 buttons_hold = 0;
for(s32 pad = 0;pad<HID_MAX_PADS_COUNT;pad++){
buttons_hold = 0;
buttondata[pad].hold = 0;
buttondata[pad].trigger = 0;
buttondata[pad].release = 0;
s32 res;
if((res = ControllerPatcherHID::getHIDData(deviceinfo->slotdata.hidmask,pad,&data_cur)) < 0){
continue;
}
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[pad].hold |= buttons_hold;
buttondata[pad].trigger |= (buttons_hold & (~(data_cur->last_buttons)));
buttondata[pad].release |= ((data_cur->last_buttons) & (~buttons_hold));
data_cur->last_buttons = buttons_hold;
}
result++;
if(result >= array_size){
break;
}
} }
} }

View File

@ -217,7 +217,6 @@ class ControllerPatcher{
@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. @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); static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size);
static CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevicesEx(InputDataEx * 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. 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.

View File

@ -15,7 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "controller_patcher/ControllerPatcher.hpp" #include "controller_patcher/ControllerPatcher.hpp"
#include "controller_patcher/ControllerPatcherWrapper.h" #include "controller_patcher/ControllerPatcherWrapper.h"
extern "C" void ControllerPatcherInit(void){ extern "C" void ControllerPatcherInit(void){
ControllerPatcher::Init(); ControllerPatcher::Init();
ControllerPatcher::disableControllerMapping(); ControllerPatcher::disableControllerMapping();
@ -23,12 +24,13 @@ extern "C" void ControllerPatcherInit(void){
ControllerPatcher::disableWiiUEnergySetting(); ControllerPatcher::disableWiiUEnergySetting();
} }
extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data){ extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data){
ControllerPatcher::setControllerDataFromHID(data); ControllerPatcher::setControllerDataFromHID(data);
} }
extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevicesEx(InputDataEx * output,s32 array_size){ extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size){
ControllerPatcher::gettingInputAllDevicesEx(output,array_size); ControllerPatcher::gettingInputAllDevices(output,array_size);
} }
extern "C" void ControllerPatcherDeInit(void){ extern "C" void ControllerPatcherDeInit(void){

View File

@ -14,7 +14,7 @@ extern "C" {
void ControllerPatcherInit(void); void ControllerPatcherInit(void);
void ControllerPatcherDeInit(void); void ControllerPatcherDeInit(void);
CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data); CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatus * data);
CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevicesEx(InputDataEx * output,s32 array_size); CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -223,6 +223,14 @@ typedef struct _HIDSlotData{
u32 hidmask; /**< Used HID-Mask */ u32 hidmask; /**< Used HID-Mask */
}HIDSlotData; }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 * @brief Struct where the data for the callback funtion is stored
*/ */
@ -235,6 +243,7 @@ typedef struct _my_cb_user{
u8 pad_slot; /**< number of the pad that will be used */ u8 pad_slot; /**< number of the pad that will be used */
u8 rumblestatus[HID_MAX_PADS_COUNT]; /**< Current status of the device rumble */ u8 rumblestatus[HID_MAX_PADS_COUNT]; /**< Current status of the device rumble */
u8 forceRumbleInTicks[HID_MAX_PADS_COUNT]; u8 forceRumbleInTicks[HID_MAX_PADS_COUNT];
DeviceVIDPIDInfo vidpid; /**< The VID/PID of the device */
}my_cb_user; }my_cb_user;
/** /**
@ -289,15 +298,6 @@ typedef struct _HID_DEVICE_DATA {
HID_Data pad_data[HID_MAX_PADS_COUNT]; HID_Data pad_data[HID_MAX_PADS_COUNT];
} HID_DEVICE_DATA; } HID_DEVICE_DATA;
/**
* @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 Infos of the device * @brief Infos of the device
*/ */
@ -353,14 +353,6 @@ typedef struct _InputButtonData{
u32 release; /**< Buttons that were button released */ u32 release; /**< Buttons that were button released */
}InputButtonData; }InputButtonData;
/**
* @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 */
InputButtonData button_data[HID_MAX_PADS_COUNT];
}InputData;
typedef struct _InputStickData{ typedef struct _InputStickData{
f32 leftStickX; f32 leftStickX;
f32 leftStickY; f32 leftStickY;
@ -368,11 +360,15 @@ typedef struct _InputStickData{
f32 rightStickY; f32 rightStickY;
}InputStickData; }InputStickData;
typedef struct _InputDataEx{ /**
* @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 status;
InputButtonData button_data; InputButtonData button_data;
InputStickData stick_data; InputStickData stick_data;
}InputDataEx; }InputData;
/** /**
* @brief The enumeration of WiiU Controller types * @brief The enumeration of WiiU Controller types

View File

@ -160,6 +160,7 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
usr->slotdata = device_info.slotdata; usr->slotdata = device_info.slotdata;
usr->transfersize = p_device->max_packet_size_rx; usr->transfersize = p_device->max_packet_size_rx;
usr->handle = p_device->handle; usr->handle = p_device->handle;
usr->vidpid = device_info.vidpid;
gHIDAttached |= slotdata->hidmask; gHIDAttached |= slotdata->hidmask;
gHIDCurrentDevice |= slotdata->hidmask; gHIDCurrentDevice |= slotdata->hidmask;
s32 pads_per_device = 1; s32 pads_per_device = 1;
@ -220,6 +221,15 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
DCInvalidateRange(&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] == NULL){
connectionOrderHelper[i] = usr;
break;
}
}
}
if(HID_DEBUG){ printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully attached\n",__LINE__); } if(HID_DEBUG){ printf("ControllerPatcherHID::AttachDetachCallback(line %d): Device successfully attached\n",__LINE__); }
if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD if(slotdata->hidmask == gHID_LIST_GC){ // GC PAD
@ -299,6 +309,15 @@ s32 ControllerPatcherHID::AttachDetachCallback(HIDClient *p_client, HIDDevice *p
} }
if(user_data){ if(user_data){
for(s32 j = 0;j < user_data->pads_per_device; j++){
for(s32 i = 0;i < gHIDMaxDevices; i++){
if(connectionOrderHelper[i] == user_data){
connectionOrderHelper[i] = NULL;
break;
}
}
}
config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1] &= ~ (1 << user_data->pad_slot); 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])); 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])); DCInvalidateRange(&config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1],sizeof(config_controller[slotdata->deviceslot][CONTRPS_CONNECTED_PADS][1]));

View File

@ -64,6 +64,8 @@ u8 gCallbackCooldown __attribute__((section(".data"))) = 0;
u8 gGlobalRumbleActivated __attribute__((section(".data"))) = 0; u8 gGlobalRumbleActivated __attribute__((section(".data"))) = 0;
my_cb_user * connectionOrderHelper[gHIDMaxDevices] __attribute__((section(".data")));
u32 gUDPClientip __attribute__((section(".data"))) = 0; u32 gUDPClientip __attribute__((section(".data"))) = 0;
ControllerMappingPADInfo* gProPadInfo[4] __attribute__((section(".data"))) = {&gControllerMapping.proController[0].pad_infos[0], ControllerMappingPADInfo* gProPadInfo[4] __attribute__((section(".data"))) = {&gControllerMapping.proController[0].pad_infos[0],
&gControllerMapping.proController[1].pad_infos[0], &gControllerMapping.proController[1].pad_infos[0],

View File

@ -68,6 +68,8 @@ extern wpad_sampling_callback_t gSamplingCallback;
extern u8 gCallbackCooldown; extern u8 gCallbackCooldown;
extern u8 gGlobalRumbleActivated; extern u8 gGlobalRumbleActivated;
extern my_cb_user * connectionOrderHelper[gHIDMaxDevices];
extern u32 gUDPClientip; extern u32 gUDPClientip;
extern ControllerMappingPADInfo* gProPadInfo[4]; extern ControllerMappingPADInfo* gProPadInfo[4];