Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Jan 2021 23:20:50 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 3b2175fdb62c - main - evdev: Implement fuzz.
Message-ID:  <202101072320.107NKox0063047@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b2175fdb62c7f872e78ce732952f2ac2ff99c8d

commit 3b2175fdb62c7f872e78ce732952f2ac2ff99c8d
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2020-11-30 21:10:04 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2021-01-07 23:18:44 +0000

    evdev: Implement fuzz.
    
    Fuzz is used to filter noise from the event stream.
    Upcoming gamepad drivers use it.
    
    Reviewed by:    hselasky (as part of D27993)
---
 sys/dev/evdev/evdev.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/sys/dev/evdev/evdev.c b/sys/dev/evdev/evdev.c
index e76abbc816d3..086ee36333dc 100644
--- a/sys/dev/evdev/evdev.c
+++ b/sys/dev/evdev/evdev.c
@@ -684,6 +684,7 @@ static void
 evdev_modify_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
     int32_t *value)
 {
+	int32_t fuzz, old_value, abs_change;
 
 	EVDEV_LOCK_ASSERT(evdev);
 
@@ -710,7 +711,24 @@ evdev_modify_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
 		break;
 
 	case EV_ABS:
-		/* TBD: implement fuzz */
+		fuzz = evdev->ev_absinfo[code].fuzz;
+		if (fuzz == 0 || code == ABS_MT_SLOT)
+			break;
+		else if (!ABS_IS_MT(code))
+			old_value = evdev->ev_absinfo[code].value;
+		else if (bit_test(evdev->ev_abs_flags, ABS_MT_SLOT))
+			old_value = evdev_get_mt_value(evdev,
+			    evdev_get_last_mt_slot(evdev), code);
+		else	/* Pass MT protocol type A events as is */
+			break;
+
+		abs_change = abs(*value - old_value);
+		if (abs_change < fuzz / 2)
+			*value = old_value;
+		else if (abs_change < fuzz)
+			*value = (old_value * 3 + *value) / 4;
+		else if (abs_change < fuzz * 2)
+			*value = (old_value + *value) / 2;
 		break;
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101072320.107NKox0063047>