Skip to content

Commit 954b600

Browse files
committed
Updated if statement checking if sensors are connected
1 parent 5ec85e1 commit 954b600

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

CircuitPython_Pyloton/code.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
HEART = True
1414
SPEED = True
15-
CAD = True
15+
CADENCE = True
1616
AMS = True
1717
DEBUG = False
1818

1919
# 84.229 is wheel circumference (700x23 in my case)
20-
pyloton = pyloton.Pyloton(ble, display, 84.229, HEART, SPEED, CAD, AMS, DEBUG)
20+
pyloton = pyloton.Pyloton(ble, display, 84.229, HEART, SPEED, CADENCE, AMS, DEBUG)
2121

2222
pyloton.show_splash()
2323

@@ -26,18 +26,18 @@
2626

2727
start = time()
2828
hr_connection = None
29-
speed_cad_connections = []
29+
speed_cadence_connections = []
3030
radio = None
3131
while True:
3232
if HEART:
3333
if not hr_connection:
3434
print("Attempting to connect to a heart rate monitor")
3535
hr_connection = pyloton.heart_connect()
3636
ble.stop_scan()
37-
if SPEED or CAD:
38-
if not speed_cad_connections:
37+
if SPEED or CADENCE:
38+
if not speed_cadence_connections:
3939
print("Attempting to connect to speed and cadence monitors")
40-
speed_cad_connections = pyloton.speed_cad_connect()
40+
speed_cadence_connections = pyloton.speed_cadence_connect()
4141

4242
if time()-start >= CONNECTION_TIMEOUT:
4343
pyloton.timeout()
@@ -49,15 +49,20 @@
4949
# devices you are using.
5050
# For example, remove hr_connection and hr_connection.connected if you aren't using a heart
5151
# rate monitor. Do the same for other sensors you aren't using.
52-
if hr_connection and speed_cad_connections and ams:
53-
if hr_connection.connected and speed_cad_connections[0].connected and ams.connected:
54-
pyloton.setup_display()
55-
break
52+
if ((not HEART or (hr_connection and hr_connection.connected)) and #pylint: disable=too-many-boolean-expressions
53+
((not SPEED and not CADENCE) or
54+
(speed_cadence_connections and speed_cadence_connections[0].connected)) and
55+
(not AMS or (ams and ams.connected))):
56+
break
57+
58+
pyloton.setup_display()
5659

5760
# You may need to remove some parts of the following line depending on what devices you are using.
5861
# For example, remove hr_connection and hr_connection.connected if you aren't using a heart rate
5962
# monitor. Do the same for other sensors you aren't using.
60-
while hr_connection.connected and speed_cad_connections[0].connected and ams.connected:
63+
while ((not HEART or hr_connection.connected) and
64+
((not SPEED or not CADENCE) or speed_cadence_connections[0].connected) and
65+
(not AMS or ams.connected)):
6166
pyloton.update_display()
6267
pyloton.ams_remote()
6368

0 commit comments

Comments
 (0)