File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 29
29
start = time .time ()
30
30
hr_connection = None
31
31
speed_cad_connection = []
32
+ radio = None
32
33
while True :
33
34
if not hr_connection :
34
35
print ("Running hr_connection" )
37
38
if not speed_cad_connection :
38
39
print ("Running speed_cad_connection" )
39
40
speed_cad_connection = pyloton .speed_cad_connect ()
41
+ if not radio :
42
+ print ("Running ams_connection" )
43
+ radio = ams_connection
40
44
41
45
if time .time ()- start >= 45 :
42
46
pyloton .timeout ()
43
47
break
44
48
# Stop scanning whether or not we are connected.
45
49
ble .stop_scan ()
46
- if hr_connection and hr_connection .connected and speed_cad_connection :
50
+ if hr_connection and hr_connection .connected and speed_cad_connection and radio . connected :
47
51
print ("Fetch connection" )
48
52
hr_service = hr_connection [HeartRateService ]
49
53
print ("Location:" , hr_service .location )
Original file line number Diff line number Diff line change 1
1
import time
2
+ import adafruit_ble
2
3
from adafruit_ble .advertising .standard import ProvideServicesAdvertisement
4
+ from adafruit_ble .advertising .standard import SolicitServicesAdvertisement
3
5
import displayio
4
6
import adafruit_imageload
5
7
from adafruit_ble_cycling_speed_and_cadence import CyclingSpeedAndCadenceService
8
10
from adafruit_display_shapes .rect import Rect
9
11
from adafruit_display_text import label
10
12
13
+ from adafruit_ble_apple_media import AppleMediaService
14
+
11
15
12
16
class Pyloton :
13
17
@@ -148,6 +152,25 @@ def heart_connect(self):
148
152
break
149
153
return self .hr_connection
150
154
155
+ def ams_connect (self ):
156
+ self .radio = adafruit_ble .BLERadio ()
157
+ a = SolicitServicesAdvertisement ()
158
+ a .solicited_services .append (AppleMediaService )
159
+ self .radio .start_adversising (a )
160
+
161
+ while not self .radio .connected :
162
+ pass
163
+
164
+ print ("connected" )
165
+
166
+ for connection in self .radio .connections :
167
+ if not connection .paired :
168
+ connection .pair ()
169
+ print ("paired" )
170
+ known_notifications = set ()
171
+
172
+ return self .radio
173
+
151
174
152
175
def speed_cad_connect (self ):
153
176
"""
You can’t perform that action at this time.
0 commit comments