mirror of
https://github.com/Maschell/controller_patcher.git
synced 2024-11-22 03:59:16 +01:00
[WIP] Trying to implement motion controls and you the touch pad for emulating a mouse
This commit is contained in:
parent
3bf07857be
commit
22775dcbbb
@ -402,6 +402,14 @@ void ControllerPatcher::ResetConfig(){
|
|||||||
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS4_BUTTON_GUIDE[0], HID_DS4_BUTTON_GUIDE[1]);
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_HOME], HID_DS4_BUTTON_GUIDE[0], HID_DS4_BUTTON_GUIDE[1]);
|
||||||
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_PAD_COUNT);
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_PAD_COUNT], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_PAD_COUNT);
|
||||||
|
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_ACC_X], HID_DS4_ACC[ACC_CONF_X_1BYTE], HID_DS4_ACC[ACC_CONF_X_2BYTE]);
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_ACC_Y], HID_DS4_ACC[ACC_CONF_Y_1BYTE], HID_DS4_ACC[ACC_CONF_Y_2BYTE]);
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_ACC_Z], HID_DS4_ACC[ACC_CONF_Z_1BYTE], HID_DS4_ACC[ACC_CONF_Z_2BYTE]);
|
||||||
|
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_GYRO_X], HID_DS4_GYRO[GYRO_CONF_X_1BYTE], HID_DS4_GYRO[GYRO_CONF_X_2BYTE]);
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_GYRO_Y], HID_DS4_GYRO[GYRO_CONF_Y_1BYTE], HID_DS4_GYRO[GYRO_CONF_Y_2BYTE]);
|
||||||
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_GYRO_Z], HID_DS4_GYRO[GYRO_CONF_Z_1BYTE], HID_DS4_GYRO[GYRO_CONF_Z_2BYTE]);
|
||||||
|
|
||||||
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS4_STICK_L_X[STICK_CONF_BYTE], HID_DS4_STICK_L_X[STICK_CONF_DEFAULT]);
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X], HID_DS4_STICK_L_X[STICK_CONF_BYTE], HID_DS4_STICK_L_X[STICK_CONF_DEFAULT]);
|
||||||
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_X[STICK_CONF_DEADZONE]);
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_DEADZONE], CONTROLLER_PATCHER_VALUE_SET, HID_DS4_STICK_L_X[STICK_CONF_DEADZONE]);
|
||||||
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS4_STICK_L_X[STICK_CONF_MIN], HID_DS4_STICK_L_X[STICK_CONF_MAX]);
|
ControllerPatcherUtils::setConfigValue((u8*)&config_controller[ds4_slot][CONTRPS_VPAD_BUTTON_L_STICK_X_MINMAX], HID_DS4_STICK_L_X[STICK_CONF_MIN], HID_DS4_STICK_L_X[STICK_CONF_MAX]);
|
||||||
@ -735,18 +743,36 @@ HID_Mouse_Data * ControllerPatcher::getMouseData(){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HID_Mouse_Data * result = NULL;
|
|
||||||
|
|
||||||
for(s32 i;i<HID_MAX_DEVICES_PER_SLOT;i++){
|
for(s32 i;i<HID_MAX_DEVICES_PER_SLOT;i++){
|
||||||
ControllerMappingPADInfo * padinfo = &(CMPAD->pad_infos[i]);
|
ControllerMappingPADInfo * padinfo = &(CMPAD->pad_infos[i]);
|
||||||
if(!padinfo->active){
|
|
||||||
break;
|
if(!padinfo->active){ //?!?!?!
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if(padinfo->type == CM_Type_Mouse){
|
|
||||||
result = &(gHID_Devices[gMouseSlot].pad_data[padinfo->pad].data_union.mouse.cur_mouse_data);
|
if(padinfo->type == CM_Type_Mouse || (padinfo->vidpid.vid == 0x054c && padinfo->vidpid.pid == 0x09CC)){
|
||||||
|
DeviceInfo device_info;
|
||||||
|
memset(&device_info,0,sizeof(device_info));
|
||||||
|
device_info.vidpid = padinfo->vidpid;
|
||||||
|
|
||||||
|
if(ControllerPatcherUtils::getDeviceInfoFromVidPid(&device_info) < 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
HID_Data * data = &gHID_Devices[device_info.slotdata.deviceslot].pad_data[padinfo->pad];
|
||||||
|
|
||||||
|
if(!data->mouse.isValid){ //is valid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data->mouse.ticksSinceChange < 60*5){ //Was moved in the last 5 seconds
|
||||||
|
data->mouse.ticksSinceChange++;
|
||||||
|
HID_Mouse_Data * mouse = &(data->mouse.cur_mouse_data);
|
||||||
|
return mouse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return (HID_Mouse_Data *) 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type type,u32 status){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::setRumble(UController_Type type,u32 status){
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
#define HID_SDCARD_READ 2
|
#define HID_SDCARD_READ 2
|
||||||
|
|
||||||
#define gHIDMaxDevices 32
|
#define gHIDMaxDevices 32
|
||||||
#define HID_MAX_DATA_LENGTH_PER_PAD 16
|
#define HID_MAX_DATA_LENGTH_PER_PAD 40
|
||||||
|
#define HID_EXTRA_DATA_LENGTH 0x10
|
||||||
#define HID_MAX_PADS_COUNT 5
|
#define HID_MAX_PADS_COUNT 5
|
||||||
#define HID_MAX_DEVICES_PER_SLOT 2
|
#define HID_MAX_DEVICES_PER_SLOT 2
|
||||||
|
|
||||||
@ -92,7 +93,33 @@ enum Controller_Stick_Defines
|
|||||||
STICK_CONF_ENUM_MAXVALUE /**< Maxmimum enum value for iteration*/
|
STICK_CONF_ENUM_MAXVALUE /**< Maxmimum enum value for iteration*/
|
||||||
};
|
};
|
||||||
|
|
||||||
#define STICK_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!!
|
enum Controller_Acc_Defines
|
||||||
|
{
|
||||||
|
ACC_CONF_MAGIC_VERSION, /**< Version of the acc configuration. Changes with every format*/
|
||||||
|
ACC_CONF_X_1BYTE, /**< first Byte where the X is stored*/
|
||||||
|
ACC_CONF_X_2BYTE, /**< second Byte where the X is stored*/
|
||||||
|
ACC_CONF_Y_1BYTE, /**< first Byte where the Y is stored*/
|
||||||
|
ACC_CONF_Y_2BYTE, /**< second Byte where the Y is stored*/
|
||||||
|
ACC_CONF_Z_1BYTE, /**< first Byte where the Z is stored*/
|
||||||
|
ACC_CONF_Z_2BYTE, /**< second Byte where the Z is stored*/
|
||||||
|
ACC_CONF_ENUM_MAXVALUE /**< Maxmimum enum value for iteration*/
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Controller_Gyro_Defines
|
||||||
|
{
|
||||||
|
GYRO_CONF_MAGIC_VERSION, /**< Version of the acc configuration. Changes with every format*/
|
||||||
|
GYRO_CONF_X_1BYTE, /**< first Byte where the X is stored*/
|
||||||
|
GYRO_CONF_X_2BYTE, /**< second Byte where the X is stored*/
|
||||||
|
GYRO_CONF_Y_1BYTE, /**< first Byte where the Y is stored*/
|
||||||
|
GYRO_CONF_Y_2BYTE, /**< second Byte where the Y is stored*/
|
||||||
|
GYRO_CONF_Z_1BYTE, /**< first Byte where the Z is stored*/
|
||||||
|
GYRO_CONF_Z_2BYTE, /**< second Byte where the Z is stored*/
|
||||||
|
GYRO_CONF_ENUM_MAXVALUE /**< Maxmimum enum value for iteration*/
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ACC_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!!
|
||||||
|
#define GYRO_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!!
|
||||||
|
#define STICK_CONF_MAGIC_VALUE 0xF0 // When you change the enum above, Dont forget to change the magic version!!!!
|
||||||
|
|
||||||
//! most data has the format: byte,value (byte starting at 0)
|
//! most data has the format: byte,value (byte starting at 0)
|
||||||
enum Controller_Patcher_Settings
|
enum Controller_Patcher_Settings
|
||||||
@ -164,6 +191,14 @@ enum Controller_Patcher_Settings
|
|||||||
CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE, //! Deadzone
|
CONTRPS_VPAD_BUTTON_R_STICK_Y_DEADZONE, //! Deadzone
|
||||||
CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX, //! min,max
|
CONTRPS_VPAD_BUTTON_R_STICK_Y_MINMAX, //! min,max
|
||||||
|
|
||||||
|
CONTRPS_VPAD_ACC_X,
|
||||||
|
CONTRPS_VPAD_ACC_Y,
|
||||||
|
CONTRPS_VPAD_ACC_Z,
|
||||||
|
|
||||||
|
CONTRPS_VPAD_GYRO_X,
|
||||||
|
CONTRPS_VPAD_GYRO_Y,
|
||||||
|
CONTRPS_VPAD_GYRO_Z,
|
||||||
|
|
||||||
CONTRPS_VPAD_BUTTON_L_STICK_UP,
|
CONTRPS_VPAD_BUTTON_L_STICK_UP,
|
||||||
CONTRPS_VPAD_BUTTON_L_STICK_DOWN,
|
CONTRPS_VPAD_BUTTON_L_STICK_DOWN,
|
||||||
CONTRPS_VPAD_BUTTON_L_STICK_LEFT,
|
CONTRPS_VPAD_BUTTON_L_STICK_LEFT,
|
||||||
@ -266,16 +301,17 @@ typedef struct _HID_Data {
|
|||||||
u32 handle; /**< The HID-handle this device is using */
|
u32 handle; /**< The HID-handle this device is using */
|
||||||
u8 rumbleActive; /**< 1 when rumble is active */
|
u8 rumbleActive; /**< 1 when rumble is active */
|
||||||
u32 last_buttons; /**< The last pressed buttons, based on VPAD_BUTTON_XXX data */
|
u32 last_buttons; /**< The last pressed buttons, based on VPAD_BUTTON_XXX data */
|
||||||
union{
|
struct{
|
||||||
struct{
|
u8 cur_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the current controller data is stored */
|
||||||
u8 cur_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the current controller data is stored */
|
u8 last_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the last controller data is stored */
|
||||||
u8 last_hid_data[HID_MAX_DATA_LENGTH_PER_PAD]; /**< Array where the last controller data is stored */
|
} controller; /**< Used when the device in a controller. Using u8 array where the raw data of the controller is placed. */
|
||||||
} controller; /**< Used when the device in a controller. Using u8 array where the raw data of the controller is placed. */
|
struct{
|
||||||
struct{
|
|
||||||
HID_Mouse_Data cur_mouse_data; /**< Struct where the current mouse data is stored */
|
HID_Mouse_Data cur_mouse_data; /**< Struct where the current mouse data is stored */
|
||||||
HID_Mouse_Data last_mouse_data; /**< Struct where the last mouse data is stored */
|
HID_Mouse_Data last_mouse_data; /**< Struct where the last mouse data is stored */
|
||||||
} mouse; /**< Used when the device in a mouse. Using a new struct to store the data. */
|
u16 ticksSinceChange;
|
||||||
}data_union; /**< The data union where the current and last data is stored.*/
|
u8 isValid;
|
||||||
|
} mouse;
|
||||||
|
u8 extraData[0x10]; /**< The device type*/
|
||||||
DEVICE_TYPE type; /**< The device type*/
|
DEVICE_TYPE type; /**< The device type*/
|
||||||
HIDSlotData slotdata; /**< Information about the deviceslot and his mask*/
|
HIDSlotData slotdata; /**< Information about the deviceslot and his mask*/
|
||||||
my_cb_user * user_data; /**< Pointer to the user data the read callback is using*/
|
my_cb_user * user_data; /**< Pointer to the user data the read callback is using*/
|
||||||
@ -395,11 +431,17 @@ enum UController_Type{
|
|||||||
#define HID_DS3_VID 0x054c
|
#define HID_DS3_VID 0x054c
|
||||||
#define HID_DS3_PID 0x0268
|
#define HID_DS3_PID 0x0268
|
||||||
|
|
||||||
|
//#define HID_DS4_VID 0x054c
|
||||||
|
//#define HID_DS4_PID 0x05c4
|
||||||
|
|
||||||
|
//#define HID_NEW_DS4_VID 0x054c
|
||||||
|
//#define HID_NEW_DS4_PID 0x09CC
|
||||||
|
|
||||||
#define HID_DS4_VID 0x054c
|
#define HID_DS4_VID 0x054c
|
||||||
#define HID_DS4_PID 0x05c4
|
#define HID_DS4_PID 0x09CC
|
||||||
|
|
||||||
#define HID_NEW_DS4_VID 0x054c
|
#define HID_NEW_DS4_VID 0x054c
|
||||||
#define HID_NEW_DS4_PID 0x09CC
|
#define HID_NEW_DS4_PID 0x09CD
|
||||||
|
|
||||||
#define HID_XINPUT_VID 0x7331
|
#define HID_XINPUT_VID 0x7331
|
||||||
#define HID_XINPUT_PID 0x1337
|
#define HID_XINPUT_PID 0x1337
|
||||||
|
@ -57,7 +57,9 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]);
|
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]);
|
||||||
HID_Mouse_Data * cur_mouse_data = &data_ptr->data_union.mouse.cur_mouse_data;
|
HID_Mouse_Data * cur_mouse_data = &data_ptr->mouse.cur_mouse_data;
|
||||||
|
|
||||||
|
u16 * ticksSinceChangePointer = &data_ptr->mouse.ticksSinceChange;
|
||||||
|
|
||||||
data_ptr->type = DEVICE_TYPE_MOUSE;
|
data_ptr->type = DEVICE_TYPE_MOUSE;
|
||||||
//log_printf("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered);
|
//log_printf("%02X %02X %02X %02X %02X bytes_transfered: %d\n",buf[0],buf[1],buf[2],buf[3],buf[4],bytes_transfered);
|
||||||
@ -88,6 +90,7 @@ void ControllerPatcherHID::myHIDMouseReadCallback(u32 handle, s32 error, unsigne
|
|||||||
if(cur_mouse_data->Y > 720) cur_mouse_data->Y = 720;
|
if(cur_mouse_data->Y > 720) cur_mouse_data->Y = 720;
|
||||||
|
|
||||||
cur_mouse_data->valuedChanged = 1;
|
cur_mouse_data->valuedChanged = 1;
|
||||||
|
*ticksSinceChangePointer = 0;
|
||||||
|
|
||||||
//log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value);
|
//log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %d = X: %d Y: %d \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],bytes_transfered,x_value,y_value);
|
||||||
|
|
||||||
@ -348,8 +351,8 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b
|
|||||||
//Copy the data for all 4 pads
|
//Copy the data for all 4 pads
|
||||||
for(s32 i = 0;i<4;i++){
|
for(s32 i = 0;i<4;i++){
|
||||||
data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]);
|
data_ptr = &(gHID_Devices[gHID_SLOT_GC].pad_data[i]);
|
||||||
memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),10); //save last data.
|
memcpy(&(data_ptr->controller.last_hid_data[0]),&(data_ptr->controller.cur_hid_data[0]),10); //save last data.
|
||||||
memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data.
|
memcpy(&(data_ptr->controller.cur_hid_data[0]),&buf[(i*9)+1],9); //save new data.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,8 +469,12 @@ void ControllerPatcherHID::HIDReadCallback(u32 handle, unsigned char *buf, u32 b
|
|||||||
|
|
||||||
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]);
|
HID_Data * data_ptr = &(gHID_Devices[usr->slotdata.deviceslot].pad_data[slot]);
|
||||||
|
|
||||||
memcpy(&(data_ptr->data_union.controller.last_hid_data[0]),&(data_ptr->data_union.controller.cur_hid_data[0]),dsize); // save the last data.
|
//s32 i = 0;
|
||||||
memcpy(&(data_ptr->data_union.controller.cur_hid_data[0]),&buf[0],dsize); // save the new data.
|
//log_printf("data %08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X ", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++;
|
||||||
|
//log_printf("%02X %02X %02X %02X %02X %02X %02X %02X %02X\n", buf[i*9+0],buf[i*9+1],buf[i*9+2],buf[i*9+3],buf[i*9+4],buf[i*9+5],buf[i*9+6],buf[i*9+7],buf[i*9+8]);i++;
|
||||||
|
|
||||||
|
memcpy(&(data_ptr->controller.last_hid_data[0]),&(data_ptr->controller.cur_hid_data[0]),dsize); // save the last data.
|
||||||
|
memcpy(&(data_ptr->controller.cur_hid_data[0]),&buf[0],dsize); // save the new data.
|
||||||
|
|
||||||
DCFlushRange(&gHID_Devices[usr->slotdata.deviceslot].pad_data[slot],sizeof(HID_Data));
|
DCFlushRange(&gHID_Devices[usr->slotdata.deviceslot].pad_data[slot],sizeof(HID_Data));
|
||||||
|
|
||||||
@ -491,7 +498,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
|
|||||||
data_cur = data[i];
|
data_cur = data[i];
|
||||||
|
|
||||||
if(data_cur->slotdata.hidmask & gHID_LIST_MOUSE){ //Reset the input when we have no new inputs
|
if(data_cur->slotdata.hidmask & gHID_LIST_MOUSE){ //Reset the input when we have no new inputs
|
||||||
HID_Mouse_Data * mouse_data = &data_cur->data_union.mouse.cur_mouse_data;
|
HID_Mouse_Data * mouse_data = &data_cur->mouse.cur_mouse_data;
|
||||||
if(mouse_data->valuedChanged == 1){ //Fix for the mouse cursor
|
if(mouse_data->valuedChanged == 1){ //Fix for the mouse cursor
|
||||||
mouse_data->valuedChanged = 0;
|
mouse_data->valuedChanged = 0;
|
||||||
}else{
|
}else{
|
||||||
@ -532,6 +539,8 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherHID::setVPADControllerData(V
|
|||||||
|
|
||||||
ControllerPatcherUtils::convertAnalogSticks(data_cur,buffer);
|
ControllerPatcherUtils::convertAnalogSticks(data_cur,buffer);
|
||||||
|
|
||||||
|
ControllerPatcherUtils::convertGyroAndAcc(data_cur,buffer);
|
||||||
|
|
||||||
ControllerPatcherUtils::setEmulatedSticks(buffer,&last_emulate_stick);
|
ControllerPatcherUtils::setEmulatedSticks(buffer,&last_emulate_stick);
|
||||||
|
|
||||||
ControllerPatcherUtils::checkAndSetMouseMode(data_cur);
|
ControllerPatcherUtils::checkAndSetMouseMode(data_cur);
|
||||||
|
@ -15,6 +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 "ControllerPatcherUtils.hpp"
|
#include "ControllerPatcherUtils.hpp"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
|
|||||||
|
|
||||||
do{
|
do{
|
||||||
if(data->type == DEVICE_TYPE_MOUSE){
|
if(data->type == DEVICE_TYPE_MOUSE){
|
||||||
HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data;
|
HID_Mouse_Data * ms_data = &data->mouse.cur_mouse_data;
|
||||||
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
|
if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
|
||||||
if(VPADButton == VPAD_BUTTON_TOUCH){
|
if(VPADButton == VPAD_BUTTON_TOUCH){
|
||||||
@ -71,7 +73,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
|
|||||||
}
|
}
|
||||||
result = 0; break;
|
result = 0; break;
|
||||||
}
|
}
|
||||||
u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
s32 cur_config = 0;
|
s32 cur_config = 0;
|
||||||
@ -224,7 +226,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getButtonPressed(HID_
|
|||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::isValueSet(HID_Data * data,s32 cur_config){
|
||||||
if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
u32 hidmask = data->slotdata.hidmask;
|
u32 hidmask = data->slotdata.hidmask;
|
||||||
@ -293,7 +295,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setButtonData(VPADDat
|
|||||||
|
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hidmask,s32 pad){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hidmask,s32 pad){
|
||||||
if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){
|
if(hidmask & gHID_LIST_GC && pad >= 0 && pad <= 3){
|
||||||
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
|
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[pad].controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[pad].controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
|
||||||
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
|
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
|
||||||
}else{
|
}else{
|
||||||
s32 deviceslot = getDeviceSlot(hidmask);
|
s32 deviceslot = getDeviceSlot(hidmask);
|
||||||
@ -310,10 +312,10 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkActivePad(u32 hi
|
|||||||
/*
|
/*
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(u32 hidmask){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::getActivePad(u32 hidmask){
|
||||||
if(hidmask & gHID_LIST_GC){
|
if(hidmask & gHID_LIST_GC){
|
||||||
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 0;
|
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[0].controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[0].controller.cur_hid_data[0] & 0x22) != 0x22))) return 0;
|
||||||
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
|
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[1].controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[1].controller.cur_hid_data[0] & 0x22) != 0x22))) return 1;
|
||||||
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[2].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[2].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 2;
|
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[2].controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[2].controller.cur_hid_data[0] & 0x22) != 0x22))) return 2;
|
||||||
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[3].data_union.controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[3].data_union.controller.cur_hid_data[0] & 0x22) != 0x22))) return 3;
|
if (!(((gHID_Devices[gHID_SLOT_GC].pad_data[3].controller.cur_hid_data[0] & 0x10) == 0) && ((gHID_Devices[gHID_SLOT_GC].pad_data[3].controller.cur_hid_data[0] & 0x22) != 0x22))) return 3;
|
||||||
|
|
||||||
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
|
return CONTROLLER_PATCHER_ERROR_NO_PAD_CONNECTED;
|
||||||
}
|
}
|
||||||
@ -420,7 +422,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
|
|||||||
if (data->type == DEVICE_TYPE_MOUSE){
|
if (data->type == DEVICE_TYPE_MOUSE){
|
||||||
|
|
||||||
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values
|
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ // TODO: tweak values
|
||||||
HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data;
|
HID_Mouse_Data * ms_data = &data->mouse.cur_mouse_data;
|
||||||
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
f32 x_value = ms_data->deltaX/10.0f;
|
f32 x_value = ms_data->deltaX/10.0f;
|
||||||
@ -438,7 +440,7 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
|
|||||||
buffer->rstick.y += y_value;
|
buffer->rstick.y += y_value;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
s32 deadzone = 0;
|
s32 deadzone = 0;
|
||||||
@ -531,6 +533,164 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertAnalogSticks(H
|
|||||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PI 3.14159265
|
||||||
|
|
||||||
|
Vec3D smoothedAcc;
|
||||||
|
Vec3D smoothedAccNorm;
|
||||||
|
|
||||||
|
Vec3D smoothedGyro;
|
||||||
|
Vec3D smoothedGyroNorm;
|
||||||
|
|
||||||
|
|
||||||
|
float Vec3Ddot(Vec3D v1, Vec3D v2) {
|
||||||
|
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Vec3Dlength(Vec3D p) {
|
||||||
|
return (float) sqrt(Vec3Ddot(p,p));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3D Vec3Dsub(Vec3D v1, Vec3D v2) {
|
||||||
|
v1.x -= v2.x;
|
||||||
|
v1.y -= v2.y;
|
||||||
|
v1.z -= v2.z;
|
||||||
|
return v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3D applyPitch(Vec3D in,float val){
|
||||||
|
Vec3D out = in;
|
||||||
|
out.y = (float) (in.y * cos(val) - in.z * sin(val));
|
||||||
|
out.z = (float) (in.z * cos(val) + in.y * sin(val));
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3D applyRoll(Vec3D in,double val){
|
||||||
|
Vec3D out = in;
|
||||||
|
out.x = (float) (in.x * cos(val) - in.y * sin(val));
|
||||||
|
out.y = (float) (in.y * cos(val) + in.x * sin(val));
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3D lastAcc = {0,0,0};
|
||||||
|
|
||||||
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::convertGyroAndAcc(HID_Data * data, VPADData * buffer){
|
||||||
|
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
s32 deviceslot = data->slotdata.deviceslot;
|
||||||
|
|
||||||
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
|
if(cur_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
short accX,accY,accZ = 0;
|
||||||
|
short gyroX,gyroY,gyroZ = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
buffer->acc.x = smoothedAccNorm.x;
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_ACC_X][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_ACC_X][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
accX = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_X][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_X][1]];
|
||||||
|
smoothedAcc.x = (accX + smoothedAcc.x * 2.0f) / 3.0f; // smooth out
|
||||||
|
smoothedAccNorm.x = ((smoothedAcc.x/8192.0f));
|
||||||
|
buffer->dir.X.x = 1.0f;
|
||||||
|
buffer->dir.X.y = 0.0f;
|
||||||
|
buffer->dir.X.z = 0.0f;
|
||||||
|
|
||||||
|
buffer->dir.Y.x = 0.0f;
|
||||||
|
buffer->dir.Y.y = 1.0f;
|
||||||
|
buffer->dir.Y.z = 0.0f;
|
||||||
|
|
||||||
|
buffer->dir.Z.x = 0.0f;
|
||||||
|
buffer->dir.Z.y = 0.0f;
|
||||||
|
buffer->dir.Z.z = 1.0f;
|
||||||
|
//buffer->dir.X.y = smoothedAccNorm.x * -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_ACC_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_ACC_Y][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
accY = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_Y][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_Y][1]];
|
||||||
|
smoothedAcc.y = (accY + smoothedAcc.y * 2.0f) / 3.0f; // smooth out
|
||||||
|
smoothedAccNorm.y = ((smoothedAcc.y/8192.0f));
|
||||||
|
buffer->acc.y = smoothedAccNorm.y * -1.0f;
|
||||||
|
if(smoothedAccNorm.y < 0.0f){
|
||||||
|
buffer->acc_vertical.x = smoothedAccNorm.y * -1.0f;
|
||||||
|
}else{
|
||||||
|
buffer->acc_vertical.x = smoothedAccNorm.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_ACC_Z][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_ACC_Z][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
accZ = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_Z][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_ACC_Z][1]];
|
||||||
|
smoothedAcc.z = (accZ + smoothedAcc.z * 2.0f) / 3.0f; // smooth out
|
||||||
|
smoothedAccNorm.z = ((smoothedAcc.z/8192.0f));
|
||||||
|
buffer->acc.z = smoothedAccNorm.z;
|
||||||
|
buffer->acc_vertical.y = smoothedAccNorm.z * -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_GYRO_X][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_GYRO_X][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
gyroX = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_X][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_X][1]];
|
||||||
|
smoothedGyro.x = (gyroX + smoothedGyro.x * 2.0f) / 3.0f; // smooth out
|
||||||
|
//if(smoothedGyro.x > 256.0f || smoothedGyro.x < - 256.0f){
|
||||||
|
buffer->gyro.x = (smoothedGyro.x/4096.0f * -1.0f);
|
||||||
|
//}else{
|
||||||
|
// buffer->gyro.x = 0.0f;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_GYRO_Y][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_GYRO_Y][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
gyroY = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_Y][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_Y][1]];
|
||||||
|
smoothedGyro.y = (gyroY + smoothedGyro.y * 2.0f) / 3.0f; // smooth out
|
||||||
|
if(smoothedGyro.y < -260.0f || smoothedGyro.y > -230.0f){
|
||||||
|
buffer->gyro.y = (smoothedGyro.y/4096.0f);
|
||||||
|
}else{
|
||||||
|
buffer->gyro.y = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if((config_controller[deviceslot][CONTRPS_VPAD_GYRO_Z][0] != CONTROLLER_PATCHER_INVALIDVALUE) &&
|
||||||
|
(config_controller[deviceslot][CONTRPS_VPAD_GYRO_Z][1] != CONTROLLER_PATCHER_INVALIDVALUE)){
|
||||||
|
gyroZ = (cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_Z][0]] *0x100 ) + cur_data[config_controller[deviceslot][CONTRPS_VPAD_GYRO_Z][1]];
|
||||||
|
smoothedGyro.z = (gyroZ + smoothedGyro.z * 2.0f) / 3.0f; // smooth out
|
||||||
|
if(smoothedGyro.z > 256.0f || smoothedGyro.z < - 256.0f){
|
||||||
|
buffer->gyro.z = (smoothedGyro.z/4096.0f);
|
||||||
|
}else{
|
||||||
|
buffer->gyro.z = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float roll = atan2(-smoothedAcc.y, smoothedAcc.z) + PI/2.0f;
|
||||||
|
float pitch = atan2(smoothedAcc.x, sqrt(smoothedAcc.y*smoothedAcc.y + smoothedAcc.z*smoothedAcc.z));
|
||||||
|
|
||||||
|
if(roll > PI){
|
||||||
|
roll -= 2.0f*PI;
|
||||||
|
}
|
||||||
|
pitch = pitch * -1.0f;
|
||||||
|
|
||||||
|
//buffer->dir.X = applyRoll(buffer->dir.X,pitch);
|
||||||
|
//buffer->dir.Y = applyPitch(applyRoll(buffer->dir.Y,pitch),roll);
|
||||||
|
buffer->dir.Y = applyPitch(buffer->dir.Y,roll);
|
||||||
|
buffer->dir.Z = applyPitch(buffer->dir.Z,roll);
|
||||||
|
|
||||||
|
/*
|
||||||
|
buffer->dir.Y.y = buffer->acc.y * -1.0f;
|
||||||
|
buffer->dir.Y.z = buffer->acc.z;
|
||||||
|
buffer->dir.Z.y = buffer->acc.z * -1.0f;
|
||||||
|
buffer->dir.Z.z = buffer->acc.y * -1.0f;*/
|
||||||
|
|
||||||
|
buffer->acc_magnitude = Vec3Dlength(smoothedAccNorm);
|
||||||
|
Vec3D tmp = Vec3Dsub(smoothedAccNorm,lastAcc);
|
||||||
|
buffer->acc_variation = Vec3Dlength(tmp);
|
||||||
|
lastAcc = smoothedAccNorm;
|
||||||
|
|
||||||
|
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPADData * buffer, u32 * last_emulatedSticks){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPADData * buffer, u32 * last_emulatedSticks){
|
||||||
if(buffer == NULL || last_emulatedSticks == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(buffer == NULL || last_emulatedSticks == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
@ -583,36 +743,107 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setEmulatedSticks(VPA
|
|||||||
|
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADData * buffer){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::setTouch(HID_Data * data,VPADData * buffer){
|
||||||
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(buffer == NULL || data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
u32 hidmask = data->slotdata.hidmask;
|
||||||
if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
|
if(data->type == DEVICE_TYPE_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){
|
||||||
|
data->mouse.isValid = 1;
|
||||||
s32 buttons_hold;
|
s32 buttons_hold;
|
||||||
if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){
|
if(getButtonPressed(data,&buttons_hold,VPAD_BUTTON_TOUCH)){
|
||||||
HID_Mouse_Data * ms_data = &data->data_union.mouse.cur_mouse_data;
|
HID_Mouse_Data * ms_data = &data->mouse.cur_mouse_data;
|
||||||
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
if(ms_data == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
s32 x_mouse = 80 + ((int)(((ms_data->X)*1.0f/1280.0)*3890.0f));
|
clickTouchScreen(buffer,ms_data->X,ms_data->Y);
|
||||||
s32 y_mouse = 3910 - ((int)(((ms_data->Y)*1.0f/720.0)*3760.0f));
|
}
|
||||||
buffer->tpdata.x = x_mouse;
|
}else if(hidmask & gHID_LIST_DS4){
|
||||||
buffer->tpdata.y = y_mouse;
|
HID_Mouse_Data * cur_ms_data = &data->mouse.cur_mouse_data;
|
||||||
buffer->tpdata.touched = 1;
|
u8 * extra_data = &data->extraData[0];
|
||||||
buffer->tpdata.invalid = 0;
|
u8 * last_data = &data->controller.last_hid_data[0];
|
||||||
buffer->tpdata1.x = x_mouse;
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
buffer->tpdata1.y = y_mouse;
|
u8 id = cur_data[34] & 0x7f;
|
||||||
buffer->tpdata1.touched = 1;
|
u8 isActiveDrag = (cur_data[38] >> 7) == 0;
|
||||||
buffer->tpdata1.invalid = 0;
|
u8 isActive = (cur_data[34] >> 7) == 0;
|
||||||
buffer->tpdata2.x = x_mouse;
|
u8 lastActive = (last_data[34] >> 7) == 0;
|
||||||
buffer->tpdata2.y = y_mouse;
|
u8 click = 0;
|
||||||
buffer->tpdata2.touched = 1;
|
|
||||||
buffer->tpdata2.invalid = 0;
|
if(isActive){
|
||||||
|
data->mouse.ticksSinceChange = 0;
|
||||||
|
data->mouse.isValid = 1;
|
||||||
|
}else{
|
||||||
|
data->mouse.ticksSinceChange++;
|
||||||
|
extra_data[1] = 0;
|
||||||
|
extra_data[2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isActive && lastActive){
|
||||||
|
extra_data[0]++;
|
||||||
|
|
||||||
|
short xValue = ((cur_data[36] & 0x0f) << 8) | cur_data[35];
|
||||||
|
short yValue = cur_data[37] << 4 | ((cur_data[36] & 0xf0) >> 4);
|
||||||
|
|
||||||
|
short lastXValue = ((last_data[36] & 0x0f) << 8) | last_data[35];
|
||||||
|
short lastYValue = last_data[37] << 4 | ((last_data[36] & 0xf0) >> 4);
|
||||||
|
|
||||||
|
s16 deltaX = xValue - lastXValue;
|
||||||
|
s16 deltaY = yValue - lastYValue;
|
||||||
|
|
||||||
|
if((deltaX > -2 && deltaX < 2) &&
|
||||||
|
(deltaX > -2 && deltaX < 2)){
|
||||||
|
extra_data[1]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_ms_data->X += (deltaX / 1.5f);
|
||||||
|
cur_ms_data->Y += (deltaY / 1.5f);
|
||||||
|
|
||||||
|
if(cur_ms_data->X < 0) cur_ms_data->X = 0;
|
||||||
|
if(cur_ms_data->X > 1280) cur_ms_data->X = 1280;
|
||||||
|
|
||||||
|
if(cur_ms_data->Y < 0) cur_ms_data->Y = 0;
|
||||||
|
if(cur_ms_data->Y > 720) cur_ms_data->Y = 720;
|
||||||
|
DCFlushRange(cur_ms_data,sizeof(cur_ms_data));
|
||||||
|
DCInvalidateRange(cur_ms_data,sizeof(cur_ms_data));
|
||||||
|
}else if(!isActive){
|
||||||
|
if(lastActive && extra_data[0] <=5){
|
||||||
|
//log_printf("click\n");
|
||||||
|
clickTouchScreen(buffer,cur_ms_data->X,cur_ms_data->Y);
|
||||||
|
}
|
||||||
|
extra_data[0] = 0;
|
||||||
|
}
|
||||||
|
if(extra_data[1] > 30 && extra_data[2] == 0){
|
||||||
|
//log_printf("drag started\n");
|
||||||
|
extra_data[2] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((isActive && isActiveDrag) || extra_data[2]){
|
||||||
|
clickTouchScreen(buffer,cur_ms_data->X,cur_ms_data->Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CONTROLLER_PATCHER_ERROR_NONE;
|
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::clickTouchScreen(VPADData * buffer, short X, short Y){
|
||||||
|
if(buffer == NULL) return CONTROLLER_PATCHER_ERROR_NULL_POINTER;
|
||||||
|
s32 x_mouse = 80 + ((int)(((X)*1.0f/1280.0)*3890.0f));
|
||||||
|
s32 y_mouse = 3910 - ((int)(((Y)*1.0f/720.0)*3760.0f));
|
||||||
|
buffer->tpdata.x = x_mouse;
|
||||||
|
buffer->tpdata.y = y_mouse;
|
||||||
|
buffer->tpdata.touched = 1;
|
||||||
|
buffer->tpdata.invalid = 0;
|
||||||
|
buffer->tpdata1.x = x_mouse;
|
||||||
|
buffer->tpdata1.y = y_mouse;
|
||||||
|
buffer->tpdata1.touched = 1;
|
||||||
|
buffer->tpdata1.invalid = 0;
|
||||||
|
buffer->tpdata2.x = x_mouse;
|
||||||
|
buffer->tpdata2.y = y_mouse;
|
||||||
|
buffer->tpdata2.touched = 1;
|
||||||
|
buffer->tpdata2.invalid = 0;
|
||||||
|
return CONTROLLER_PATCHER_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){
|
CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode(HID_Data * data){
|
||||||
u32 hidmask = data->slotdata.hidmask;
|
u32 hidmask = data->slotdata.hidmask;
|
||||||
|
|
||||||
if(hidmask & gHID_LIST_KEYBOARD){
|
if(hidmask & gHID_LIST_KEYBOARD){
|
||||||
u8 * cur_data = &data->data_union.controller.cur_hid_data[0];
|
u8 * cur_data = &data->controller.cur_hid_data[0];
|
||||||
u8 * last_data = &data->data_union.controller.last_hid_data[0];
|
u8 * last_data = &data->controller.last_hid_data[0];
|
||||||
if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){
|
if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){
|
||||||
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){
|
if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){
|
||||||
gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH;
|
gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH;
|
||||||
|
@ -210,6 +210,8 @@ class ControllerPatcherUtils{
|
|||||||
**/
|
**/
|
||||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR convertAnalogSticks(HID_Data * data,VPADData * buffer);
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR convertAnalogSticks(HID_Data * data,VPADData * buffer);
|
||||||
|
|
||||||
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR convertGyroAndAcc(HID_Data * data,VPADData * buffer);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
* Mouse functions
|
* Mouse functions
|
||||||
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||||
@ -224,6 +226,9 @@ class ControllerPatcherUtils{
|
|||||||
**/
|
**/
|
||||||
static CONTROLLER_PATCHER_RESULT_OR_ERROR setTouch(HID_Data * data,VPADData * buffer);
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR setTouch(HID_Data * data,VPADData * buffer);
|
||||||
|
|
||||||
|
static CONTROLLER_PATCHER_RESULT_OR_ERROR clickTouchScreen(VPADData * buffer, short X, short Y);
|
||||||
|
|
||||||
|
|
||||||
/** \brief Checks if the mouse mode needs to be changed. Sets it to the new mode if necessary.
|
/** \brief Checks if the mouse mode needs to be changed. Sets it to the new mode if necessary.
|
||||||
* Currently the incoming data needs to be from a keyboard.
|
* Currently the incoming data needs to be from a keyboard.
|
||||||
*
|
*
|
||||||
|
@ -167,7 +167,6 @@ const u8 HID_DS4_BUTTON_R3[] = { 0x06,HID_DS4_BUTTON_R3_VALUE};
|
|||||||
const u8 HID_DS4_BUTTON_SHARE[] = { 0x06,HID_DS4_BUTTON_SHARE_VALUE};
|
const u8 HID_DS4_BUTTON_SHARE[] = { 0x06,HID_DS4_BUTTON_SHARE_VALUE};
|
||||||
const u8 HID_DS4_BUTTON_OPTIONS[] = { 0x06,HID_DS4_BUTTON_OPTIONS_VALUE};
|
const u8 HID_DS4_BUTTON_OPTIONS[] = { 0x06,HID_DS4_BUTTON_OPTIONS_VALUE};
|
||||||
|
|
||||||
|
|
||||||
const u8 HID_DS4_BUTTON_DPAD_TYPE[] = { CONTRPDM_Hat,HID_DS4_BUTTON_DPAD_MASK_VALUE};
|
const u8 HID_DS4_BUTTON_DPAD_TYPE[] = { CONTRPDM_Hat,HID_DS4_BUTTON_DPAD_MASK_VALUE};
|
||||||
const u8 HID_DS4_BUTTON_DPAD_N[] = { 0x05,HID_DS4_BUTTON_DPAD_N_VALUE};
|
const u8 HID_DS4_BUTTON_DPAD_N[] = { 0x05,HID_DS4_BUTTON_DPAD_N_VALUE};
|
||||||
const u8 HID_DS4_BUTTON_DPAD_NE[] = { 0x05,HID_DS4_BUTTON_DPAD_NE_VALUE};
|
const u8 HID_DS4_BUTTON_DPAD_NE[] = { 0x05,HID_DS4_BUTTON_DPAD_NE_VALUE};
|
||||||
@ -182,6 +181,23 @@ const u8 HID_DS4_BUTTON_DPAD_NEUTRAL[] = { 0x05,HID_DS4_BUTTON_DPAD_NEUTRAL_VAL
|
|||||||
const u8 HID_DS4_BUTTON_GUIDE[] = { 0x07,HID_DS4_BUTTON_GUIDE_VALUE};
|
const u8 HID_DS4_BUTTON_GUIDE[] = { 0x07,HID_DS4_BUTTON_GUIDE_VALUE};
|
||||||
const u8 HID_DS4_BUTTON_T_PAD_CLICK[] = { 0x07,HID_DS4_BUTTON_T_PAD_CLICK_VALUE};
|
const u8 HID_DS4_BUTTON_T_PAD_CLICK[] = { 0x07,HID_DS4_BUTTON_T_PAD_CLICK_VALUE};
|
||||||
|
|
||||||
|
const u8 HID_DS4_ACC[ACC_CONF_ENUM_MAXVALUE] = { ACC_CONF_MAGIC_VALUE, //ACC_CONF_MAGIC_VERSION
|
||||||
|
0x13, //ACC_CONF_X_1BYTE,
|
||||||
|
0x14, //ACC_CONF_X_2BYTE,
|
||||||
|
0x15, //ACC_CONF_Y_1BYTE,
|
||||||
|
0x16, //ACC_CONF_Y_2BYTE,
|
||||||
|
0x17, //ACC_CONF_Z_1BYTE,
|
||||||
|
0x18};//ACC_CONF_Z_2BYTE,
|
||||||
|
|
||||||
|
const u8 HID_DS4_GYRO[GYRO_CONF_ENUM_MAXVALUE] = { GYRO_CONF_MAGIC_VALUE, //GYRO_CONF_MAGIC_VERSION
|
||||||
|
0x0D, //GYRO_CONF_X_1BYTE,
|
||||||
|
0x0E, //GYRO_CONF_X_2BYTE,
|
||||||
|
0x0F, //GYRO_CONF_Y_1BYTE,
|
||||||
|
0x10, //GYRO_CONF_Y_2BYTE,
|
||||||
|
0x11, //GYRO_CONF_Z_1BYTE,
|
||||||
|
0x12};//GYRO_CONF_Z_2BYTE,
|
||||||
|
|
||||||
|
|
||||||
const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION
|
const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE] = { STICK_CONF_MAGIC_VALUE, //STICK_CONF_MAGIC_VERSION
|
||||||
0x01, //STICK_CONF_BYTE,
|
0x01, //STICK_CONF_BYTE,
|
||||||
0x80, //STICK_CONF_DEFAULT,
|
0x80, //STICK_CONF_DEFAULT,
|
||||||
|
@ -133,6 +133,8 @@ extern const u8 HID_DS4_BUTTON_DPAD_NEUTRAL[];
|
|||||||
extern const u8 HID_DS4_BUTTON_GUIDE[];
|
extern const u8 HID_DS4_BUTTON_GUIDE[];
|
||||||
extern const u8 HID_DS4_BUTTON_T_PAD_CLICK[];
|
extern const u8 HID_DS4_BUTTON_T_PAD_CLICK[];
|
||||||
|
|
||||||
|
extern const u8 HID_DS4_ACC[ACC_CONF_ENUM_MAXVALUE];
|
||||||
|
extern const u8 HID_DS4_GYRO[GYRO_CONF_ENUM_MAXVALUE];
|
||||||
extern const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE];
|
extern const u8 HID_DS4_STICK_L_X[STICK_CONF_ENUM_MAXVALUE];
|
||||||
extern const u8 HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE];
|
extern const u8 HID_DS4_STICK_L_Y[STICK_CONF_ENUM_MAXVALUE];
|
||||||
extern const u8 HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE];
|
extern const u8 HID_DS4_STICK_R_X[STICK_CONF_ENUM_MAXVALUE];
|
||||||
|
Loading…
Reference in New Issue
Block a user