diff options
| author | MmAaXx500 <viktor.balogh45@gmail.com> | 2024-06-20 00:25:09 +0200 |
|---|---|---|
| committer | MmAaXx500 <viktor.balogh45@gmail.com> | 2024-06-20 01:16:49 +0200 |
| commit | 5d3ca03ab5ebdf40d78fe9e8c2551cf7af81bc8b (patch) | |
| tree | abb64fb6efcef7e619f9907f9119cd8893e74254 /src/tmt300rs | |
| parent | a6b104c76afc571a7b5a6ec180a468d66b426acb (diff) | |
| download | hid-tmff2-5d3ca03ab5ebdf40d78fe9e8c2551cf7af81bc8b.tar.gz hid-tmff2-5d3ca03ab5ebdf40d78fe9e8c2551cf7af81bc8b.zip | |
fix periodic effect offset calculation
Diffstat (limited to 'src/tmt300rs')
| -rw-r--r-- | src/tmt300rs/hid-tmt300rs.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/tmt300rs/hid-tmt300rs.c b/src/tmt300rs/hid-tmt300rs.c index 4360743..0d81655 100644 --- a/src/tmt300rs/hid-tmt300rs.c +++ b/src/tmt300rs/hid-tmt300rs.c @@ -347,6 +347,7 @@ static u8 damper_values[] = { static void t300rs_calculate_periodic_values(struct ff_effect *effect) { struct ff_periodic_effect *periodic = &effect->u.periodic; + int16_t headroom; effect->replay.length -= 1; @@ -362,6 +363,11 @@ static void t300rs_calculate_periodic_values(struct ff_effect *effect) /* the interval [0; 32677[ is used by the wheel for the [0; 360[ degree phase shift */ periodic->phase = periodic->phase * 32677 / 0x10000; + + headroom = 0x7FFF - periodic->magnitude; + /* magnitude + offset cannot be outside the valid magnitude range, */ + /* otherwise the wheel behaves incorrectly */ + periodic->offset = clamp(periodic->offset, -headroom, headroom); } int t300rs_send_buf(struct t300rs_device_entry *t300rs, u8 *send_buffer, size_t len) |
