31
31
PYBADGE_BUTTON_DOWN = const (5 )
32
32
PYBADGE_BUTTON_RIGHT = const (4 )
33
33
# PyBadge & PyGamer
34
+ PYBADGE_BUTTON_SELECT = const (3 )
35
+ PYBADGE_BUTTON_START = const (2 )
34
36
PYBADGE_BUTTON_A = const (1 )
35
37
PYBADGE_BUTTON_B = const (0 )
36
38
@@ -41,10 +43,14 @@ class CursorManager:
41
43
:param Cursor cursor: The cursor object we are using.
42
44
"""
43
45
46
+ # pylint: disable=too-many-instance-attributes
47
+
44
48
def __init__ (self , cursor : Cursor ) -> None :
45
49
self ._cursor = cursor
46
50
self ._is_clicked = False
47
51
self ._is_alt_clicked = False
52
+ self ._is_select_clicked = False
53
+ self ._is_start_clicked = False
48
54
self ._pad_states = 0
49
55
self ._event = Event ()
50
56
self ._init_hardware ()
@@ -86,12 +92,19 @@ def _init_hardware(self) -> None:
86
92
"btn_down" : PYBADGE_BUTTON_DOWN ,
87
93
"btn_a" : PYBADGE_BUTTON_A ,
88
94
"btn_b" : PYBADGE_BUTTON_B ,
95
+ "btn_select" : PYBADGE_BUTTON_SELECT ,
96
+ "btn_start" : PYBADGE_BUTTON_START ,
89
97
}
90
98
self ._pad_states = 0
91
99
elif hasattr (board , "JOYSTICK_X" ):
92
100
self ._joystick_x = analogio .AnalogIn (board .JOYSTICK_X )
93
101
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
+ }
95
108
# Sample the center points of the joystick
96
109
self ._center_x = self ._joystick_x .value
97
110
self ._center_y = self ._joystick_y .value
@@ -109,18 +122,32 @@ def _init_hardware(self) -> None:
109
122
110
123
@property
111
124
def is_clicked (self ) -> bool :
112
- """Returns True if the cursor button was pressed
125
+ """Returns True if the cursor A button was pressed
113
126
during previous call to update()
114
127
"""
115
128
return self ._is_clicked
116
129
117
130
@property
118
131
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
120
133
during previous call to update()
121
134
"""
122
135
return self ._is_alt_clicked
123
136
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
+
124
151
def update (self ) -> None :
125
152
"""Updates the cursor object."""
126
153
if self ._pad .events .get_into (self ._event ):
@@ -136,6 +163,16 @@ def update(self) -> None:
136
163
elif self ._pad_states & (1 << self ._pad_btns ["btn_b" ]):
137
164
self ._is_alt_clicked = True
138
165
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
+
139
176
def _read_joystick_x (self , samples : int = 3 ) -> float :
140
177
"""Read the X analog joystick on the PyGamer.
141
178
:param int samples: How many samples to read and average.
0 commit comments