Added a new getAllInputData function that also gets the stick data

This commit is contained in:
Maschell 2017-05-08 21:42:49 +02:00
parent adfde9f3a9
commit 48c554a9dd
6 changed files with 109 additions and 4 deletions

View File

@ -90,8 +90,11 @@ s32 ConfigReader::InitSDCard(){
if (this->pClient && this->pCmd){
FSInit();
if(HID_DEBUG){ printf("ConfigReader::InitSDCard(line %d): FSInit done\n",__LINE__); }
FSInitCmdBlock((FSCmdBlock*)pCmd);
FSAddClientEx((FSClient*)pClient,0, -1);
if(HID_DEBUG){ printf("ConfigReader::InitSDCard(line %d): Init CMD Block done\n",__LINE__); }
status = FSAddClientEx((FSClient*)pClient,0, -1);
if(HID_DEBUG){ printf("ConfigReader::InitSDCard(line %d): Added Client, result: %d\n",__LINE__,status); }
if ((status = FSGetMountSource((FSClient*)this->pClient,(FSCmdBlock*)this->pCmd, FS_MOUNT_SOURCE_SD, (FSMountSource *)mountSrc, 0)) == FS_STATUS_OK)
{
if(HID_DEBUG){ printf("ConfigReader::InitSDCard(line %d): \n",__LINE__); }

View File

@ -755,6 +755,92 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type
return CONTROLLER_PATCHER_ERROR_NONE;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevicesEx(InputDataEx * 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(result > array_size){
break;
}
if((hid & (1 << i)) != 0){
memset(buffer,0,sizeof(*buffer));
s32 newhid = (1 << i);
s32 buttons_hold = 0;
for(s32 pad = 0;pad<HID_MAX_PADS_COUNT;pad++){
InputButtonData * buttondata = &output[result].button_data;
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);
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;
data_cur->last_buttons = buttons_hold;
}
}
}
return array_size;
}
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(InputData * output,s32 array_size){
s32 hid = gHIDCurrentDevice;
HID_Data * data_cur;

View File

@ -217,6 +217,7 @@ 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.
**/
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.

View File

@ -27,8 +27,8 @@ extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR setControllerDataFromHID(VPADStatu
ControllerPatcher::setControllerDataFromHID(data);
}
extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevices(InputData * output,s32 array_size){
ControllerPatcher::gettingInputAllDevices(output,array_size);
extern "C" CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevicesEx(InputDataEx * output,s32 array_size){
ControllerPatcher::gettingInputAllDevicesEx(output,array_size);
}
extern "C" void ControllerPatcherDeInit(void){

View File

@ -14,7 +14,7 @@ extern "C" {
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);
CONTROLLER_PATCHER_RESULT_OR_ERROR gettingInputAllDevicesEx(InputDataEx * output,s32 array_size);
#ifdef __cplusplus
}

View File

@ -352,6 +352,7 @@ typedef struct _InputButtonData{
u32 trigger; /**< Buttons that started pressing */
u32 release; /**< Buttons that were button released */
}InputButtonData;
/**
* @brief Struct where the inputdata of a device for all HID_MAX_PADS_COUNT pads can be stored
*/
@ -359,6 +360,20 @@ 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{
f32 leftStickX;
f32 leftStickY;
f32 rightStickX;
f32 rightStickY;
}InputStickData;
typedef struct _InputDataEx{
u8 status;
InputButtonData button_data;
InputStickData stick_data;
}InputDataEx;
/**
* @brief The enumeration of WiiU Controller types
*/