Skip to content

Commit d777c3a

Browse files
committed
Made ams work
1 parent 9bda79f commit d777c3a

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

CircuitPython_Pyloton/code.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,29 @@
1818
pyloton = pyloton.Pyloton(ble, display, 84.229)
1919
pyloton.show_splash()
2020

21+
pyloton.ams_connect()
22+
2123
hr_connection = None
22-
# Start with a fresh connection.
23-
if ble.connected:
24-
for connection in ble.connections:
25-
if HeartRateService in connection:
26-
connection.disconnect()
27-
break
2824

2925
start = time.time()
3026
hr_connection = None
31-
speed_cad_connection = []
27+
speed_cad_connections = []
3228
radio = None
3329
while True:
3430
if not hr_connection:
3531
print("Running hr_connection")
3632
hr_connection = pyloton.heart_connect()
3733
ble.stop_scan()
38-
if not speed_cad_connection:
34+
if not speed_cad_connections:
3935
print("Running speed_cad_connection")
40-
speed_cad_connection = pyloton.speed_cad_connect()
41-
if not radio:
42-
print("Running ams_connection")
43-
radio = pyloton.ams_connect()
36+
speed_cad_connections = pyloton.speed_cad_connect()
4437

4538
if time.time()-start >= 45:
4639
pyloton.timeout()
4740
break
4841
# Stop scanning whether or not we are connected.
4942
ble.stop_scan()
50-
if hr_connection and hr_connection.connected and speed_cad_connection and radio.connected:
43+
if hr_connection and hr_connection.connected and speed_cad_connections:
5144
print("Fetch connection")
5245
hr_service = hr_connection[HeartRateService]
5346
print("Location:", hr_service.location)

CircuitPython_Pyloton/pyloton.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from adafruit_display_shapes.rect import Rect
1111
from adafruit_display_text import label
1212

13-
from adafruit_ble_apple_media import AppleMediaService
13+
from adafruit_ble_apple_media import AppleMediaService
1414

1515

1616
class Pyloton:
@@ -164,13 +164,16 @@ def ams_connect(self):
164164

165165
self._status_update("Connected")
166166

167+
known_notifications = set()
168+
167169
for connection in radio.connections:
168170
if not connection.paired:
169171
connection.pair()
170172
self._status_update("paired")
171-
known_notifications = set()
173+
174+
self.ams = connection[AppleMediaService]
175+
172176
self.radio = radio
173-
return self.radio
174177

175178

176179
def speed_cad_connect(self):
@@ -270,11 +273,13 @@ def icon_maker(self, n, icon_x, icon_y):
270273
return sprite
271274

272275

273-
def _label_maker(self, text, x, y):
276+
def _label_maker(self, text, x, y, font=None):
274277
"""
275278
Generates labels
276279
"""
277-
return label.Label(font=self.arial24, x=x, y=y, text=text, color=self.WHITE)
280+
if not font:
281+
font = self.arial24
282+
return label.Label(font=font, x=x, y=y, text=text, color=self.WHITE)
278283

279284

280285
def _get_y(self):
@@ -362,13 +367,14 @@ def update_display(self, hr_service):
362367
self.splash.append(cad_label)
363368

364369
if self.ams_enabled:
365-
ams_label = self._label_maker('None', 50, self.ams_y) # 210
370+
ams_label = self._label_maker('{}'.format(self.ams.title), 50, self.ams_y, font=self.arial16) # 210
366371
if self.setup:
367372
self.splash[6] = ams_label
368373
else:
369374
self.splash.append(ams_label)
370375

371376

372377
self.setup=True
378+
time.sleep(0.1)
373379

374380
self.display.show(self.splash)

0 commit comments

Comments
 (0)