Fix live data refresh loop
This commit is contained in:
41
menu.py
41
menu.py
@@ -55,28 +55,39 @@ 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")
|
||||
print("\nLive Data")
|
||||
print("---------")
|
||||
|
||||
if rpm.is_null():
|
||||
print("RPM: Not supported")
|
||||
else:
|
||||
value = response.value
|
||||
print("RPM:", rpm.value)
|
||||
|
||||
if name == "Speed":
|
||||
value = value.to("mile_per_hour")
|
||||
if speed.is_null():
|
||||
print("Speed: Not supported")
|
||||
else:
|
||||
speed_mph = speed.value.to("mile_per_hour")
|
||||
print("Speed:", speed_mph)
|
||||
|
||||
elif name == "Coolant Temp":
|
||||
value = value.to("degF")
|
||||
if coolant.is_null():
|
||||
print("Coolant Temp: Not supported")
|
||||
else:
|
||||
coolant_f = coolant.value.to("degF")
|
||||
print("Coolant Temp:", coolant_f)
|
||||
|
||||
print(name + ":", value)
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopped live data")
|
||||
pause()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user