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 */
staticunsignedchar find_button(struct iforce *iforce, signedshort button)
{ int i;
for (i = 1; iforce->type->btn[i] >= 0; i++) if (iforce->type->btn[i] == button) return i + 1; return 0;
}
/* * Analyse the changes in an effect, and tell if we need to send an condition * parameter packet
*/ staticint need_condition_modifier(struct iforce *iforce, struct ff_effect *old, struct ff_effect *new)
{ int ret = 0; int i;
if (new->type != FF_SPRING && new->type != FF_FRICTION) {
dev_warn(&iforce->dev->dev, "bad effect type in %s\n",
__func__); return 0;
}
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
|| old->u.condition[i].left_coeff != new->u.condition[i].left_coeff
|| old->u.condition[i].deadband != new->u.condition[i].deadband
|| old->u.condition[i].center != new->u.condition[i].center;
} return ret;
}
/* * Analyse the changes in an effect, and tell if we need to send a magnitude * parameter packet
*/ staticint need_magnitude_modifier(struct iforce *iforce, struct ff_effect *old, struct ff_effect *effect)
{ if (effect->type != FF_CONSTANT) {
dev_warn(&iforce->dev->dev, "bad effect type in %s\n",
__func__); return 0;
}
default:
dev_warn(&iforce->dev->dev, "bad effect type in %s\n",
__func__);
}
return 0;
}
/* * Analyse the changes in an effect, and tell if we need to send a periodic * parameter effect
*/ staticint need_period_modifier(struct iforce *iforce, struct ff_effect *old, struct ff_effect *new)
{ if (new->type != FF_PERIODIC) {
dev_warn(&iforce->dev->dev, "bad effect type in %s\n",
__func__); 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
|| old->u.periodic.phase != new->u.periodic.phase);
}
/* * Analyse the changes in an effect, and tell if we need to send an effect * packet
*/ staticint need_core(struct ff_effect *old, struct ff_effect *new)
{ 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 1;
return 0;
} /* * Send the part common to all effects to the device
*/ staticint make_core(struct iforce* iforce, u16 id, u16 mod_id1, u16 mod_id2,
u8 effect_type, u8 axes, u16 duration, u16 delay, u16 button,
u16 interval, u16 direction)
{ unsignedchar data[14];
/* If needed, restart effect */ if (test_bit(FF_CORE_SHOULD_PLAY, iforce->core_effects[id].flags)) { /* BUG: perhaps we should replay n times, instead of 1. But we do not know n */
iforce_control_playback(iforce, id, 1);
}
return 0;
}
/* * Upload a periodic effect to the device * See also iforce_upload_constant.
*/ int iforce_upload_periodic(struct iforce *iforce, struct ff_effect *effect, struct ff_effect *old)
{
u8 wave_code; int core_id = effect->id; struct iforce_core_effect* core_effect = iforce->core_effects + core_id; struct resource* mod1_chunk = &(iforce->core_effects[core_id].mod1_chunk); struct resource* mod2_chunk = &(iforce->core_effects[core_id].mod2_chunk); int param1_err = 1; int param2_err = 1; int core_err = 0;
if (!old || need_period_modifier(iforce, old, effect)) {
param1_err = make_period_modifier(iforce, mod1_chunk,
old != NULL,
effect->u.periodic.magnitude, effect->u.periodic.offset,
effect->u.periodic.period, effect->u.periodic.phase); if (param1_err) return param1_err;
set_bit(FF_MOD1_IS_USED, core_effect->flags);
}
if (!old || need_envelope_modifier(iforce, old, effect)) {
param2_err = make_envelope_modifier(iforce, mod2_chunk,
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;
set_bit(FF_MOD2_IS_USED, core_effect->flags);
}
switch (effect->u.periodic.waveform) { case FF_SQUARE: wave_code = 0x20; break; case FF_TRIANGLE: wave_code = 0x21; break; case FF_SINE: wave_code = 0x22; break; case FF_SAW_UP: wave_code = 0x23; break; case FF_SAW_DOWN: wave_code = 0x24; break; default: wave_code = 0x20; break;
}
/* If one of the parameter creation failed, we already returned an * error code. * If the core creation failed, we return its error code. * Else: if one parameter at least was created, we return 0 * else we return 1;
*/ return core_err < 0 ? core_err : (param1_err && param2_err);
}
/* * Upload a constant force effect * Return value: * <0 Error code * 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, struct ff_effect *old)
{ int core_id = effect->id; struct iforce_core_effect* core_effect = iforce->core_effects + core_id; struct resource* mod1_chunk = &(iforce->core_effects[core_id].mod1_chunk); struct resource* mod2_chunk = &(iforce->core_effects[core_id].mod2_chunk); int param1_err = 1; int param2_err = 1; int core_err = 0;
if (!old || need_magnitude_modifier(iforce, old, effect)) {
param1_err = make_magnitude_modifier(iforce, mod1_chunk,
old != NULL,
effect->u.constant.level); if (param1_err) return param1_err;
set_bit(FF_MOD1_IS_USED, core_effect->flags);
}
if (!old || need_envelope_modifier(iforce, old, effect)) {
param2_err = make_envelope_modifier(iforce, mod2_chunk,
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;
set_bit(FF_MOD2_IS_USED, core_effect->flags);
}
/* If one of the parameter creation failed, we already returned an * error code. * If the core creation failed, we return its error code. * Else: if one parameter at least was created, we return 0 * else we return 1;
*/ return core_err < 0 ? core_err : (param1_err && param2_err);
}
/* * Upload an condition effect. Those are for example friction, inertia, springs...
*/ 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; struct resource* mod1_chunk = &(core_effect->mod1_chunk); struct resource* mod2_chunk = &(core_effect->mod2_chunk);
u8 type; int param_err = 1; int core_err = 0;
switch (effect->type) { case FF_SPRING: type = 0x40; break; case FF_DAMPER: type = 0x41; break; default: return -1;
}
if (!old || need_condition_modifier(iforce, old, effect)) {
param_err = make_condition_modifier(iforce, mod1_chunk,
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;
set_bit(FF_MOD1_IS_USED, core_effect->flags);
param_err = make_condition_modifier(iforce, mod2_chunk,
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;
set_bit(FF_MOD2_IS_USED, core_effect->flags);
/* If the parameter creation failed, we already returned an * error code. * If the core creation failed, we return its error code. * Else: if a parameter was created, we return 0 * else we return 1;
*/ return core_err < 0 ? core_err : param_err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.