From 2e7cf35aa7277181ce10ec0f26130e1f4db43e51 Mon Sep 17 00:00:00 2001 From: Mike Cronce Date: Thu, 16 Feb 2017 23:55:54 -0500 Subject: src/events.py: Added some additional math handling trackpad button touch and button click mode; what this does, in a nutshell, is change the deadzone from effectively being a square to effectively being a circle. The net effect is that diagonals work better. --- src/events.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/events.py b/src/events.py index ecfdb89..ddc4483 100644 --- a/src/events.py +++ b/src/events.py @@ -28,7 +28,7 @@ events """ from time import time -from math import sqrt +import math from enum import IntEnum @@ -297,7 +297,7 @@ class EventMapper(object): # FIXME: make haptic configurable if sci.buttons & touch == touch: - self._moved[pos] += sqrt((xm - xm_p)**2 + (ym - ym_p)**2) + self._moved[pos] += math.sqrt((xm - xm_p)**2 + (ym - ym_p)**2) if self._moved[pos] >= 4000: sc.addFeedback(pos, amplitude=100) self._moved[pos] %= 4000 @@ -339,22 +339,46 @@ class EventMapper(object): bmode, bev = self._pad_evts[pos][2] rmode, rev = self._pad_evts[pos][3] - if ym > dzone: # TOP + distance = math.hypot(xm, ym) + + # For whatever reason, the "extremes" on the pads (in + # radians), are approximately: + # up: 0.6pi + # left: -0.9pi + # down: -0.4pi + # right: 0.1pi + # Because of this, we subtract 0.1 from them to + # normalize. + angle = math.atan2(float(ym), float(xm)) - (0.1 * math.pi) + sin = math.sin(angle) + + # TODO: Figure out whether it's faster to calculate + # both sine and cosine here and have simple + # conditionals, or to only figure out one and have + # half the conditionals look like (e.g.) this: + # xm < 0 and sin <= 0.839 and sin >= 0.839 + cos = math.cos(angle) + + # top + if(sin >= 0.545): haptic |= _keypressed(tmode, tev) else: haptic |= _keyreleased(tmode, tev) - if xm < -dzone: # LEFT + # left + if(cos <= -0.545): haptic |= _keypressed(lmode, lev) else: haptic |= _keyreleased(lmode, lev) - if ym < -dzone: # BOTTOM + # bottom + if(sin <= -0.545): haptic |= _keypressed(bmode, bev) else: haptic |= _keyreleased(bmode, bev) - if xm > dzone: # RIGHT + # right + if(cos >= 0.545): haptic |= _keypressed(rmode, rev) else: haptic |= _keyreleased(rmode, rev) -- cgit v1.2.3 From 62f30cd366e660bed698eaa191f1dca8f1a056a8 Mon Sep 17 00:00:00 2001 From: Mike Cronce Date: Fri, 17 Feb 2017 10:04:11 -0500 Subject: src/events.py: Fixed sin/cos constant for angles --- src/events.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/events.py b/src/events.py index ddc4483..cfa9895 100644 --- a/src/events.py +++ b/src/events.py @@ -360,25 +360,25 @@ class EventMapper(object): cos = math.cos(angle) # top - if(sin >= 0.545): + if(sin >= 0.383): haptic |= _keypressed(tmode, tev) else: haptic |= _keyreleased(tmode, tev) # left - if(cos <= -0.545): + if(cos <= -0.383): haptic |= _keypressed(lmode, lev) else: haptic |= _keyreleased(lmode, lev) # bottom - if(sin <= -0.545): + if(sin <= -0.383): haptic |= _keypressed(bmode, bev) else: haptic |= _keyreleased(bmode, bev) # right - if(cos >= 0.545): + if(cos >= 0.383): haptic |= _keypressed(rmode, rev) else: haptic |= _keyreleased(rmode, rev) -- cgit v1.2.3 From a765fc842e3a2a47ad3143dcb652ca86454a9503 Mon Sep 17 00:00:00 2001 From: Mike Cronce Date: Fri, 17 Feb 2017 18:40:09 -0500 Subject: src/events.py: Whoops...gotta take deadzone into account --- src/events.py | 79 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/events.py b/src/events.py index cfa9895..37bf179 100644 --- a/src/events.py +++ b/src/events.py @@ -340,47 +340,52 @@ class EventMapper(object): rmode, rev = self._pad_evts[pos][3] distance = math.hypot(xm, ym) - - # For whatever reason, the "extremes" on the pads (in - # radians), are approximately: - # up: 0.6pi - # left: -0.9pi - # down: -0.4pi - # right: 0.1pi - # Because of this, we subtract 0.1 from them to - # normalize. - angle = math.atan2(float(ym), float(xm)) - (0.1 * math.pi) - sin = math.sin(angle) - - # TODO: Figure out whether it's faster to calculate - # both sine and cosine here and have simple - # conditionals, or to only figure out one and have - # half the conditionals look like (e.g.) this: - # xm < 0 and sin <= 0.839 and sin >= 0.839 - cos = math.cos(angle) - - # top - if(sin >= 0.383): - haptic |= _keypressed(tmode, tev) + if(distance >= dzone): + # For whatever reason, the "extremes" on the pads (in + # radians), are approximately: + # up: 0.6pi + # left: -0.9pi + # down: -0.4pi + # right: 0.1pi + # Because of this, we subtract 0.1 from them to + # normalize. + angle = math.atan2(float(ym), float(xm)) - (0.1 * math.pi) + sin = math.sin(angle) + + # TODO: Figure out whether it's faster to calculate + # both sine and cosine here and have simple + # conditionals, or to only figure out one and have + # half the conditionals look like (e.g.) this: + # xm < 0 and sin <= 0.839 and sin >= 0.839 + cos = math.cos(angle) + + # top + if(sin >= 0.383): + haptic |= _keypressed(tmode, tev) + else: + haptic |= _keyreleased(tmode, tev) + + # left + if(cos <= -0.383): + haptic |= _keypressed(lmode, lev) + else: + haptic |= _keyreleased(lmode, lev) + + # bottom + if(sin <= -0.383): + haptic |= _keypressed(bmode, bev) + else: + haptic |= _keyreleased(bmode, bev) + + # right + if(cos >= 0.383): + haptic |= _keypressed(rmode, rev) + else: + haptic |= _keyreleased(rmode, rev) else: haptic |= _keyreleased(tmode, tev) - - # left - if(cos <= -0.383): - haptic |= _keypressed(lmode, lev) - else: haptic |= _keyreleased(lmode, lev) - - # bottom - if(sin <= -0.383): - haptic |= _keypressed(bmode, bev) - else: haptic |= _keyreleased(bmode, bev) - - # right - if(cos >= 0.383): - haptic |= _keypressed(rmode, rev) - else: haptic |= _keyreleased(rmode, rev) elif len(self._pad_evts[pos]) == 2: -- cgit v1.2.3