Skip to content

Commit 9c3ecdf

Browse files
author
brentru
committed
remove joyxctr, joyctr
1 parent d81ba2d commit 9c3ecdf

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

adafruit_cursorcontrol/cursorcontrol_cursormanager.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
# PyBadge & PyGamer
4242
PYBADGE_BUTTON_A = const(2)
4343

44-
JOY_X_CTR = 32767.5
45-
JOY_Y_CTR = 32767.5
46-
47-
4844
class CursorManager(object):
4945
"""Simple interaction user interface interaction for Adafruit_CursorControl.
5046
@@ -55,8 +51,8 @@ def __init__(self, cursor):
5551
self._cursor = cursor
5652
self._is_clicked = False
5753
self._init_hardware()
58-
self._center_x = self._read_joystick_x(samples=10)
59-
self._center_y = self._read_joystick_y(samples=10)
54+
self._center_x = self._joystick_x.value
55+
self._center_y = self._joystick_y.value
6056

6157
def __enter__(self):
6258
return self
@@ -129,7 +125,6 @@ def _read_joystick_x(self, samples=3):
129125
for sample in range(0, samples):
130126
reading += self._joystick_x.value
131127
reading /= samples
132-
reading -= JOY_X_CTR
133128
return reading
134129

135130
def _read_joystick_y(self, samples=3):
@@ -142,7 +137,6 @@ def _read_joystick_y(self, samples=3):
142137
for sample in range(0, samples):
143138
reading += self._joystick_y.value
144139
reading /= samples
145-
reading -= JOY_Y_CTR
146140
return reading
147141

148142
def _check_cursor_movement(self, pressed=None):
@@ -162,13 +156,13 @@ def _check_cursor_movement(self, pressed=None):
162156
elif hasattr(board, "JOYSTICK_X"):
163157
joy_x = self._read_joystick_x()
164158
joy_y = self._read_joystick_y()
165-
if joy_x > self._center_x + 100:
159+
if joy_x > self._center_x + 1000:
166160
self._cursor.x += self._cursor.speed
167-
elif joy_x < self._center_x - 100:
161+
elif joy_x < self._center_x - 1000:
168162
self._cursor.x -= self._cursor.speed
169-
if joy_y > self._center_y + 100:
163+
if joy_y > self._center_y + 1000:
170164
self._cursor.y += self._cursor.speed
171-
elif joy_y < self._center_y - 100:
165+
elif joy_y < self._center_y - 1000:
172166
self._cursor.y -= self._cursor.speed
173167
else:
174168
raise AttributeError(
@@ -219,4 +213,4 @@ def update(self):
219213
"""Updates the cursor object."""
220214
self._pressed = self._pad.get_pressed()
221215
self._check_cursor_movement(self._pressed)
222-
self._debouncer.update()
216+
self._debouncer.update()

0 commit comments

Comments
 (0)