Skip to content

Commit f64201c

Browse files
committed
add simulated directional buttons for pygamer
1 parent 4561601 commit f64201c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

adafruit_pybadger.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,22 @@ def button(self):
206206
207207
"""
208208
button_values = self._buttons.get_pressed()
209-
return Buttons(*[button_values & button for button in
210-
(PyBadger.BUTTON_B, PyBadger.BUTTON_A, PyBadger.BUTTON_START,
211-
PyBadger.BUTTON_SELECT, PyBadger.BUTTON_RIGHT,
212-
PyBadger.BUTTON_DOWN, PyBadger.BUTTON_UP, PyBadger.BUTTON_LEFT)])
209+
if hasattr(board, "JOYSTICK_X"):
210+
x, y = self.joystick
211+
return Buttons(button_values & PyBadger.BUTTON_B,
212+
button_values & PyBadger.BUTTON_A,
213+
button_values & PyBadger.BUTTON_START,
214+
button_values & PyBadger.BUTTON_SELECT,
215+
x > 50000, # RIGHT
216+
y > 50000, # DOWN
217+
y < 15000, # UP
218+
x < 15000 # LEFT
219+
)
220+
else:
221+
return Buttons(*[button_values & button for button in
222+
(PyBadger.BUTTON_B, PyBadger.BUTTON_A, PyBadger.BUTTON_START,
223+
PyBadger.BUTTON_SELECT, PyBadger.BUTTON_RIGHT,
224+
PyBadger.BUTTON_DOWN, PyBadger.BUTTON_UP, PyBadger.BUTTON_LEFT)])
213225

214226
@property
215227
def light(self):

0 commit comments

Comments
 (0)