From 6ae14dad3988174b9101071f7729948295b9076a Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Feb 2020 21:27:37 -0500 Subject: [PATCH] Fixed bugs causing crashes --- CircuitPython_Pyloton/code.py | 3 ++- CircuitPython_Pyloton/pyloton.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CircuitPython_Pyloton/code.py b/CircuitPython_Pyloton/code.py index 8219098bc..986f4f37b 100644 --- a/CircuitPython_Pyloton/code.py +++ b/CircuitPython_Pyloton/code.py @@ -54,7 +54,8 @@ while True: pyloton.setup_display() while ((not HEART or hr_connection.connected) and - ((not SPEED or not CADENCE) or speed_cadence_connections[0].connected) and + ((not SPEED or not CADENCE) or + (speed_cadence_connections and speed_cadence_connections[0].connected)) and (not AMS or ams.connected)): pyloton.update_display() pyloton.ams_remote() diff --git a/CircuitPython_Pyloton/pyloton.py b/CircuitPython_Pyloton/pyloton.py index 9888d51b1..84dd5beaa 100644 --- a/CircuitPython_Pyloton/pyloton.py +++ b/CircuitPython_Pyloton/pyloton.py @@ -206,7 +206,7 @@ class Pyloton: if len(message) > 25: self.status.text = message[:25] - self.status1.text = message[25:] + self.status1.text = message[25:50] else: self.status.text = message @@ -382,6 +382,12 @@ class Pyloton: cadence = self._compute_cadence(values, cadence) + if speed: + if len(str(speed)) > 8: + speed = str(speed)[:8] + if cadence: + if len(str(cadence)) > 8: + cadence = str(cadence)[:8] return speed, cadence @@ -395,6 +401,9 @@ class Pyloton: else: heart = measurement.heart_rate self._previous_heart = measurement.heart_rate + if heart: + if len(str(heart)) > 4: + heart = str(heart)[:4] return heart @@ -412,9 +421,12 @@ class Pyloton: data = self.ams.artist if not self.track_artist: data = self.ams.title - except RuntimeError: + except (RuntimeError, UnicodeError): data = None + if data: + if len(data) > 20: + data = data[:20] return data