Skip to content

Commit

Permalink
Input: iforce - switch to the new FF interface
Browse files Browse the repository at this point in the history
Signed-off-by: Anssi Hannula <anssi.hannula@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
Anssi Hannula authored and Dmitry Torokhov committed Jul 19, 2006
1 parent 7d928a2 commit f6a01c8
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 238 deletions.
118 changes: 55 additions & 63 deletions drivers/input/joystick/iforce/iforce-ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ static int make_condition_modifier(struct iforce* iforce,
data[0] = LO(mod_chunk->start);
data[1] = HI(mod_chunk->start);

data[2] = (100*rk)>>15; /* Dangerous: the sign is extended by gcc on plateforms providing an arith shift */
data[3] = (100*lk)>>15; /* This code is incorrect on cpus lacking arith shift */
data[2] = (100 * rk) >> 15; /* Dangerous: the sign is extended by gcc on plateforms providing an arith shift */
data[3] = (100 * lk) >> 15; /* This code is incorrect on cpus lacking arith shift */

center = (500*center)>>15;
center = (500 * center) >> 15;
data[4] = LO(center);
data[5] = HI(center);

db = (1000*db)>>16;
db = (1000 * db) >> 16;
data[6] = LO(db);
data[7] = HI(db);

data[8] = (100*rsat)>>16;
data[9] = (100*lsat)>>16;
data[8] = (100 * rsat) >> 16;
data[9] = (100 * lsat) >> 16;

iforce_send_packet(iforce, FF_CMD_CONDITION, data);
iforce_dump_packet("condition", FF_CMD_CONDITION, data);
Expand All @@ -188,6 +188,7 @@ static int make_condition_modifier(struct iforce* iforce,
static unsigned char find_button(struct iforce *iforce, signed short button)
{
int i;

for (i = 1; iforce->type->btn[i] >= 0; i++)
if (iforce->type->btn[i] == button)
return i + 1;
Expand All @@ -198,19 +199,17 @@ static unsigned char find_button(struct iforce *iforce, signed short button)
* Analyse the changes in an effect, and tell if we need to send an condition
* parameter packet
*/
static int need_condition_modifier(struct iforce* iforce, struct ff_effect* new)
static int need_condition_modifier(struct ff_effect *old, struct ff_effect *new)
{
int id = new->id;
struct ff_effect* old = &iforce->core_effects[id].effect;
int ret=0;
int ret = 0;
int i;

if (new->type != FF_SPRING && new->type != FF_FRICTION) {
printk(KERN_WARNING "iforce.c: bad effect type in need_condition_modifier\n");
return FALSE;
return 0;
}

for(i=0; i<2; i++) {
for (i = 0; i < 2; i++) {
ret |= old->u.condition[i].right_saturation != new->u.condition[i].right_saturation
|| old->u.condition[i].left_saturation != new->u.condition[i].left_saturation
|| old->u.condition[i].right_coeff != new->u.condition[i].right_coeff
Expand All @@ -225,66 +224,56 @@ static int need_condition_modifier(struct iforce* iforce, struct ff_effect* new)
* Analyse the changes in an effect, and tell if we need to send a magnitude
* parameter packet
*/
static int need_magnitude_modifier(struct iforce* iforce, struct ff_effect* effect)
static int need_magnitude_modifier(struct ff_effect *old, struct ff_effect *effect)
{
int id = effect->id;
struct ff_effect* old = &iforce->core_effects[id].effect;

if (effect->type != FF_CONSTANT) {
printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n");
return FALSE;
return 0;
}

return (old->u.constant.level != effect->u.constant.level);
return old->u.constant.level != effect->u.constant.level;
}

/*
* Analyse the changes in an effect, and tell if we need to send an envelope
* parameter packet
*/
static int need_envelope_modifier(struct iforce* iforce, struct ff_effect* effect)
static int need_envelope_modifier(struct ff_effect *old, struct ff_effect *effect)
{
int id = effect->id;
struct ff_effect* old = &iforce->core_effects[id].effect;

switch (effect->type) {
case FF_CONSTANT:
if (old->u.constant.envelope.attack_length != effect->u.constant.envelope.attack_length
|| old->u.constant.envelope.attack_level != effect->u.constant.envelope.attack_level
|| old->u.constant.envelope.fade_length != effect->u.constant.envelope.fade_length
|| old->u.constant.envelope.fade_level != effect->u.constant.envelope.fade_level)
return TRUE;
return 1;
break;

case FF_PERIODIC:
if (old->u.periodic.envelope.attack_length != effect->u.periodic.envelope.attack_length
|| old->u.periodic.envelope.attack_level != effect->u.periodic.envelope.attack_level
|| old->u.periodic.envelope.fade_length != effect->u.periodic.envelope.fade_length
|| old->u.periodic.envelope.fade_level != effect->u.periodic.envelope.fade_level)
return TRUE;
return 1;
break;

default:
printk(KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n");
}

return FALSE;
return 0;
}

/*
* Analyse the changes in an effect, and tell if we need to send a periodic
* parameter effect
*/
static int need_period_modifier(struct iforce* iforce, struct ff_effect* new)
static int need_period_modifier(struct ff_effect *old, struct ff_effect *new)
{
int id = new->id;
struct ff_effect* old = &iforce->core_effects[id].effect;

if (new->type != FF_PERIODIC) {
printk(KERN_WARNING "iforce.c: bad effect type in need_periodic_modifier\n");
return FALSE;
printk(KERN_WARNING "iforce.c: bad effect type in need_period_modifier\n");
return 0;
}

return (old->u.periodic.period != new->u.periodic.period
|| old->u.periodic.magnitude != new->u.periodic.magnitude
|| old->u.periodic.offset != new->u.periodic.offset
Expand All @@ -295,19 +284,16 @@ static int need_period_modifier(struct iforce* iforce, struct ff_effect* new)
* Analyse the changes in an effect, and tell if we need to send an effect
* packet
*/
static int need_core(struct iforce* iforce, struct ff_effect* new)
static int need_core(struct ff_effect *old, struct ff_effect *new)
{
int id = new->id;
struct ff_effect* old = &iforce->core_effects[id].effect;

if (old->direction != new->direction
|| old->trigger.button != new->trigger.button
|| old->trigger.interval != new->trigger.interval
|| old->replay.length != new->replay.length
|| old->replay.delay != new->replay.delay)
return TRUE;
return 1;

return FALSE;
return 0;
}
/*
* Send the part common to all effects to the device
Expand Down Expand Up @@ -360,7 +346,7 @@ static int make_core(struct iforce* iforce, u16 id, u16 mod_id1, u16 mod_id2,
* Upload a periodic effect to the device
* See also iforce_upload_constant.
*/
int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int is_update)
int iforce_upload_periodic(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
{
u8 wave_code;
int core_id = effect->id;
Expand All @@ -371,23 +357,25 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
int param2_err = 1;
int core_err = 0;

if (!is_update || need_period_modifier(iforce, effect)) {
if (!old || need_period_modifier(old, effect)) {
param1_err = make_period_modifier(iforce, mod1_chunk,
is_update,
old != NULL,
effect->u.periodic.magnitude, effect->u.periodic.offset,
effect->u.periodic.period, effect->u.periodic.phase);
if (param1_err) return param1_err;
if (param1_err)
return param1_err;
set_bit(FF_MOD1_IS_USED, core_effect->flags);
}

if (!is_update || need_envelope_modifier(iforce, effect)) {
if (!old || need_envelope_modifier(old, effect)) {
param2_err = make_envelope_modifier(iforce, mod2_chunk,
is_update,
old !=NULL,
effect->u.periodic.envelope.attack_length,
effect->u.periodic.envelope.attack_level,
effect->u.periodic.envelope.fade_length,
effect->u.periodic.envelope.fade_level);
if (param2_err) return param2_err;
if (param2_err)
return param2_err;
set_bit(FF_MOD2_IS_USED, core_effect->flags);
}

Expand All @@ -400,7 +388,7 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
default: wave_code = 0x20; break;
}

if (!is_update || need_core(iforce, effect)) {
if (!old || need_core(old, effect)) {
core_err = make_core(iforce, effect->id,
mod1_chunk->start,
mod2_chunk->start,
Expand Down Expand Up @@ -429,7 +417,7 @@ int iforce_upload_periodic(struct iforce* iforce, struct ff_effect* effect, int
* 0 Ok, effect created or updated
* 1 effect did not change since last upload, and no packet was therefore sent
*/
int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int is_update)
int iforce_upload_constant(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
{
int core_id = effect->id;
struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
Expand All @@ -439,26 +427,28 @@ int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int
int param2_err = 1;
int core_err = 0;

if (!is_update || need_magnitude_modifier(iforce, effect)) {
if (!old || need_magnitude_modifier(old, effect)) {
param1_err = make_magnitude_modifier(iforce, mod1_chunk,
is_update,
old != NULL,
effect->u.constant.level);
if (param1_err) return param1_err;
if (param1_err)
return param1_err;
set_bit(FF_MOD1_IS_USED, core_effect->flags);
}

if (!is_update || need_envelope_modifier(iforce, effect)) {
if (!old || need_envelope_modifier(old, effect)) {
param2_err = make_envelope_modifier(iforce, mod2_chunk,
is_update,
old != NULL,
effect->u.constant.envelope.attack_length,
effect->u.constant.envelope.attack_level,
effect->u.constant.envelope.fade_length,
effect->u.constant.envelope.fade_level);
if (param2_err) return param2_err;
if (param2_err)
return param2_err;
set_bit(FF_MOD2_IS_USED, core_effect->flags);
}

if (!is_update || need_core(iforce, effect)) {
if (!old || need_core(old, effect)) {
core_err = make_core(iforce, effect->id,
mod1_chunk->start,
mod2_chunk->start,
Expand All @@ -483,7 +473,7 @@ int iforce_upload_constant(struct iforce* iforce, struct ff_effect* effect, int
/*
* Upload an condition effect. Those are for example friction, inertia, springs...
*/
int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, int is_update)
int iforce_upload_condition(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
{
int core_id = effect->id;
struct iforce_core_effect* core_effect = iforce->core_effects + core_id;
Expand All @@ -494,37 +484,39 @@ int iforce_upload_condition(struct iforce* iforce, struct ff_effect* effect, int
int core_err = 0;

switch (effect->type) {
case FF_SPRING: type = 0x40; break;
case FF_DAMPER: type = 0x41; break;
case FF_SPRING: type = 0x40; break;
case FF_DAMPER: type = 0x41; break;
default: return -1;
}

if (!is_update || need_condition_modifier(iforce, effect)) {
if (!old || need_condition_modifier(old, effect)) {
param_err = make_condition_modifier(iforce, mod1_chunk,
is_update,
old != NULL,
effect->u.condition[0].right_saturation,
effect->u.condition[0].left_saturation,
effect->u.condition[0].right_coeff,
effect->u.condition[0].left_coeff,
effect->u.condition[0].deadband,
effect->u.condition[0].center);
if (param_err) return param_err;
if (param_err)
return param_err;
set_bit(FF_MOD1_IS_USED, core_effect->flags);

param_err = make_condition_modifier(iforce, mod2_chunk,
is_update,
old != NULL,
effect->u.condition[1].right_saturation,
effect->u.condition[1].left_saturation,
effect->u.condition[1].right_coeff,
effect->u.condition[1].left_coeff,
effect->u.condition[1].deadband,
effect->u.condition[1].center);
if (param_err) return param_err;
if (param_err)
return param_err;
set_bit(FF_MOD2_IS_USED, core_effect->flags);

}

if (!is_update || need_core(iforce, effect)) {
if (!old || need_core(old, effect)) {
core_err = make_core(iforce, effect->id,
mod1_chunk->start, mod2_chunk->start,
type, 0xc0,
Expand Down
Loading

0 comments on commit f6a01c8

Please sign in to comment.