aboutsummaryrefslogtreecommitdiff
path: root/src/tmt300rs
diff options
context:
space:
mode:
authorMmAaXx500 <viktor.balogh45@gmail.com>2025-07-24 20:19:52 +0200
committerMmAaXx500 <viktor.balogh45@gmail.com>2025-07-24 22:31:59 +0200
commitd757f6183c650706b5e98d7c55ce7f4b33b5539d (patch)
tree11878268b76dbdb319dc51863959c6525f395290 /src/tmt300rs
parent49adf5c48ba2784d97384619a52e875daf4bc062 (diff)
downloadhid-tmff2-d757f6183c650706b5e98d7c55ce7f4b33b5539d.tar.gz
hid-tmff2-d757f6183c650706b5e98d7c55ce7f4b33b5539d.zip
refactor effect length calculation
- do the calculation in only one place - avoid losing 1 ms (if it ever matters)
Diffstat (limited to 'src/tmt300rs')
-rw-r--r--src/tmt300rs/hid-tmt300rs.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/tmt300rs/hid-tmt300rs.c b/src/tmt300rs/hid-tmt300rs.c
index f83e3af..993b438 100644
--- a/src/tmt300rs/hid-tmt300rs.c
+++ b/src/tmt300rs/hid-tmt300rs.c
@@ -335,6 +335,15 @@ static u8 condition_values[] = {
0xff, 0xfe, 0xff
};
+static uint16_t t300rs_calculate_length(uint16_t length)
+{
+ /* translate infinite effect length from Linux's 0 to the wheel's 0xffff */
+ if (length == 0)
+ return 0xffff;
+
+ return length;
+}
+
static int16_t t300rs_calculate_constant_level(int16_t level, uint16_t direction)
{
level = (level * fixp_sin16(direction * 360 / 0x10000)) / 0x7fff;
@@ -582,8 +591,8 @@ static int t300rs_update_constant(struct t300rs_device_entry *t300rs,
level = t300rs_calculate_constant_level(constant.level, effect.direction);
old_level = t300rs_calculate_constant_level(constant_old.level, old.direction);
- length = effect.replay.length - 1;
- old_length = old.replay.length - 1;
+ length = t300rs_calculate_length(effect.replay.length);
+ old_length = t300rs_calculate_length(old.replay.length);
if (!t300rs_is_envelope_changed(&constant.envelope, &constant_old.envelope)
&& level == old_level
@@ -637,8 +646,8 @@ static int t300rs_update_ramp(struct t300rs_device_entry *t300rs,
t300rs_calculate_ramp_parameters(&slope, &center, &invert, &effect);
t300rs_calculate_ramp_parameters(&old_slope, &old_center, &old_invert, &old);
- length = effect.replay.length - 1;
- old_length = old.replay.length - 1;
+ length = t300rs_calculate_length(effect.replay.length);
+ old_length = t300rs_calculate_length(old.replay.length);
if (!t300rs_is_envelope_changed(&ramp.envelope, &ramp_old.envelope)
&& slope == old_slope
@@ -713,8 +722,8 @@ static int t300rs_update_condition(struct t300rs_device_entry *t300rs,
left_sat = t300rs_calculate_saturation(cond.left_saturation, effect.type);
left_sat_old = t300rs_calculate_saturation(cond_old.left_saturation, old.type);
- duration = effect.replay.length - 1;
- duration_old = old.replay.length - 1;
+ duration = t300rs_calculate_length(effect.replay.length);
+ duration_old = t300rs_calculate_length(old.replay.length);
if (right_coeff == right_coeff_old
&& left_coeff == left_coeff_old
@@ -775,8 +784,8 @@ static int t300rs_update_periodic(struct t300rs_device_entry *t300rs,
t300rs_calculate_periodic_values(&old);
periodic_old = old.u.periodic;
- length = effect.replay.length - 1;
- old_length = old.replay.length - 1;
+ length = t300rs_calculate_length(effect.replay.length);
+ old_length = t300rs_calculate_length(old.replay.length);
if (!t300rs_is_envelope_changed(&periodic.envelope, &periodic_old.envelope)
&& periodic.magnitude == periodic_old.magnitude
@@ -827,7 +836,7 @@ static int t300rs_upload_constant(struct t300rs_device_entry *t300rs,
int ret;
level = t300rs_calculate_constant_level(constant.level, effect.direction);
- duration = effect.replay.length - 1;
+ duration = t300rs_calculate_length(effect.replay.length);
offset = effect.replay.delay;
@@ -869,7 +878,7 @@ static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs,
t300rs_calculate_ramp_parameters(&slope, &center, &invert, &effect);
- duration = effect.replay.length - 1;
+ duration = t300rs_calculate_length(effect.replay.length);
offset = effect.replay.delay;
t300rs_fill_header(&packet_ramp->header, effect.id, 0x6b);
@@ -926,7 +935,7 @@ static int t300rs_upload_condition(struct t300rs_device_entry *t300rs,
right_sat = t300rs_calculate_saturation(cond.right_saturation, effect.type);
left_sat = t300rs_calculate_saturation(cond.left_saturation, effect.type);
- duration = effect.replay.length - 1;
+ duration = t300rs_calculate_length(effect.replay.length);
offset = effect.replay.delay;
@@ -980,7 +989,7 @@ static int t300rs_upload_periodic(struct t300rs_device_entry *t300rs,
t300rs_calculate_periodic_values(&effect);
periodic = effect.u.periodic;
- duration = effect.replay.length;
+ duration = t300rs_calculate_length(effect.replay.length);
offset = effect.replay.delay;
magnitude = periodic.magnitude;
period = periodic.period;