From 5a951d3b64aeace1af900bc58500ea5528d2f75c Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Thu, 3 Nov 2022 22:55:02 +0000 Subject: [PATCH] Further simplify for this example --- .../computer/display_arena_from_robot.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ch-13/1-modelling-space/computer/display_arena_from_robot.py b/ch-13/1-modelling-space/computer/display_arena_from_robot.py index 548a4dd..8875729 100644 --- a/ch-13/1-modelling-space/computer/display_arena_from_robot.py +++ b/ch-13/1-modelling-space/computer/display_arena_from_robot.py @@ -11,25 +11,22 @@ class RobotDisplay: self.ble_connection = BleConnection(self.handle_data) self.line = "" - self.arena = None self.display_closed = False def handle_close(self, _): self.display_closed = True def handle_data(self, data): - line_part = data.decode("utf-8") - self.line += line_part + self.line += data.decode("utf-8") if not self.line.endswith("\n"): return print(f"Received data: {self.line}") - data = json.loads(self.line) + message = json.loads(self.line) self.line = "" - if "arena" in data: - self.update(data) + if "arena" in message: + self.update_arena(message) - def update(self, arena): - self.arena = arena + def update_arena(self, arena): plt.gca().clear() for line in arena["arena"]: plt.gca().plot(