Skip to content

Commit 7ef68b1

Browse files
committed
Added displayio to clue_ams_remote
1 parent 7a6f276 commit 7ef68b1

File tree

1 file changed

+105
-35
lines changed

1 file changed

+105
-35
lines changed

examples/clue_ams_remote.py

Lines changed: 105 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
This example solicits that apple devices that provide notifications connect to it, initiates
1+
""" This example solicits that apple devices that provide notifications connect to it, initiates
32
pairing, then allows the user to use a CLUE board as a media remote through both the buttons
43
and capacitive touch pads.
54
@@ -12,7 +11,13 @@
1211
import adafruit_ble
1312
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
1413
from adafruit_ble_apple_media import AppleMediaService
14+
from adafruit_ble_apple_media import UnsupportedCommand
1515
from adafruit_clue import clue
16+
import displayio
17+
from adafruit_bitmap_font import bitmap_font
18+
from adafruit_display_shapes.rect import Rect
19+
from adafruit_display_text import label
20+
import board
1621

1722
# PyLint can't find BLERadio for some reason so special case it here.
1823
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
@@ -36,42 +41,107 @@
3641

3742
ams = connection[AppleMediaService]
3843

44+
45+
#arial12 = bitmap_font.load_font("/fonts/Arial-12.bdf")
46+
arial16 = bitmap_font.load_font("/fonts/Arial-16.bdf")
47+
#arial24 = bitmap_font.load_font("/fonts/Arial-Bold-24.bdf")
48+
49+
display = board.DISPLAY
50+
51+
group = displayio.Group(max_size=25)
52+
53+
title = label.Label(font=arial16, x=15, y=25, text='_', color=0xFFFFFF, max_glyphs=30)
54+
group.append(title)
55+
56+
artist = label.Label(font=arial16, x=15, y=50, text='_', color=0xFFFFFF, max_glyphs=30)
57+
group.append(artist)
58+
59+
album = label.Label(font=arial16, x=15, y=75, text='_', color=0xFFFFFF, max_glyphs=30)
60+
group.append(album)
61+
62+
player = label.Label(font=arial16, x=15, y=100, text='_', color=0xFFFFFF, max_glyphs=30)
63+
group.append(player)
64+
65+
volume = Rect(15, 170, 210, 20, fill=0x0, outline=0xFFFFFF)
66+
group.append(volume)
67+
68+
track_time = Rect(15, 210, 210, 20, fill=0x0, outline=0xFFFFFF)
69+
#time = label.Label(font=arial16, x=15, y=215, text='Time', color=0xFFFFFF)
70+
group.append(track_time)
71+
72+
time_inner = Rect(15, 210, 1, 20, fill=0xFFFFFF, outline=0xFFFFFF)
73+
group.append(time_inner)
74+
75+
volume_inner = Rect(15, 170, 1, 20, fill=0xFFFFFF, outline=0xFFFFFF)
76+
group.append(volume_inner)
77+
78+
display.show(group)
79+
time.sleep(0.01)
80+
81+
width1 = 1
82+
83+
ref_time = time.time()
84+
ela_time = ams.elapsed_time
3985
while radio.connected:
40-
if ams.playing:
41-
play_str = "Playing"
42-
else:
43-
play_str = "Paused"
44-
print("{} - {}, {}".format(ams.title, ams.artist, play_str))
45-
46-
# Capacitive touch pad marked 0 goes to the previous track
47-
if clue.touch_0:
48-
ams.previous_track()
49-
time.sleep(0.25)
50-
51-
# Capacitive touch pad marked 1 toggles pause/play
52-
if clue.touch_1:
53-
ams.toggle_play_pause()
54-
time.sleep(0.25)
55-
56-
# Capacitive touch pad marked 2 advances to the next track
57-
if clue.touch_2:
58-
ams.next_track()
59-
time.sleep(0.25)
60-
61-
# If button B (on the right) is pressed, it increases the volume
62-
if 'B' in clue.were_pressed:
63-
ams.volume_up()
64-
time.sleep(0.30)
65-
while 'B' in clue.were_pressed:
86+
try:
87+
if ams.elapsed_time != ela_time:
88+
ela_time = ams.elapsed_time
89+
ref_time = time.time()
90+
title.text = ams.title
91+
artist.text = ams.artist
92+
album.text = ams.album
93+
player.text = ams.player_name
94+
if ams.volume is not None:
95+
width = int(16*13.125*float(ams.volume))
96+
if not width:
97+
width = 1
98+
if ams.duration and ams.playing:
99+
width1 = int(210*((time.time() - ref_time + ela_time)/float(ams.duration)))
100+
if not width1:
101+
width1 = 1
102+
elif not ams.duration:
103+
width1 = 1
104+
105+
time_inner = Rect(15, 210, width1, 20, fill=0xFFFFFF)#, outline=0xFFFFFF)
106+
group[-2] = time_inner
107+
volume_inner = Rect(15, 170, width, 20, fill=0xFFFFFF)#, outline=0xFFFFFF)
108+
group[-1] = volume_inner
109+
110+
# Capacitive touch pad marked 0 goes to the previous track
111+
if clue.touch_0:
112+
ams.previous_track()
113+
time.sleep(0.25)
114+
115+
# Capacitive touch pad marked 1 toggles pause/play
116+
if clue.touch_1:
117+
ams.toggle_play_pause()
118+
time.sleep(0.25)
119+
120+
# Capacitive touch pad marked 2 advances to the next track
121+
if clue.touch_2:
122+
ams.next_track()
123+
time.sleep(0.25)
124+
125+
# If button B (on the right) is pressed, it increases the volume
126+
if 'B' in clue.were_pressed:
66127
ams.volume_up()
67-
time.sleep(0.07)
128+
a = clue.were_pressed
129+
time.sleep(0.35)
130+
while 'B' in clue.were_pressed:
131+
ams.volume_up()
132+
time.sleep(0.07)
68133

69-
# If button A (on the left) is pressed, the volume decreases
70-
if 'A' in clue.were_pressed:
71-
ams.volume_down()
72-
time.sleep(0.30)
73-
while 'A' in clue.were_pressed:
134+
# If button A (on the left) is pressed, the volume decreases
135+
if 'A' in clue.were_pressed:
74136
ams.volume_down()
75-
time.sleep(0.07)
137+
a = clue.were_pressed
138+
time.sleep(0.35)
139+
while 'A' in clue.were_pressed:
140+
ams.volume_down()
141+
time.sleep(0.07)
142+
time.sleep(0.01)
143+
except (RuntimeError, UnsupportedCommand, AttributeError):
144+
time.sleep(0.01)
145+
continue
76146

77147
print("disconnected")

0 commit comments

Comments
 (0)