Skip to content

Commit 72e7c0b

Browse files
authored
Merge branch 'master' into master
2 parents fc48cd4 + 80ed5a0 commit 72e7c0b

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

CPB_ANCS/code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import displayio
1313
import adafruit_ble
1414
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
15-
from adafruit_ble.services.apple import AppleNotificationService
15+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
1616
from adafruit_gizmo import tft_gizmo
1717
from audiocore import WaveFile
1818
from audiopwmio import PWMAudioOut as AudioOut
@@ -54,11 +54,11 @@ def play_sound():
5454

5555
def find_connection():
5656
for connection in radio.connections:
57-
if AppleNotificationService not in connection:
57+
if AppleNotificationCenterService not in connection:
5858
continue
5959
if not connection.paired:
6060
connection.pair()
61-
return connection, connection[AppleNotificationService]
61+
return connection, connection[AppleNotificationCenterService]
6262
return None, None
6363

6464
class Dimmer:
@@ -86,7 +86,7 @@ def check_timeout(self):
8686
radio = adafruit_ble.BLERadio()
8787
advertisement = SolicitServicesAdvertisement()
8888
advertisement.complete_name = "CIRCUITPY"
89-
advertisement.solicited_services.append(AppleNotificationService)
89+
advertisement.solicited_services.append(AppleNotificationCenterService)
9090

9191
def wrap_in_tilegrid(open_file):
9292
odb = displayio.OnDiskBitmap(open_file)

CPB_ANCS/print_code.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""This demo shows the latest notification from a connected Apple device on the REPL and Gizmo"""
2+
import time
3+
import adafruit_ble
4+
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
5+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
6+
from adafruit_gizmo import tft_gizmo
7+
8+
# This is a whitelist of apps to show notifications from.
9+
#APPS = ["com.tinyspeck.chatlyio", "com.atebits.Tweetie2"]
10+
APPS = []
11+
12+
DELAY_AFTER_PRESS = 15
13+
DEBOUNCE = 0.1
14+
15+
def find_connection():
16+
for connection in radio.connections:
17+
if AppleNotificationCenterService not in connection:
18+
continue
19+
if not connection.paired:
20+
connection.pair()
21+
return connection, connection[AppleNotificationCenterService]
22+
return None, None
23+
24+
# Start advertising before messing with the display so that we can connect immediately.
25+
radio = adafruit_ble.BLERadio()
26+
advertisement = SolicitServicesAdvertisement()
27+
advertisement.complete_name = "CIRCUITPY"
28+
advertisement.solicited_services.append(AppleNotificationCenterService)
29+
30+
display = tft_gizmo.TFT_Gizmo()
31+
32+
current_notification = None
33+
new_ids = []
34+
displayed_ids = []
35+
active_connection, notification_service = find_connection()
36+
while True:
37+
if not active_connection:
38+
radio.start_advertising(advertisement)
39+
40+
while not active_connection:
41+
print("waiting for connection...")
42+
active_connection, notification_service = find_connection()
43+
time.sleep(0.1)
44+
45+
while active_connection.connected:
46+
current_notifications = notification_service.active_notifications
47+
for notification_id in current_notifications:
48+
if notification_id in displayed_ids:
49+
continue # already seen!
50+
notification = current_notifications[notification_id]
51+
print('-'*36)
52+
category = str(notification).split(" ", 1)[0]
53+
print("Msg #%d - Category %s" % (notification.id, category))
54+
print("From app:", notification.app_id)
55+
if notification.title:
56+
print("Title:", notification.title)
57+
if notification.subtitle:
58+
print("Subtitle:", notification.subtitle)
59+
if notification.message:
60+
print("Message:", notification.message)
61+
displayed_ids.append(id)
62+
active_connection = None
63+
notification_service = None

0 commit comments

Comments
 (0)