1111from adafruit_display_text import label
1212
1313from adafruit_ble_apple_media import AppleMediaService
14+ from adafruit_ble_apple_media import UnsupportedCommand
1415import board
1516import digitalio
1617import gamepad
@@ -35,6 +36,7 @@ def __init__(self):
3536 self ._b .switch_to_input (pull = digitalio .Pull .UP )
3637 self ._gamepad = gamepad .GamePad (self ._a , self ._b )
3738
39+ @property
3840 def were_pressed (self ):
3941 ret = set ()
4042 pressed = self ._gamepad .get_pressed ()
@@ -49,12 +51,15 @@ def _touch(self, i):
4951 self ._touches [i ].threshold += self ._touch_threshold_adjustment
5052 return self ._touches [i ].value
5153
54+ @property
5255 def touch_0 (self ):
5356 return self ._touch (0 )
5457
58+ @property
5559 def touch_1 (self ):
5660 return self ._touch (1 )
5761
62+ @property
5863 def touch_2 (self ):
5964 return self ._touch (2 )
6065
@@ -437,6 +442,7 @@ def setup_display(self):
437442 self .display .show (self .splash )
438443 while len (self .loading_group ):
439444 self .loading_group .pop ()
445+ self .clue = clue ()
440446
441447
442448 def update_display (self ):
@@ -490,27 +496,30 @@ def update_display(self):
490496# self.display.show(self.splash)
491497
492498 def ams_remote (self ):
493- # Capacitive touch pad marked 0 goes to the previous track
494- if clue .touch_0 :
495- self .ams .previous_track ()
496- time .sleep (0.25 )
497-
498- # Capacitive touch pad marked 1 toggles pause/play
499- if clue .touch_1 :
500- self .ams .toggle_play_pause ()
501- time .sleep (0.25 )
502-
503- # Capacitive touch pad marked 2 advances to the next track
504- if clue .touch_2 :
505- self .ams .next_track ()
506- time .sleep (0.25 )
507-
508- # If button B (on the right) is pressed, it increases the volume
509- if 'B' in clue .were_pressed :
510- self .ams .volume_up ()
511- time .sleep (0.1 )
512-
513- # If button A (on the left) is pressed, the volume decreases
514- if 'A' in clue .were_pressed :
515- self .ams .volume_down ()
516- time .sleep (0.1 )
499+ try :
500+ # Capacitive touch pad marked 0 goes to the previous track
501+ if self .clue .touch_0 :
502+ self .ams .previous_track ()
503+ time .sleep (0.25 )
504+
505+ # Capacitive touch pad marked 1 toggles pause/play
506+ if self .clue .touch_1 :
507+ self .ams .toggle_play_pause ()
508+ time .sleep (0.25 )
509+
510+ # Capacitive touch pad marked 2 advances to the next track
511+ if self .clue .touch_2 :
512+ self .ams .next_track ()
513+ time .sleep (0.25 )
514+
515+ # If button B (on the right) is pressed, it increases the volume
516+ if 'B' in self .clue .were_pressed :
517+ self .ams .volume_up ()
518+ time .sleep (0.1 )
519+
520+ # If button A (on the left) is pressed, the volume decreases
521+ if 'A' in self .clue .were_pressed :
522+ self .ams .volume_down ()
523+ time .sleep (0.1 )
524+ except (RuntimeError , UnsupportedCommand , AttributeError ):
525+ return
0 commit comments