From fc1be268f350eb6824a3e17b719374d85d85169c Mon Sep 17 00:00:00 2001 From: brentru Date: Mon, 22 Jul 2019 11:35:07 -0400 Subject: [PATCH] fix joystick center position --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 72e20c3..c5946dd 100755 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -53,6 +53,8 @@ class CursorManager(object): self._cursor = cursor self._is_clicked = False self._init_hardware() + self._center_x = self._read_joystick_x(samples=10) + self._center_y = self._read_joystick_y(samples=10) def __enter__(self): return self @@ -151,13 +153,13 @@ class CursorManager(object): elif hasattr(board, 'JOYSTICK_X'): joy_x = self._read_joystick_x() joy_y = self._read_joystick_y() - if joy_x > 700: + if joy_x > self._center_x + 100: self._cursor.x += self._cursor.speed - elif joy_x < -700: + elif joy_x < self._center_x - 100: self._cursor.x -= self._cursor.speed - if joy_y > 700: + if joy_y > self._center_y + 100: self._cursor.y += self._cursor.speed - elif joy_y < -700: + elif joy_y < self._center_y - 100: self._cursor.y -= self._cursor.speed else: raise AttributeError('Board must have a D-Pad or Joystick for use with CursorManager!')