Skip to content

Commit 6ae14da

Browse files
committed
Fixed bugs causing crashes
1 parent 764f359 commit 6ae14da

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CircuitPython_Pyloton/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
pyloton.setup_display()
5555

5656
while ((not HEART or hr_connection.connected) and
57-
((not SPEED or not CADENCE) or speed_cadence_connections[0].connected) and
57+
((not SPEED or not CADENCE) or
58+
(speed_cadence_connections and speed_cadence_connections[0].connected)) and
5859
(not AMS or ams.connected)):
5960
pyloton.update_display()
6061
pyloton.ams_remote()

CircuitPython_Pyloton/pyloton.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def _status_update(self, message):
206206

207207
if len(message) > 25:
208208
self.status.text = message[:25]
209-
self.status1.text = message[25:]
209+
self.status1.text = message[25:50]
210210

211211
else:
212212
self.status.text = message
@@ -382,6 +382,12 @@ def read_s_and_c(self):
382382

383383
cadence = self._compute_cadence(values, cadence)
384384

385+
if speed:
386+
if len(str(speed)) > 8:
387+
speed = str(speed)[:8]
388+
if cadence:
389+
if len(str(cadence)) > 8:
390+
cadence = str(cadence)[:8]
385391
return speed, cadence
386392

387393

@@ -395,6 +401,9 @@ def read_heart(self):
395401
else:
396402
heart = measurement.heart_rate
397403
self._previous_heart = measurement.heart_rate
404+
if heart:
405+
if len(str(heart)) > 4:
406+
heart = str(heart)[:4]
398407
return heart
399408

400409

@@ -412,9 +421,12 @@ def read_ams(self):
412421
data = self.ams.artist
413422
if not self.track_artist:
414423
data = self.ams.title
415-
except RuntimeError:
424+
except (RuntimeError, UnicodeError):
416425
data = None
417426

427+
if data:
428+
if len(data) > 20:
429+
data = data[:20]
418430
return data
419431

420432

0 commit comments

Comments
 (0)