Skip to content

Commit 68c37d8

Browse files
authored
Merge pull request adafruit#1020 from dherrada/master
[WIP] Pyloton
2 parents 90f96ca + a42dc37 commit 68c37d8

File tree

8 files changed

+24085
-0
lines changed

8 files changed

+24085
-0
lines changed
19.5 KB
Binary file not shown.

CircuitPython_Pyloton/code.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from time import time
2+
import adafruit_ble
3+
import board
4+
import pyloton
5+
6+
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
7+
8+
CONNECTION_TIMEOUT = 45
9+
10+
HEART = True
11+
SPEED = True
12+
CADENCE = True
13+
AMS = True
14+
DEBUG = False
15+
16+
# 84.229 is wheel circumference (700x23 in my case)
17+
pyloton = pyloton.Pyloton(ble, board.DISPLAY, 84.229, HEART, SPEED, CADENCE, AMS, DEBUG)
18+
19+
pyloton.show_splash()
20+
21+
ams = pyloton.ams_connect()
22+
23+
24+
start = time()
25+
hr_connection = None
26+
speed_cadence_connections = []
27+
while True:
28+
if HEART:
29+
if not hr_connection:
30+
print("Attempting to connect to a heart rate monitor")
31+
hr_connection = pyloton.heart_connect()
32+
ble.stop_scan()
33+
if SPEED or CADENCE:
34+
if not speed_cadence_connections:
35+
print("Attempting to connect to speed and cadence monitors")
36+
speed_cadence_connections = pyloton.speed_cadence_connect()
37+
38+
if time()-start >= CONNECTION_TIMEOUT:
39+
pyloton.timeout()
40+
break
41+
# Stop scanning whether or not we are connected.
42+
ble.stop_scan()
43+
44+
#pylint: disable=too-many-boolean-expressions
45+
if ((not HEART or (hr_connection and hr_connection.connected)) and
46+
((not SPEED and not CADENCE) or
47+
(speed_cadence_connections and speed_cadence_connections[0].connected)) and
48+
(not AMS or (ams and ams.connected))):
49+
break
50+
51+
pyloton.setup_display()
52+
53+
while ((not HEART or hr_connection.connected) and
54+
((not SPEED or not CADENCE) or
55+
(speed_cadence_connections and speed_cadence_connections[0].connected)) and
56+
(not AMS or ams.connected)):
57+
pyloton.update_display()
58+
pyloton.ams_remote()
59+
60+
print("\n\nNot all sensors are connected. Please reset to try again\n\n")

0 commit comments

Comments
 (0)