|
1 |
| -# SPDX-FileCopyrightText: 2022 Tod Kurt for Adafruit Industries |
2 |
| -# SPDX-License-Identifier: MIT |
3 |
| - |
4 |
| -""" |
5 |
| -This example solicits notifications from Apple devices paired with it, |
6 |
| -detecting specifically the IncomingCall and ActiveCall notification categories |
7 |
| -and sending back Positive Actions to accept calls or Negative Actions to |
8 |
| -decline or hang up calls. It also shows initiating pairing, prints existing |
9 |
| -notifications and prints any new ones as they arrive. |
10 |
| -""" |
11 |
| - |
12 |
| -import time |
13 |
| -import board |
14 |
| -import digitalio |
15 |
| - |
16 |
| -import adafruit_ble |
17 |
| -from adafruit_ble.advertising.standard import SolicitServicesAdvertisement |
18 |
| -import adafruit_ble_apple_notification_center as ancs |
19 |
| - |
20 |
| -butA = digitalio.DigitalInOut(board.D4) # Circuit Playground Bluefruit A button |
21 |
| -butB = digitalio.DigitalInOut(board.D5) # Circuit Playground Bluefruit A button |
22 |
| -butA.switch_to_input(digitalio.Pull.DOWN) # buttons are active HIGH |
23 |
| -butB.switch_to_input(digitalio.Pull.DOWN) |
24 |
| - |
25 |
| -radio = adafruit_ble.BLERadio() # pylint: disable=no-member |
26 |
| -a = SolicitServicesAdvertisement() |
27 |
| -a.solicited_services.append(ancs.AppleNotificationCenterService) |
28 |
| -radio.start_advertising(a) |
29 |
| - |
30 |
| -while not radio.connected: |
31 |
| - pass |
32 |
| - |
33 |
| -print("connected") |
34 |
| - |
35 |
| -while radio.connected: |
36 |
| - for connection in radio.connections: |
37 |
| - if not connection.paired: |
38 |
| - connection.pair() |
39 |
| - print("paired") |
40 |
| - |
41 |
| - ans = connection[ancs.AppleNotificationCenterService] |
42 |
| - for notification in ans.wait_for_new_notifications(): |
43 |
| - print("new notification:", notification) |
44 |
| - |
45 |
| - print("Notifications:", len(ans.active_notifications)) |
46 |
| - for nid, n in ans.active_notifications.items(): |
47 |
| - print( |
48 |
| - "uid:", |
49 |
| - n.id, |
50 |
| - "cat:", |
51 |
| - n.category_id, |
52 |
| - "title:", |
53 |
| - n.title, |
54 |
| - "msg:", |
55 |
| - n.message, |
56 |
| - ) |
57 |
| - if n.category_id == 1: # incoming call, has positive & negative actions |
58 |
| - if butA.value: |
59 |
| - print("accepting call") |
60 |
| - n.send_positive_action() |
61 |
| - if butB.value: |
62 |
| - print("declining call") |
63 |
| - n.send_negative_action() |
64 |
| - if n.category_id == 12: # active call, only has negative action |
65 |
| - if butB.value: |
66 |
| - print("hanging up call") |
67 |
| - n.send_negative_action() |
68 |
| - time.sleep(1) |
69 |
| - |
70 |
| -print("disconnected") |
| 1 | +# SPDX-FileCopyrightText: 2022 Tod Kurt for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +""" |
| 5 | +This example solicits notifications from Apple devices paired with it, |
| 6 | +detecting specifically the IncomingCall and ActiveCall notification categories |
| 7 | +and sending back Positive Actions to accept calls or Negative Actions to |
| 8 | +decline or hang up calls. It also shows initiating pairing, prints existing |
| 9 | +notifications and prints any new ones as they arrive. |
| 10 | +""" |
| 11 | + |
| 12 | +import time |
| 13 | +import board |
| 14 | +import digitalio |
| 15 | + |
| 16 | +import adafruit_ble |
| 17 | +from adafruit_ble.advertising.standard import SolicitServicesAdvertisement |
| 18 | +import adafruit_ble_apple_notification_center as ancs |
| 19 | + |
| 20 | +butA = digitalio.DigitalInOut(board.D4) # Circuit Playground Bluefruit A button |
| 21 | +butB = digitalio.DigitalInOut(board.D5) # Circuit Playground Bluefruit A button |
| 22 | +butA.switch_to_input(digitalio.Pull.DOWN) # buttons are active HIGH |
| 23 | +butB.switch_to_input(digitalio.Pull.DOWN) |
| 24 | + |
| 25 | +radio = adafruit_ble.BLERadio() # pylint: disable=no-member |
| 26 | +a = SolicitServicesAdvertisement() |
| 27 | +a.solicited_services.append(ancs.AppleNotificationCenterService) |
| 28 | +radio.start_advertising(a) |
| 29 | + |
| 30 | +while not radio.connected: |
| 31 | + pass |
| 32 | + |
| 33 | +print("connected") |
| 34 | + |
| 35 | +while radio.connected: |
| 36 | + for connection in radio.connections: |
| 37 | + if not connection.paired: |
| 38 | + connection.pair() |
| 39 | + print("paired") |
| 40 | + |
| 41 | + ans = connection[ancs.AppleNotificationCenterService] |
| 42 | + for notification in ans.wait_for_new_notifications(): |
| 43 | + print("new notification:", notification) |
| 44 | + |
| 45 | + print("Notifications:", len(ans.active_notifications)) |
| 46 | + for nid, n in ans.active_notifications.items(): |
| 47 | + print( |
| 48 | + "uid:", |
| 49 | + n.id, |
| 50 | + "cat:", |
| 51 | + n.category_id, |
| 52 | + "title:", |
| 53 | + n.title, |
| 54 | + "msg:", |
| 55 | + n.message, |
| 56 | + ) |
| 57 | + if n.category_id == 1: # incoming call, has positive & negative actions |
| 58 | + if butA.value: |
| 59 | + print("accepting call") |
| 60 | + n.send_positive_action() |
| 61 | + if butB.value: |
| 62 | + print("declining call") |
| 63 | + n.send_negative_action() |
| 64 | + if n.category_id == 12: # active call, only has negative action |
| 65 | + if butB.value: |
| 66 | + print("hanging up call") |
| 67 | + n.send_negative_action() |
| 68 | + time.sleep(1) |
| 69 | + |
| 70 | +print("disconnected") |
0 commit comments