Skip to content

Commit a9e34f7

Browse files
committed
updates to lib per request
1 parent 7b49cff commit a9e34f7

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

adafruit_featherwing/joy_featherwing.py

+38-41
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
BUTTON_Y = const(1 << 9)
4141
BUTTON_X = const(1 << 10)
4242
BUTTON_SELECT = const(1 << 14)
43-
# BUTTON_MASK = const((1 << BUTTON_A) | (1 << BUTTON_B) | (1 << BUTTON_Y) | (1 << BUTTON_X) |
44-
# (1 << BUTTON_SELECT))
4543

4644

4745
class JoyFeatherWing:
@@ -70,10 +68,10 @@ def button_a(self):
7068
from adafruit_featherwing import joy_featherwing
7169
import time
7270
73-
WING = joy_featherwing.JoyFeatherWing()
71+
wing = joy_featherwing.JoyFeatherWing()
7472
7573
while True:
76-
if WING.button_a:
74+
if wing.button_a:
7775
print("Button A pressed!")
7876
7977
"""
@@ -93,10 +91,10 @@ def button_b(self):
9391
from adafruit_featherwing import joy_featherwing
9492
import time
9593
96-
WING = joy_featherwing.JoyFeatherWing()
94+
wing = joy_featherwing.JoyFeatherWing()
9795
9896
while True:
99-
if WING.button_b:
97+
if wing.button_b:
10098
print("Button B pressed!")
10199
102100
"""
@@ -116,10 +114,10 @@ def button_x(self):
116114
from adafruit_featherwing import joy_featherwing
117115
import time
118116
119-
WING = joy_featherwing.JoyFeatherWing()
117+
wing = joy_featherwing.JoyFeatherWing()
120118
121119
while True:
122-
if WING.button_x:
120+
if wing.button_x:
123121
print("Button X pressed!")
124122
125123
"""
@@ -139,10 +137,10 @@ def button_y(self):
139137
from adafruit_featherwing import joy_featherwing
140138
import time
141139
142-
WING = joy_featherwing.JoyFeatherWing()
140+
wing = joy_featherwing.JoyFeatherWing()
143141
144142
while True:
145-
if WING.button_y:
143+
if wing.button_y:
146144
print("Button Y pressed!")
147145
148146
"""
@@ -162,10 +160,10 @@ def button_select(self):
162160
from adafruit_featherwing import joy_featherwing
163161
import time
164162
165-
WING = joy_featherwing.JoyFeatherWing()
163+
wing = joy_featherwing.JoyFeatherWing()
166164
167165
while True:
168-
if WING.button_select:
166+
if wing.button_select:
169167
print("Button SELECT pressed!")
170168
171169
"""
@@ -178,12 +176,7 @@ def _check_button(self, button):
178176

179177
@property
180178
def joystick_offset(self):
181-
"""Returns the joystick offset, set by the `joystick_offset.setter`."""
182-
return self._joystick_offset
183-
184-
@joystick_offset.setter
185-
def joystick_offset(self, offset):
186-
"""Allows for setting explicit numbers to effectively zero the joystick.
179+
"""Offset used to correctly report (0, 0) when the joystick is centered.
187180
188181
.. image :: /_static/joy_featherwing/joy_featherwing_joystick.jpg
189182
:alt: Joy FeatherWing Joystick
@@ -202,20 +195,24 @@ def joystick_offset(self, offset):
202195
from adafruit_featherwing import joy_featherwing
203196
import time
204197
205-
WING = joy_featherwing.JoyFeatherWing()
206-
LAST_X = 0
207-
LAST_Y = 0
198+
wing = joy_featherwing.JoyFeatherWing()
199+
last_x = 0
200+
last_y = 0
208201
209202
while True:
210203
wing.joystick_offset = (-4, 0)
211-
x, y = WING.joystick
212-
if (abs(x - LAST_X) > 3) or (abs(y - LAST_Y) > 3):
213-
LAST_X = x
214-
LAST_Y = y
204+
x, y = wing.joystick
205+
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
206+
last_x = x
207+
last_y = y
215208
print(x, y)
216209
time.sleep(0.01)
217210
218211
"""
212+
return self._joystick_offset
213+
214+
@joystick_offset.setter
215+
def joystick_offset(self, offset):
219216
self._joystick_offset = offset
220217

221218
def zero_joystick(self):
@@ -234,16 +231,16 @@ def zero_joystick(self):
234231
from adafruit_featherwing import joy_featherwing
235232
import time
236233
237-
WING = joy_featherwing.JoyFeatherWing()
238-
LAST_X = 0
239-
LAST_Y = 0
240-
WING.zero_joystick()
234+
wing = joy_featherwing.JoyFeatherWing()
235+
last_x = 0
236+
last_y = 0
237+
wing.zero_joystick()
241238
242239
while True:
243-
x, y = WING.joystick
244-
if (abs(x - LAST_X) > 3) or (abs(y - LAST_Y) > 3):
245-
LAST_X = x
246-
LAST_Y = y
240+
x, y = wing.joystick
241+
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
242+
last_x = x
243+
last_y = y
247244
print(x, y)
248245
time.sleep(0.01)
249246
@@ -266,16 +263,16 @@ def joystick(self):
266263
from adafruit_featherwing import joy_featherwing
267264
import time
268265
269-
WING = joy_featherwing.JoyFeatherWing()
270-
LAST_X = 0
271-
LAST_Y = 0
272-
WING.zero_joystick()
266+
wing = joy_featherwing.JoyFeatherWing()
267+
last_x = 0
268+
last_y = 0
269+
wing.zero_joystick()
273270
274271
while True:
275-
x, y = WING.joystick
276-
if (abs(x - LAST_X) > 3) or (abs(y - LAST_Y) > 3):
277-
LAST_X = x
278-
LAST_Y = y
272+
x, y = wing.joystick
273+
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
274+
last_x = x
275+
last_y = y
279276
print(x, y)
280277
time.sleep(0.01)
281278
"""

0 commit comments

Comments
 (0)