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