@@ -37,6 +37,7 @@ def __init__(self, cursor):
37
37
self ._cursor = cursor
38
38
self ._is_clicked = False
39
39
self ._pad_states = 0
40
+ self ._event = None
40
41
self ._init_hardware ()
41
42
42
43
def __enter__ (self ):
@@ -99,8 +100,8 @@ def is_clicked(self):
99
100
100
101
def update (self ):
101
102
"""Updates the cursor object."""
102
- event = self ._pad .events .get ()
103
- self ._store_button_states (event )
103
+ if self ._pad .events .get_into ( self . _event ):
104
+ self ._store_button_states ()
104
105
self ._check_cursor_movement ()
105
106
if self ._is_clicked :
106
107
self ._is_clicked = False
@@ -131,17 +132,16 @@ def _read_joystick_y(self, samples=3):
131
132
reading /= samples
132
133
return reading
133
134
134
- def _store_button_states (self , event ):
135
+ def _store_button_states (self ):
135
136
"""Stores the state of the PyBadge's D-Pad or the PyGamer's Joystick
136
137
into a byte
137
138
138
139
:param Event event: The latest button press transition event detected.
139
140
"""
140
- if event :
141
- bit_index = event .key_number
142
- current_state = self ._pad_states >> bit_index
143
- if current_state != event .pressed :
144
- self ._pad_states = (1 << bit_index ) ^ self ._pad_states
141
+ bit_index = self ._event .key_number
142
+ current_state = (self ._pad_states >> bit_index ) & 1
143
+ if current_state != self ._event .pressed :
144
+ self ._pad_states = (1 << bit_index ) ^ self ._pad_states
145
145
146
146
def _check_cursor_movement (self ):
147
147
"""Checks the PyBadge D-Pad or the PyGamer's Joystick for movement."""
@@ -211,7 +211,7 @@ def held(self):
211
211
212
212
def update (self ):
213
213
"""Updates the cursor object."""
214
- event = self ._pad .events .get ()
215
- self ._store_button_states (event )
214
+ if self ._pad .events .get_into ( self . _event ):
215
+ self ._store_button_states ()
216
216
self ._check_cursor_movement ()
217
217
self ._debouncer .update ()
0 commit comments