From 3f24ee0c93393903d44054b1aaf581bc7783e64e Mon Sep 17 00:00:00 2001 From: Zachary Nisen Date: Fri, 5 Jun 2026 12:31:30 -0600 Subject: [PATCH] Fix live data refresh loop --- menu.py | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/menu.py b/menu.py index 4eeec8c..a540c6e 100644 --- a/menu.py +++ b/menu.py @@ -55,29 +55,40 @@ def live_data(connection): pause() return - commands = [ - ("RPM", obd.commands.RPM), - ("Speed", obd.commands.SPEED), - ("Coolant Temp", obd.commands.COOLANT_TEMP), - ] + print("Live data running.") + print("Press Ctrl+C to stop and return to menu.\n") - for name, command in commands: - response = connection.query(command) + try: + while True: + rpm = connection.query(obd.commands.RPM) + speed = connection.query(obd.commands.SPEED) + coolant = connection.query(obd.commands.COOLANT_TEMP) - if response.is_null(): - print(name + ": Not supported") - else: - value = response.value + print("\nLive Data") + print("---------") - if name == "Speed": - value = value.to("mile_per_hour") + if rpm.is_null(): + print("RPM: Not supported") + else: + print("RPM:", rpm.value) - elif name == "Coolant Temp": - value = value.to("degF") + if speed.is_null(): + print("Speed: Not supported") + else: + speed_mph = speed.value.to("mile_per_hour") + print("Speed:", speed_mph) - print(name + ":", value) + if coolant.is_null(): + print("Coolant Temp: Not supported") + else: + coolant_f = coolant.value.to("degF") + print("Coolant Temp:", coolant_f) - pause() + time.sleep(1) + + except KeyboardInterrupt: + print("\nStopped live data") + pause() def vehicle_info(connection):