Skip to content

Commit

Permalink
Add debug traces for force feedback effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
matlo committed Oct 30, 2016
1 parent b3ee4f8 commit de55d94
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions core/haptic/ff_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,37 @@ int ff_conv_init(int device, unsigned short pid) {
return 0;
}

static void dump_event(const GE_Event * event) {

switch (event->type) {
case GE_JOYCONSTANTFORCE:
dprintf("< CONSTANT, level: %d\n", event->jconstant.level);
fflush(stdout);
break;
case GE_JOYSPRINGFORCE:
dprintf("< SPRING, saturation: %u %u, coefficient: %u %u, center: %d, deadband: %u\n",
event->jcondition.saturation.left, event->jcondition.saturation.right,
event->jcondition.coefficient.left, event->jcondition.coefficient.right,
event->jcondition.center, event->jcondition.deadband);
fflush(stdout);
break;
case GE_JOYDAMPERFORCE:
dprintf("< DAMPER, saturation: %u %u, coefficient: %u %u\n",
event->jcondition.saturation.left, event->jcondition.saturation.right,
event->jcondition.coefficient.left, event->jcondition.coefficient.right);
fflush(stdout);
break;
default:
dprintf("< UNKNOWN\n");
fflush(stdout);
break;
}
}

static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {

int ret = 0;

s_ff_lg_force * force = &ff_lg_device[device].slots[index].ff_lg_force;

switch (force->type) {
Expand All @@ -78,7 +107,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
if (ff_lg_device[device].slots[index].active) {
event->jconstant.level = u8_to_s16(FF_LG_CONSTANT_LEVEL(force, index));
}
return 1;
ret = 1;
break;
case FF_LG_FTYPE_VARIABLE:
event->type = GE_JOYCONSTANTFORCE;
if (ff_lg_device[device].slots[index].active) {
Expand All @@ -101,7 +131,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
}
}
}
return 1;
ret = 1;
break;
case FF_LG_FTYPE_SPRING:
event->type = GE_JOYSPRINGFORCE;
if (ff_lg_device[device].slots[index].active) {
Expand All @@ -114,7 +145,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
event->jcondition.center = u8_to_s16((FF_LG_SPRING_D1(force) + FF_LG_SPRING_D2(force)) / 2);
event->jcondition.deadband = u8_to_u16(FF_LG_SPRING_D2(force) - FF_LG_SPRING_D1(force));
}
return 1;
ret = 1;
break;
case FF_LG_FTYPE_DAMPER:
event->type = GE_JOYDAMPERFORCE;
if (ff_lg_device[device].slots[index].active) {
Expand All @@ -123,7 +155,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
event->jcondition.coefficient.right =
ff_lg_get_condition_coef(ff_lg_device[device].pid, 0, FF_LG_DAMPER_K2(force), FF_LG_DAMPER_S2(force));
}
return 1;
ret = 1;
break;
case FF_LG_FTYPE_HIGH_RESOLUTION_SPRING:
event->type = GE_JOYSPRINGFORCE;
if (ff_lg_device[device].slots[index].active) {
Expand All @@ -138,7 +171,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
event->jcondition.center = u16_to_s16((d1 + d2) / 2);
event->jcondition.deadband = d2 - d1;
}
return 1;
ret = 1;
break;
case FF_LG_FTYPE_HIGH_RESOLUTION_DAMPER:
event->type = GE_JOYDAMPERFORCE;
if (ff_lg_device[device].slots[index].active) {
Expand All @@ -149,7 +183,8 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
event->jcondition.coefficient.right =
ff_lg_get_condition_coef(ff_lg_device[device].pid, 1, FF_LG_HIGHRES_DAMPER_K2(force), FF_LG_HIGHRES_DAMPER_S2(force));
}
return 1;
ret = 1;
break;
default:
//TODO MLA: other force types
{
Expand All @@ -160,8 +195,14 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
warned[force->type] = 1;
}
}
return 0;
break;
}

if(gimx_params.debug && ret != 0) {
dump_event(event);
}

return ret;
}

int ff_conv(int device, const unsigned char data[FF_LG_OUTPUT_REPORT_SIZE], GE_Event events[FF_LG_FSLOTS_NB]) {
Expand Down

0 comments on commit de55d94

Please sign in to comment.