3131PYBADGE_BUTTON_DOWN = const (5 )
3232PYBADGE_BUTTON_RIGHT = const (4 )
3333# PyBadge & PyGamer
34+ PYBADGE_BUTTON_SELECT = const (3 )
35+ PYBADGE_BUTTON_START = const (2 )
3436PYBADGE_BUTTON_A = const (1 )
3537PYBADGE_BUTTON_B = const (0 )
3638
@@ -41,10 +43,14 @@ class CursorManager:
4143 :param Cursor cursor: The cursor object we are using.
4244 """
4345
46+ # pylint: disable=too-many-instance-attributes
47+
4448 def __init__ (self , cursor : Cursor ) -> None :
4549 self ._cursor = cursor
4650 self ._is_clicked = False
4751 self ._is_alt_clicked = False
52+ self ._is_select_clicked = False
53+ self ._is_start_clicked = False
4854 self ._pad_states = 0
4955 self ._event = Event ()
5056 self ._init_hardware ()
@@ -86,12 +92,19 @@ def _init_hardware(self) -> None:
8692 "btn_down" : PYBADGE_BUTTON_DOWN ,
8793 "btn_a" : PYBADGE_BUTTON_A ,
8894 "btn_b" : PYBADGE_BUTTON_B ,
95+ "btn_select" : PYBADGE_BUTTON_SELECT ,
96+ "btn_start" : PYBADGE_BUTTON_START ,
8997 }
9098 self ._pad_states = 0
9199 elif hasattr (board , "JOYSTICK_X" ):
92100 self ._joystick_x = analogio .AnalogIn (board .JOYSTICK_X )
93101 self ._joystick_y = analogio .AnalogIn (board .JOYSTICK_Y )
94- self ._pad_btns = {"btn_a" : PYBADGE_BUTTON_A , "btn_b" : PYBADGE_BUTTON_B }
102+ self ._pad_btns = {
103+ "btn_a" : PYBADGE_BUTTON_A ,
104+ "btn_b" : PYBADGE_BUTTON_B ,
105+ "btn_select" : PYBADGE_BUTTON_SELECT ,
106+ "btn_start" : PYBADGE_BUTTON_START ,
107+ }
95108 # Sample the center points of the joystick
96109 self ._center_x = self ._joystick_x .value
97110 self ._center_y = self ._joystick_y .value
@@ -109,18 +122,32 @@ def _init_hardware(self) -> None:
109122
110123 @property
111124 def is_clicked (self ) -> bool :
112- """Returns True if the cursor button was pressed
125+ """Returns True if the cursor A button was pressed
113126 during previous call to update()
114127 """
115128 return self ._is_clicked
116129
117130 @property
118131 def is_alt_clicked (self ) -> bool :
119- """Returns True if the cursor button was pressed
132+ """Returns True if the cursor B button was pressed
120133 during previous call to update()
121134 """
122135 return self ._is_alt_clicked
123136
137+ @property
138+ def is_select_clicked (self ) -> bool :
139+ """Returns True if the Select button was pressed
140+ during previous call to update()
141+ """
142+ return self ._is_select_clicked
143+
144+ @property
145+ def is_start_clicked (self ) -> bool :
146+ """Returns True if the Start button was pressed
147+ during previous call to update()
148+ """
149+ return self ._is_start_clicked
150+
124151 def update (self ) -> None :
125152 """Updates the cursor object."""
126153 if self ._pad .events .get_into (self ._event ):
@@ -136,6 +163,16 @@ def update(self) -> None:
136163 elif self ._pad_states & (1 << self ._pad_btns ["btn_b" ]):
137164 self ._is_alt_clicked = True
138165
166+ if self ._is_select_clicked :
167+ self ._is_select_clicked = False
168+ elif self ._pad_states & (1 << self ._pad_btns ["btn_select" ]):
169+ self ._is_select_clicked = True
170+
171+ if self ._is_start_clicked :
172+ self ._is_start_clicked = False
173+ elif self ._pad_states & (1 << self ._pad_btns ["btn_start" ]):
174+ self ._is_start_clicked = True
175+
139176 def _read_joystick_x (self , samples : int = 3 ) -> float :
140177 """Read the X analog joystick on the PyGamer.
141178 :param int samples: How many samples to read and average.
0 commit comments