Skip to content

Commit

Permalink
gimx-launcher: show causes for common errors #478
Browse files Browse the repository at this point in the history
  • Loading branch information
matlo committed Sep 23, 2017
1 parent df551ac commit bab65bb
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 48 deletions.
78 changes: 57 additions & 21 deletions core/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,9 @@ static int adapter_send_reset(int device)
return 0;
}

int adapter_detect()
e_gimx_status adapter_detect()
{
int ret = 0;
e_gimx_status ret = E_GIMX_STATUS_SUCCESS;
int i;
s_adapter* adapter;

Expand All @@ -692,7 +692,7 @@ int adapter_detect()
if (rtype < 0)
{
fprintf(stderr, _("No GPP detected.\n"));
ret = -1;
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}
else if(rtype < C_TYPE_MAX)
{
Expand All @@ -702,7 +702,7 @@ int adapter_detect()
else
{
fprintf(stderr, _("Unknown GPP controller type.\n"));
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
}
else if(adapter->atype == E_ADAPTER_TYPE_DIY_USB)
Expand All @@ -712,8 +712,7 @@ int adapter_detect()
adapter->serialdevice = gserial_open(adapter->portname, BAUDRATE);
if(adapter->serialdevice < 0)
{
fprintf(stderr, _("Check the wiring (maybe you swapped Rx and Tx?).\n"));
ret = -1;
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}
else
{
Expand All @@ -735,15 +734,15 @@ int adapter_detect()
else if(adapter->ctype != (e_controller_type) rtype)
{
fprintf(stderr, _("Wrong controller type.\n"));
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}

int status = adapter_send_short_command(i, BYTE_STATUS);

if(status < 0)
{
fprintf(stderr, _("Can't get adapter status.\n"));
ret = -1;
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}

if(ret != -1)
Expand All @@ -759,7 +758,7 @@ int adapter_detect()
if(adapter_send_reset(i) < 0)
{
fprintf(stderr, _("Can't reset the adapter.\n"));
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
else
{
Expand All @@ -780,7 +779,7 @@ int adapter_detect()
if(adapter_send_reset(i) < 0)
{
fprintf(stderr, _("Can't reset the adapter.\n"));
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
else
{
Expand All @@ -800,7 +799,7 @@ int adapter_detect()
}
}

if(ret != -1)
if(ret == E_GIMX_STATUS_SUCCESS)
{
int usb_res = usb_init(i, adapter->ctype);
if(usb_res < 0)
Expand All @@ -810,12 +809,28 @@ int adapter_detect()
|| status != BYTE_STATUS_SPOOFED)
{
fprintf(stderr, _("No controller was found on USB buses.\n"));
ret = -1;
switch(adapter->ctype)
{
case C_TYPE_360_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_X360;
break;
case C_TYPE_DS4:
case C_TYPE_G29_PS4:
case C_TYPE_T300RS_PS4:
ret = E_GIMX_STATUS_AUTH_MISSING_PS4;
break;
case C_TYPE_XONE_PAD:
ret = E_GIMX_STATUS_AUTH_MISSING_XONE;
break;
default:
ret = E_GIMX_STATUS_GENERIC_ERROR;
break;
}
}
}
}

if(ret != -1)
if(ret == E_GIMX_STATUS_SUCCESS)
{
controller_init_report(adapter->ctype, &adapter->report[0].value);

Expand All @@ -825,10 +840,14 @@ int adapter_detect()
}
}
}
else
{
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}
}
if(adapter->ctype == C_TYPE_NONE)
if(adapter->ctype == C_TYPE_NONE && ret == E_GIMX_STATUS_SUCCESS)
{
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
}
}
Expand All @@ -841,7 +860,7 @@ int adapter_detect()
{
struct in_addr addr = { .s_addr = adapter->dst_ip };
fprintf(stderr, _("Can't connect to: %s:%d.\n"), inet_ntoa(addr), adapter->dst_port);
ret = -1;
ret = E_GIMX_STATUS_ADAPTER_NOT_DETECTED;
}
else
{
Expand All @@ -856,7 +875,7 @@ int adapter_detect()
{
if(btds4_init(i, adapter->dongle_index, adapter->bdaddr_dst) < 0)
{
ret = -1;
ret = E_GIMX_STATUS_GENERIC_ERROR;
}
controller_init_report(C_TYPE_DS4, &adapter->report[0].value);
}
Expand Down Expand Up @@ -999,10 +1018,10 @@ int adapter_start()
fprintf(stderr, _("Can't start the serial asynchronous processing.\n"));
ret = -1;
}
const char * button = controller_get_activation_button(adapter->ctype);
if (button != NULL)
adapter->activation_button.index = controller_get_activation_button(adapter->ctype);
if (adapter->activation_button.index != 0)
{
printf(_("Press the %s button to activate the controller.\n"), button);
printf(_("Press the %s button to activate the controller.\n"), controller_get_axis_name(adapter->ctype, adapter->activation_button.index));
}
}
}
Expand Down Expand Up @@ -1098,6 +1117,14 @@ int adapter_send()
{
if(adapter->serialdevice >= 0)
{
if (adapter->activation_button.index != 0)
{
if (adapter->axis[adapter->activation_button.index] != 0)
{
adapter->activation_button.pressed = 1;
}
}

unsigned int index = controller_build_report(adapter->ctype, adapter->axis, adapter->report);

s_report_packet* report = adapter->report+index;
Expand Down Expand Up @@ -1205,8 +1232,9 @@ int adapter_send()
return ret;
}

void adapter_clean()
e_gimx_status adapter_clean()
{
e_gimx_status status = E_GIMX_STATUS_SUCCESS;
int i;
s_adapter* adapter;
for(i=0; i<MAX_CONTROLLERS; ++i)
Expand Down Expand Up @@ -1240,6 +1268,13 @@ void adapter_clean()
{
if(adapter->serialdevice >= 0)
{
if (adapter->activation_button.index != 0)
{
if (adapter->activation_button.pressed == 0)
{
status = E_GIMX_STATUS_NO_ACTIVATION;
}
}
switch(adapter->ctype)
{
case C_TYPE_360_PAD:
Expand All @@ -1264,6 +1299,7 @@ void adapter_clean()
gpp_disconnect(i);
}
}
return status;
}

int adapter_is_usb_auth_required(int adapter)
Expand Down
Loading

0 comments on commit bab65bb

Please sign in to comment.