diff options
author | Stany MARCEL <stanypub@gmail.com> | 2017-06-13 22:12:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-13 22:12:51 +0300 |
commit | a20b9582e36d4969c82f8de70611cc7a6e48c0c7 (patch) | |
tree | c8fa9fc23c81d7ce50d9e9faef73409042dfefbf | |
parent | 60499dc65b790436a331023529a086cdaf2744c7 (diff) | |
parent | a765fc842e3a2a47ad3143dcb652ca86454a9503 (diff) |
Merge pull request #56 from mcronce/trackpad-improvements
Trackpad improvements
-rw-r--r-- | src/events.py | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/events.py b/src/events.py index ecfdb89..37bf179 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,24 +339,53 @@ class EventMapper(object): bmode, bev = self._pad_evts[pos][2] rmode, rev = self._pad_evts[pos][3] - if ym > dzone: # TOP - haptic |= _keypressed(tmode, tev) + distance = math.hypot(xm, ym) + 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) - - if xm < -dzone: # LEFT - haptic |= _keypressed(lmode, lev) - else: haptic |= _keyreleased(lmode, lev) - - if ym < -dzone: # BOTTOM - haptic |= _keypressed(bmode, bev) - else: haptic |= _keyreleased(bmode, bev) - - if xm > dzone: # RIGHT - haptic |= _keypressed(rmode, rev) - else: haptic |= _keyreleased(rmode, rev) elif len(self._pad_evts[pos]) == 2: |