From 179976cf893a6a77769aed131e17b1ff6a775e70 Mon Sep 17 00:00:00 2001 From: Zachary Nisen Date: Wed, 3 Jun 2026 11:33:21 -0600 Subject: [PATCH] Initial OBD menu --- menu.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 menu.py diff --git a/menu.py b/menu.py new file mode 100644 index 0000000..d2d9de6 --- /dev/null +++ b/menu.py @@ -0,0 +1,133 @@ +import logging +import obd + +logging.getLogger("obd").setLevel(logging.CRITICAL) + + +def pause(): + input("\nPress ENTER to return to menu...") + + +def connect(): + print("Checking for OBD adapter...") + + connection = obd.OBD(fast=False) + + if connection.is_connected(): + print("Connected") + else: + print("No OBD device found") + + return connection + + +def read_codes(connection): + print("\nTrouble Codes") + print("-------------") + + if connection is None or not connection.is_connected(): + print("Not connected to vehicle") + pause() + return + + response = connection.query(obd.commands.GET_DTC) + + if response.is_null(): + print("Unable to read trouble codes") + elif response.value: + for code in response.value: + print(code) + else: + print("No trouble codes found") + + pause() + + +def live_data(connection): + print("\nLive Data") + print("---------") + + if connection is None or not connection.is_connected(): + print("Not connected to vehicle") + pause() + return + + commands = [ + ("RPM", obd.commands.RPM), + ("Speed", obd.commands.SPEED), + ("Coolant Temp", obd.commands.COOLANT_TEMP), + ] + + for name, command in commands: + response = connection.query(command) + + if response.is_null(): + print(name + ": Not supported") + else: + print(name + ":", response.value) + + pause() + + +def vehicle_info(connection): + print("\nVehicle Information") + print("-------------------") + + if connection is None or not connection.is_connected(): + print("Not connected to vehicle") + pause() + return + + vin = connection.query(obd.commands.VIN) + + if vin.is_null(): + print("VIN: Not available") + elif vin.value: + print("VIN:", vin.value) + else: + print("VIN: Not available") + + pause() + + +def main(): + connection = None + + while True: + print("\nOBD Tool") + + if connection is not None and connection.is_connected(): + print("Status: Connected") + else: + print("Status: Not Connected") + + print("_______________________") + print("1. Connect") + print("2. Read Codes") + print("3. Live Data") + print("4. Vehicle Info") + print("Q. Quit") + print("_______________________") + + choice = input("> ") + + if choice == "1": + connection = connect() + + elif choice == "2": + read_codes(connection) + + elif choice == "3": + live_data(connection) + + elif choice == "4": + vehicle_info(connection) + + elif choice.lower() == "q": + break + + else: + print("Invalid choice") + + +main()