Ajout manette en mode Sony DualShock4
This commit is contained in:
parent
c3295f047b
commit
e5b55e420d
58
hid_app.c
58
hid_app.c
@ -74,6 +74,7 @@ static void process_kbd_report(hid_keyboard_report_t const *report);
|
||||
static void process_mouse_report(hid_mouse_report_t const * report);
|
||||
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||
void process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||
void process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||
void affiche_gamepad_data(struct gamepad_data_t _gamepad_report);
|
||||
|
||||
// HID report from 8bitPro
|
||||
@ -112,12 +113,13 @@ typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t report_id;
|
||||
uint8_t x, y, z, rz; // joystick
|
||||
|
||||
uint hat_switch:4;
|
||||
uint b1:1;
|
||||
uint b2:1;
|
||||
uint b3:1;
|
||||
uint b4:1; // 8 bits
|
||||
uint b4:1;
|
||||
|
||||
// 8 bits
|
||||
uint b5:1;
|
||||
uint b6:1;
|
||||
uint b7:1;
|
||||
@ -126,16 +128,14 @@ typedef struct TU_ATTR_PACKED
|
||||
uint b10:1;
|
||||
uint b11:1;
|
||||
uint b12:1; // 16 bits
|
||||
uint b13:1;
|
||||
uint b14:1;
|
||||
|
||||
uint data_1:6;
|
||||
uint data_1:8;
|
||||
|
||||
uint gachette_gauche:8;
|
||||
uint gachette_droite:8;
|
||||
|
||||
|
||||
} _SonyDualShock_report_t ;
|
||||
} SonyDualShock4_report_t ;
|
||||
|
||||
|
||||
|
||||
@ -228,7 +228,10 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
||||
// Report - 2dc8:6002 8BitDo 8BitDo SN30 Pro+
|
||||
if(hid_info[instance].vid == 0x2dc8 && hid_info[instance].pid == 0x6002){
|
||||
process_8bitpro_report(dev_addr, instance, report, len);
|
||||
}else if(hid_info[instance].vid == 0x054c && hid_info[instance].pid == 0x054c){
|
||||
}else if(hid_info[instance].vid == 0x054c && hid_info[instance].pid == 0x05c4){
|
||||
process_SonyDualShock4_report(dev_addr, instance, report, len);
|
||||
}else{
|
||||
printf("Generic report\n");
|
||||
process_generic_report(dev_addr, instance, report, len);
|
||||
}
|
||||
break;
|
||||
@ -378,6 +381,39 @@ void process_8bitpro_report(uint8_t dev_addr, uint8_t instance, uint8_t const* r
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// 054c:05c4 Sony Corp. DualShock 4 [CUH-ZCT1x]
|
||||
//--------------------------------------------------------------------+
|
||||
void process_SonyDualShock4_report(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
|
||||
struct gamepad_data_t gamepad_data;
|
||||
SonyDualShock4_report_t gamepad_report;
|
||||
memcpy(&gamepad_report, report, sizeof(gamepad_report));
|
||||
|
||||
// Copie des données du rapport vers la structure standard
|
||||
gamepad_data.joystick_x_gauche = gamepad_report.x;
|
||||
gamepad_data.joystick_y_gauche = gamepad_report.y;
|
||||
gamepad_data.joystick_x_droit = gamepad_report.z;
|
||||
gamepad_data.joystick_y_droit = gamepad_report.rz;
|
||||
gamepad_data.bouton_Y = gamepad_report.b4;
|
||||
gamepad_data.bouton_A = gamepad_report.b3;
|
||||
gamepad_data.bouton_B = gamepad_report.b2;
|
||||
gamepad_data.bouton_X = gamepad_report.b1;
|
||||
gamepad_data.bouton_joystick_droit = gamepad_report.b11;
|
||||
gamepad_data.bouton_joystick_gauche = gamepad_report.b12;
|
||||
gamepad_data.bouton_Select = gamepad_report.b10;
|
||||
gamepad_data.bouton_Start = gamepad_report.b9;
|
||||
gamepad_data.bouton_R2 = gamepad_report.b8;
|
||||
gamepad_data.bouton_L2 = gamepad_report.b7;
|
||||
gamepad_data.bouton_R = gamepad_report.b6;
|
||||
gamepad_data.bouton_L = gamepad_report.b5;
|
||||
gamepad_data.dpad = gamepad_report.hat_switch;
|
||||
gamepad_data.gachette_droite = gamepad_report.gachette_droite;
|
||||
gamepad_data.gachette_gauche = gamepad_report.gachette_gauche;
|
||||
|
||||
affiche_gamepad_data(gamepad_data);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Generic Report
|
||||
//--------------------------------------------------------------------+
|
||||
@ -389,14 +425,14 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
|
||||
tuh_hid_report_info_t* rpt_info_arr = hid_info[instance].report_info;
|
||||
tuh_hid_report_info_t* rpt_info = NULL;
|
||||
|
||||
printf("VID, PID:%x:%x\n", hid_info[instance].vid, hid_info[instance].pid);
|
||||
|
||||
// Supposons que ce soit notre manette !
|
||||
//_SonyDualShock_report_t _gamepad_report;
|
||||
_8bitpro_report_t _gamepad_report;
|
||||
memcpy(&_gamepad_report, report, sizeof(_gamepad_report));
|
||||
|
||||
|
||||
printf(">j1:%d\n", _gamepad_report.x);
|
||||
/*printf(">j1:%d\n", _gamepad_report.x);
|
||||
printf(">j2:%d\n", _gamepad_report.y);
|
||||
printf(">j3:%d\n", _gamepad_report.z);
|
||||
printf(">j4:%d\n", _gamepad_report.rz);
|
||||
@ -421,10 +457,10 @@ static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t c
|
||||
//printf(">data1:%d\n", _gamepad_report.data_1);
|
||||
|
||||
printf(">g1:%d\n", _gamepad_report.gachette_droite);
|
||||
printf(">g2:%d\n", _gamepad_report.gachette_gauche);
|
||||
printf(">g2:%d\n", _gamepad_report.gachette_gauche);*/
|
||||
|
||||
|
||||
printf("HID Report brut\n");
|
||||
//printf("HID Report brut\n");
|
||||
for(int i=0; i< len; i++){
|
||||
printf("0x%X ", report[i]);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user