@@ -236,45 +236,103 @@ def _check_cursor_movement(self) -> None:
236
236
237
237
238
238
class DebouncedCursorManager (CursorManager ):
239
- """Simple interaction user interface interaction for Adafruit_CursorControl.
240
- This subclass provide a debounced version on the A button and provides queries for when
241
- the button is just pressed, and just released, as well it's current state. "Just" in this
242
- context means "since the previous call to update."
239
+ """Simple user interface interaction for Adafruit_CursorControl.
240
+ This subclass provide a debounced version on the A, B, Start or Select buttons
241
+ and provides queries for when the buttons are just pressed, and just released,
242
+ as well their current state. "Just" in this context means "since the previous call to update."
243
243
244
244
:param Cursor cursor: The cursor object we are using.
245
245
"""
246
246
247
247
def __init__ (self , cursor : Cursor , debounce_interval : float = 0.01 ) -> None :
248
248
CursorManager .__init__ (self , cursor )
249
- self ._debouncer = Debouncer (
250
- lambda : bool (self ._pad_states & (1 << self ._pad_btns ["btn_a" ])),
251
- interval = debounce_interval ,
252
- )
249
+ self ._debouncers = {}
250
+ for btn , _ in self ._pad_btns .items ():
251
+ self ._debouncers [btn ] = Debouncer (
252
+ lambda btn = btn : bool ((self ._pad_states & (1 << self ._pad_btns [btn ]))),
253
+ interval = debounce_interval ,
254
+ )
253
255
254
256
@property
255
257
def is_clicked (self ) -> bool :
256
- """Returns True if the cursor button was pressed
258
+ """Returns True if the cursor A button was pressed
259
+ during previous call to update()
260
+ """
261
+ return self ._debouncers ["btn_a" ].rose
262
+
263
+ @property
264
+ def is_alt_clicked (self ) -> bool :
265
+ """Returns True if the cursor B button was pressed
257
266
during previous call to update()
258
267
"""
259
- return self ._debouncer .rose
268
+ return self ._debouncers [ "btn_b" ] .rose
260
269
261
- pressed = is_clicked
270
+ @property
271
+ def is_select_clicked (self ) -> bool :
272
+ """Returns True if the Select button was pressed
273
+ during previous call to update()
274
+ """
275
+ return self ._debouncers ["btn_select" ].rose
276
+
277
+ @property
278
+ def is_start_clicked (self ) -> bool :
279
+ """Returns True if the Start button was pressed
280
+ during previous call to update()
281
+ """
282
+ return self ._debouncers ["btn_start" ].rose
262
283
263
284
@property
264
285
def released (self ) -> bool :
265
- """Returns True if the cursor button was released
286
+ """Returns True if the cursor A button was released
287
+ during previous call to update()
288
+ """
289
+ return self ._debouncers ["btn_a" ].fell
290
+
291
+ @property
292
+ def alt_released (self ) -> bool :
293
+ """Returns True if the cursor B button was released
266
294
during previous call to update()
267
295
"""
268
- return self ._debouncer .fell
296
+ return self ._debouncers ["btn_b" ].fell
297
+
298
+ @property
299
+ def start_released (self ) -> bool :
300
+ """Returns True if the cursor Start button was released
301
+ during previous call to update()
302
+ """
303
+ return self ._debouncers ["btn_start" ].fell
304
+
305
+ @property
306
+ def select_released (self ) -> bool :
307
+ """Returns True if the cursor Select button was released
308
+ during previous call to update()
309
+ """
310
+ return self ._debouncers ["btn_select" ].fell
269
311
270
312
@property
271
313
def held (self ) -> bool :
272
- """Returns True if the cursor button is currently being held"""
273
- return self ._debouncer .value
314
+ """Returns True if the cursor A button is currently being held"""
315
+ return self ._debouncers ["btn_a" ].value
316
+
317
+ @property
318
+ def alt_held (self ) -> bool :
319
+ """Returns True if the cursor B button is currently being held"""
320
+ return self ._debouncers ["btn_b" ].value
321
+
322
+ @property
323
+ def start_held (self ) -> bool :
324
+ """Returns True if the cursor Start button is currently being held"""
325
+ return self ._debouncers ["btn_start" ].value
326
+
327
+ @property
328
+ def select_held (self ) -> bool :
329
+ """Returns True if the cursor Select is currently being held"""
330
+ return self ._debouncers ["btn_select" ].value
274
331
275
332
def update (self ) -> None :
276
333
"""Updates the cursor object."""
277
334
if self ._pad .events .get_into (self ._event ):
278
335
self ._store_button_states ()
279
336
self ._check_cursor_movement ()
280
- self ._debouncer .update ()
337
+ for debouncer in self ._debouncers .values ():
338
+ debouncer .update ()
0 commit comments