37 static int make_magnitude_modifier(
struct iforce*
iforce,
40 unsigned char data[3];
67 static int make_period_modifier(
struct iforce* iforce,
68 struct resource* mod_chunk,
int no_alloc,
71 unsigned char data[7];
105 static int make_envelope_modifier(
struct iforce* iforce,
106 struct resource* mod_chunk,
int no_alloc,
107 u16 attack_duration,
__s16 initial_level,
108 u16 fade_duration,
__s16 final_level)
110 unsigned char data[8];
112 attack_duration =
TIME_SCALE(attack_duration);
126 data[0] =
LO(mod_chunk->
start);
127 data[1] =
HI(mod_chunk->
start);
129 data[2] =
LO(attack_duration);
130 data[3] =
HI(attack_duration);
131 data[4] =
HI(initial_level);
133 data[5] =
LO(fade_duration);
134 data[6] =
HI(fade_duration);
135 data[7] =
HI(final_level);
146 static int make_condition_modifier(
struct iforce* iforce,
147 struct resource* mod_chunk,
int no_alloc,
150 unsigned char data[10];
163 data[0] =
LO(mod_chunk->
start);
164 data[1] =
HI(mod_chunk->
start);
166 data[2] = (100 * rk) >> 15;
167 data[3] = (100 * lk) >> 15;
169 center = (500 * center) >> 15;
170 data[4] =
LO(center);
171 data[5] =
HI(center);
173 db = (1000 * db) >> 16;
177 data[8] = (100 * rsat) >> 16;
178 data[9] = (100 * lsat) >> 16;
186 static unsigned char find_button(
struct iforce *iforce,
signed short button)
190 for (i = 1; iforce->
type->btn[
i] >= 0; i++)
191 if (iforce->
type->btn[i] == button)
200 static int need_condition_modifier(
struct iforce *iforce,
208 dev_warn(&iforce->
dev->dev,
"bad effect type in %s\n",
213 for (i = 0; i < 2; i++) {
214 ret |= old->
u.
condition[
i].right_saturation !=
new->u.condition[
i].right_saturation
215 || old->
u.
condition[
i].left_saturation !=
new->u.condition[
i].left_saturation
216 || old->
u.
condition[
i].right_coeff !=
new->u.condition[
i].right_coeff
217 || old->
u.
condition[
i].left_coeff !=
new->u.condition[
i].left_coeff
218 || old->
u.
condition[
i].deadband !=
new->u.condition[
i].deadband
219 || old->
u.
condition[
i].center !=
new->u.condition[
i].center;
228 static int need_magnitude_modifier(
struct iforce *iforce,
233 dev_warn(&iforce->
dev->dev,
"bad effect type in %s\n",
245 static int need_envelope_modifier(
struct iforce *iforce,
struct ff_effect *old,
248 switch (effect->
type) {
250 if (old->
u.
constant.envelope.attack_length != effect->
u.
constant.envelope.attack_length
258 if (old->
u.
periodic.envelope.attack_length != effect->
u.
periodic.envelope.attack_length
266 dev_warn(&iforce->
dev->dev,
"bad effect type in %s\n",
277 static int need_period_modifier(
struct iforce *iforce,
struct ff_effect *old,
281 dev_warn(&iforce->
dev->dev,
"bad effect type in %s\n",
285 return (old->
u.
periodic.period != new->u.periodic.period
286 || old->
u.
periodic.magnitude != new->u.periodic.magnitude
287 || old->
u.
periodic.offset != new->u.periodic.offset
288 || old->
u.
periodic.phase != new->u.periodic.phase);
298 || old->
trigger.button != new->trigger.button
299 || old->
trigger.interval != new->trigger.interval
300 || old->
replay.length != new->replay.length
301 || old->
replay.delay != new->replay.delay)
309 static int make_core(
struct iforce* iforce,
u16 id,
u16 mod_id1,
u16 mod_id2,
313 unsigned char data[14];
320 data[1] = effect_type;
321 data[2] =
LO(axes) | find_button(iforce, button);
323 data[3] =
LO(duration);
324 data[4] =
HI(duration);
326 data[5] =
HI(direction);
328 data[6] =
LO(interval);
329 data[7] =
HI(interval);
331 data[8] =
LO(mod_id1);
332 data[9] =
HI(mod_id1);
333 data[10] =
LO(mod_id2);
334 data[11] =
HI(mod_id2);
336 data[12] =
LO(delay);
337 data[13] =
HI(delay);
360 int core_id = effect->
id;
368 if (!old || need_period_modifier(iforce, old, effect)) {
369 param1_err = make_period_modifier(iforce, mod1_chunk,
378 if (!old || need_envelope_modifier(iforce, old, effect)) {
379 param2_err = make_envelope_modifier(iforce, mod2_chunk,
381 effect->
u.
periodic.envelope.attack_length,
382 effect->
u.
periodic.envelope.attack_level,
393 case FF_SINE: wave_code = 0x22;
break;
396 default: wave_code = 0x20;
break;
399 if (!old || need_core(old, effect)) {
400 core_err = make_core(iforce, effect->
id,
418 return core_err < 0 ? core_err : (param1_err && param2_err);
430 int core_id = effect->
id;
438 if (!old || need_magnitude_modifier(iforce, old, effect)) {
439 param1_err = make_magnitude_modifier(iforce, mod1_chunk,
447 if (!old || need_envelope_modifier(iforce, old, effect)) {
448 param2_err = make_envelope_modifier(iforce, mod2_chunk,
450 effect->
u.
constant.envelope.attack_length,
451 effect->
u.
constant.envelope.attack_level,
459 if (!old || need_core(old, effect)) {
460 core_err = make_core(iforce, effect->
id,
478 return core_err < 0 ? core_err : (param1_err && param2_err);
486 int core_id = effect->
id;
494 switch (effect->
type) {
500 if (!old || need_condition_modifier(iforce, old, effect)) {
501 param_err = make_condition_modifier(iforce, mod1_chunk,
513 param_err = make_condition_modifier(iforce, mod2_chunk,
527 if (!old || need_core(old, effect)) {
528 core_err = make_core(iforce, effect->
id,
542 return core_err < 0 ? core_err : param_err;