Skip to content

Commit

Permalink
[GPP/Cronus/Titan One] Do not exit when device is busy #385
Browse files Browse the repository at this point in the history
Conflicts:
	shared/gpp/pcprog.c
  • Loading branch information
Matlo committed Jul 2, 2016
1 parent f0013f8 commit 157b80e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/connectors/gpp_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int gpp_send(int id, e_controller_type type, int axis[AXIS_MAX])
}
}

if(!gpppcprog_output(id, output[id]))
if(gpppcprog_output(id, output[id]) < 0)
{
ret = -1;
}
Expand Down
30 changes: 21 additions & 9 deletions shared/gpp/pcprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static struct
{
int device;
char * path;
unsigned int pending;
ASYNC_READ_CALLBACK fp_read;
ASYNC_WRITE_CALLBACK fp_write;
ASYNC_CLOSE_CALLBACK fp_close;
Expand Down Expand Up @@ -166,10 +167,6 @@ int8_t gppcprog_connect(int id, const char * path)
{
gpp_devices[id].path = strdup(path);
}
else
{
fprintf(stderr, "failed to open %s\n", path);
}
}
else
{
Expand Down Expand Up @@ -234,6 +231,9 @@ void gppcprog_disconnect(int id)
//make sure the write is synchronous
gpp_devices[id].fp_write = NULL;

//unblock sending
gpp_devices[id].pending = 0;

// Leave Capture Mode
gpppcprog_send(id, GPPKG_LEAVE_CAPTURE, NULL, 0);

Expand Down Expand Up @@ -277,6 +277,10 @@ static int read_callback(int user, const void * buf, unsigned int count)

static int write_callback(int user, int transfered)
{
if (gpp_devices[user].pending > 0)
{
--gpp_devices[user].pending;
}
if(gpp_devices[user].fp_write)
{
return gpp_devices[user].fp_write(user, transfered);
Expand Down Expand Up @@ -305,6 +309,11 @@ int8_t gpppcprog_output(int id, int8_t output[GCAPI_INPUT_TOTAL])

int8_t gpppcprog_send(int id, uint8_t type, uint8_t * data, uint16_t length)
{
if (gpp_devices[id].pending > 0)
{
fprintf(stderr, "%s:%d %s: device is busy\n", __FILE__, __LINE__, __func__);
return 0;
}
s_gppReport report =
{
.reportId = 0x00,
Expand All @@ -319,7 +328,7 @@ int8_t gpppcprog_send(int id, uint8_t type, uint8_t * data, uint16_t length)
uint16_t i = 0;

do
{ // Data
{
if (length)
{
sndLen = (((i + sizeof(report.data)) < length) ? sizeof(report.data) : (uint16_t)(length - i));
Expand All @@ -328,15 +337,18 @@ int8_t gpppcprog_send(int id, uint8_t type, uint8_t * data, uint16_t length)
}
if(gpp_devices[id].fp_write) {
if (hidasync_write(gpp_devices[id].device, (unsigned char*)&report, sizeof(report)) == -1)
return (0);
{
return -1;
}
++gpp_devices[id].pending;
}
else {
if (hidasync_write_timeout(gpp_devices[id].device, (unsigned char*)&report, sizeof(report), 1) == -1)
return (0);
if (hidasync_write_timeout(gpp_devices[id].device, (unsigned char*)&report, sizeof(report), 1000) == -1)
return -1;
}
report.header.first = 0;
}
while (i < length);
return (1);
return 1;
}

0 comments on commit 157b80e

Please sign in to comment.