32
32
PYBADGE_BUTTON_RIGHT = const (4 )
33
33
# PyBadge & PyGamer
34
34
PYBADGE_BUTTON_A = const (1 )
35
+ PYBADGE_BUTTON_B = const (0 )
35
36
36
37
37
38
class CursorManager :
@@ -43,6 +44,7 @@ class CursorManager:
43
44
def __init__ (self , cursor : Cursor ) -> None :
44
45
self ._cursor = cursor
45
46
self ._is_clicked = False
47
+ self ._is_alt_clicked = False
46
48
self ._pad_states = 0
47
49
self ._event = Event ()
48
50
self ._init_hardware ()
@@ -83,12 +85,13 @@ def _init_hardware(self) -> None:
83
85
"btn_up" : PYBADGE_BUTTON_UP ,
84
86
"btn_down" : PYBADGE_BUTTON_DOWN ,
85
87
"btn_a" : PYBADGE_BUTTON_A ,
88
+ "btn_b" : PYBADGE_BUTTON_B ,
86
89
}
87
90
self ._pad_states = 0
88
91
elif hasattr (board , "JOYSTICK_X" ):
89
92
self ._joystick_x = analogio .AnalogIn (board .JOYSTICK_X )
90
93
self ._joystick_y = analogio .AnalogIn (board .JOYSTICK_Y )
91
- self ._pad_btns = {"btn_a" : PYBADGE_BUTTON_A }
94
+ self ._pad_btns = {"btn_a" : PYBADGE_BUTTON_A , "btn_b" : PYBADGE_BUTTON_B }
92
95
# Sample the center points of the joystick
93
96
self ._center_x = self ._joystick_x .value
94
97
self ._center_y = self ._joystick_y .value
@@ -111,6 +114,13 @@ def is_clicked(self) -> bool:
111
114
"""
112
115
return self ._is_clicked
113
116
117
+ @property
118
+ def is_alt_clicked (self ) -> bool :
119
+ """Returns True if the cursor button was pressed
120
+ during previous call to update()
121
+ """
122
+ return self ._is_alt_clicked
123
+
114
124
def update (self ) -> None :
115
125
"""Updates the cursor object."""
116
126
if self ._pad .events .get_into (self ._event ):
@@ -121,6 +131,11 @@ def update(self) -> None:
121
131
elif self ._pad_states & (1 << self ._pad_btns ["btn_a" ]):
122
132
self ._is_clicked = True
123
133
134
+ if self ._is_alt_clicked :
135
+ self ._is_alt_clicked = False
136
+ elif self ._pad_states & (1 << self ._pad_btns ["btn_b" ]):
137
+ self ._is_alt_clicked = True
138
+
124
139
def _read_joystick_x (self , samples : int = 3 ) -> float :
125
140
"""Read the X analog joystick on the PyGamer.
126
141
:param int samples: How many samples to read and average.
0 commit comments