Updated these
This commit is contained in:
parent
88d2477f41
commit
6031ebae1d
2 changed files with 28 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ if ble.connected:
|
|||
start = time.time()
|
||||
hr_connection = None
|
||||
speed_cad_connection = []
|
||||
radio = None
|
||||
while True:
|
||||
if not hr_connection:
|
||||
print("Running hr_connection")
|
||||
|
|
@ -37,13 +38,16 @@ while True:
|
|||
if not speed_cad_connection:
|
||||
print("Running speed_cad_connection")
|
||||
speed_cad_connection = pyloton.speed_cad_connect()
|
||||
if not radio:
|
||||
print("Running ams_connection")
|
||||
radio = ams_connection
|
||||
|
||||
if time.time()-start >= 45:
|
||||
pyloton.timeout()
|
||||
break
|
||||
# Stop scanning whether or not we are connected.
|
||||
ble.stop_scan()
|
||||
if hr_connection and hr_connection.connected and speed_cad_connection:
|
||||
if hr_connection and hr_connection.connected and speed_cad_connection and radio.connected:
|
||||
print("Fetch connection")
|
||||
hr_service = hr_connection[HeartRateService]
|
||||
print("Location:", hr_service.location)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import time
|
||||
import adafruit_ble
|
||||
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
||||
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
|
||||
import displayio
|
||||
import adafruit_imageload
|
||||
from adafruit_ble_cycling_speed_and_cadence import CyclingSpeedAndCadenceService
|
||||
|
|
@ -8,6 +10,8 @@ from adafruit_bitmap_font import bitmap_font
|
|||
from adafruit_display_shapes.rect import Rect
|
||||
from adafruit_display_text import label
|
||||
|
||||
from adafruit_ble_apple_media import AppleMediaService
|
||||
|
||||
|
||||
class Pyloton:
|
||||
|
||||
|
|
@ -148,6 +152,25 @@ class Pyloton:
|
|||
break
|
||||
return self.hr_connection
|
||||
|
||||
def ams_connect(self):
|
||||
self.radio = adafruit_ble.BLERadio()
|
||||
a = SolicitServicesAdvertisement()
|
||||
a.solicited_services.append(AppleMediaService)
|
||||
self.radio.start_adversising(a)
|
||||
|
||||
while not self.radio.connected:
|
||||
pass
|
||||
|
||||
print("connected")
|
||||
|
||||
for connection in self.radio.connections:
|
||||
if not connection.paired:
|
||||
connection.pair()
|
||||
print("paired")
|
||||
known_notifications = set()
|
||||
|
||||
return self.radio
|
||||
|
||||
|
||||
def speed_cad_connect(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue