41
41
# PyBadge & PyGamer
42
42
PYBADGE_BUTTON_A = const (2 )
43
43
44
- JOY_X_CTR = 32767.5
45
- JOY_Y_CTR = 32767.5
46
-
47
-
48
44
class CursorManager (object ):
49
45
"""Simple interaction user interface interaction for Adafruit_CursorControl.
50
46
@@ -55,8 +51,8 @@ def __init__(self, cursor):
55
51
self ._cursor = cursor
56
52
self ._is_clicked = False
57
53
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
60
56
61
57
def __enter__ (self ):
62
58
return self
@@ -129,7 +125,6 @@ def _read_joystick_x(self, samples=3):
129
125
for sample in range (0 , samples ):
130
126
reading += self ._joystick_x .value
131
127
reading /= samples
132
- reading -= JOY_X_CTR
133
128
return reading
134
129
135
130
def _read_joystick_y (self , samples = 3 ):
@@ -142,7 +137,6 @@ def _read_joystick_y(self, samples=3):
142
137
for sample in range (0 , samples ):
143
138
reading += self ._joystick_y .value
144
139
reading /= samples
145
- reading -= JOY_Y_CTR
146
140
return reading
147
141
148
142
def _check_cursor_movement (self , pressed = None ):
@@ -162,13 +156,13 @@ def _check_cursor_movement(self, pressed=None):
162
156
elif hasattr (board , "JOYSTICK_X" ):
163
157
joy_x = self ._read_joystick_x ()
164
158
joy_y = self ._read_joystick_y ()
165
- if joy_x > self ._center_x + 100 :
159
+ if joy_x > self ._center_x + 1000 :
166
160
self ._cursor .x += self ._cursor .speed
167
- elif joy_x < self ._center_x - 100 :
161
+ elif joy_x < self ._center_x - 1000 :
168
162
self ._cursor .x -= self ._cursor .speed
169
- if joy_y > self ._center_y + 100 :
163
+ if joy_y > self ._center_y + 1000 :
170
164
self ._cursor .y += self ._cursor .speed
171
- elif joy_y < self ._center_y - 100 :
165
+ elif joy_y < self ._center_y - 1000 :
172
166
self ._cursor .y -= self ._cursor .speed
173
167
else :
174
168
raise AttributeError (
@@ -219,4 +213,4 @@ def update(self):
219
213
"""Updates the cursor object."""
220
214
self ._pressed = self ._pad .get_pressed ()
221
215
self ._check_cursor_movement (self ._pressed )
222
- self ._debouncer .update ()
216
+ self ._debouncer .update ()
0 commit comments