Skip to content

Added clue_ams_remote.py #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 17, 2020
73 changes: 73 additions & 0 deletions examples/clue_ams_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
This example solicits that apple devices that provide notifications connect to it, initiates
pairing, then allows the user to use a CLUE board as a media remote through both the buttons
and capacitive touch pads.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if you could include a note in the doc string about the separate libraries needed to run this example. Whenever I include an example in a library-specific repo that requires an atypical library (e.g. adafruit_ble, and adafruit_ble_apple_media), I include a note in the docstring to alleviate any potential confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do


import time
import adafruit_ble
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
from adafruit_ble_apple_media import AppleMediaService
from adafruit_clue import clue

# PyLint can't find BLERadio for some reason so special case it here.
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
a = SolicitServicesAdvertisement()
a.solicited_services.append(AppleMediaService)
radio.start_advertising(a)

while not radio.connected:
pass

print("connected")

known_notifications = set()

i = 0
if radio.connected:
for connection in radio.connections:
if not connection.paired:
connection.pair()
print("paired")

ams = connection[AppleMediaService]

while radio.connected:
if ams.playing:
play_str = "Playing"
else:
play_str = "Paused"
print("{} - {}, {}".format(ams.title, ams.artist, play_str))

# Capacitive touch pad marked 0 goes to the previous track
if clue.touch_0:
ams.previous_track()
time.sleep(0.25)

# Capacitive touch pad marked 1 toggles pause/play
if clue.touch_1:
ams.toggle_play_pause()
time.sleep(0.25)

# Capacitive touch pad marked 2 advances to the next track
if clue.touch_2:
ams.next_track()
time.sleep(0.25)

# If button B (on the right) is pressed, it increases the volume
if 'B' in clue.were_pressed:
ams.volume_up()
time.sleep(0.30)
while 'B' in clue.were_pressed:
ams.volume_up()
time.sleep(0.07)

# If button A (on the left) is pressed, the volume decreases
if 'A' in clue.were_pressed:
ams.volume_down()
time.sleep(0.30)
while 'A' in clue.were_pressed:
ams.volume_down()
time.sleep(0.07)

print("disconnected")