From 742e86dea54eaed4db8cad82835c7c946f40f8e4 Mon Sep 17 00:00:00 2001 From: nasrlol Date: Mon, 18 Nov 2024 21:40:07 +0100 Subject: fixed some minor bugs within the code (sytax bugs) --- bin/__pycache__/i2c.cpython-312.pyc | Bin 0 -> 4218 bytes bin/main.py | 61 +++++++++++++++++------------------- bin/test | Bin 0 -> 16016 bytes 3 files changed, 28 insertions(+), 33 deletions(-) create mode 100644 bin/__pycache__/i2c.cpython-312.pyc create mode 100755 bin/test (limited to 'bin') diff --git a/bin/__pycache__/i2c.cpython-312.pyc b/bin/__pycache__/i2c.cpython-312.pyc new file mode 100644 index 0000000..a2ea22c Binary files /dev/null and b/bin/__pycache__/i2c.cpython-312.pyc differ diff --git a/bin/main.py b/bin/main.py index d126502..60978bb 100644 --- a/bin/main.py +++ b/bin/main.py @@ -2,7 +2,7 @@ import time import os import speech_recognition as speech import sounddevice -import i2c as LCD +import i2c as lcd from gpiozero import CPUTemperature ERROR_BAD_REQUEST = "400 Bad Request" @@ -10,75 +10,71 @@ ERROR_UNAUTHORIZED = "401 Unauthorized" ERROR_NOT_FOUND = "404 Not Found" ERROR_TIMEOUT = "408 Request Timeout" -lcd = LCD() +lcd_instance = lcd.LCD() cpu_temp = CPUTemperature() recognizer = speech.Recognizer() microphone = speech.Microphone() def display_cpu_info(): - lcd.clear() + lcd_instance.clear() while True: load = os.getloadavg()[0] temperature = cpu_temp.temperature - lcd.clear() - lcd.display_text(f"CPU Load:i {load}", 1) - lcd.display_text(f"Temp: {temperature:}C", 2) + lcd_instance.clear() + lcd_instance.display_text(f"CPU Load: {load}", 1) + lcd_instance.display_text(f"Temp: {temperature:.1f}C", 2) time.sleep(5) def display_uptime(): - lcd.clear() + lcd_instance.clear() with open("/proc/uptime") as f: uptime_seconds = float(f.readline().split()[0]) uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) - lcd.clear() - lcd.display_text(f"Uptime: {uptime_str}", 1, "center") + lcd_instance.clear() + lcd_instance.display_text(f"Uptime: {uptime_str}", 1, "center") def recognize_speech(): - lcd.clear() + lcd_instance.clear() try: with microphone as source: recognizer.adjust_for_ambient_noise(source) print("Listening...") audio = recognizer.listen(source) text = recognizer.recognize_google(audio) - lcd.clear() - lcd.display_text(text, 1) + lcd_instance.clear() + lcd_instance.display_text(text, 1) print("Speech recognized:", text) except speech.UnknownValueError: - lcd.display_text(ERROR_BAD_REQUEST, 1) + lcd_instance.display_text(ERROR_BAD_REQUEST, 1) print(ERROR_BAD_REQUEST) except speech.RequestError: - lcd.display_text(ERROR_UNAUTHORIZED, 1) + lcd_instance.display_text(ERROR_UNAUTHORIZED, 1) print(ERROR_UNAUTHORIZED) def save_notes(): - PRINT_REQUEST = True - EXIT_CODES = ["stop", "break", "quit", "exit"] - if PRINT_REQUEST == True: - while True: - OUTPUT = input() - print(OUTPUT) - lcd.display_text(OUTPUT, 1) - time.sleep(2) - for i in EXIT_CODES: - if OUTPUT == i: - PRINT_REQUEST == False + print("Type your notes (type 'stop' to exit):") + while True: + output = input() + if output.lower() in ["stop", "break", "quit", "exit"]: + break + lcd_instance.display_text(output, 1) + time.sleep(2) OPTIONS = { - "CPU_INFO": display_cpu_info(), - "UPTIME": display_uptime(), - "SPEECH_TRANSCRIBER": recognize_speech(), - "NOTES": save_notes(), + "CPU_INFO": display_cpu_info, + "UPTIME": display_uptime, + "SPEECH_TRANSCRIBER": recognize_speech, + "NOTES": save_notes, } def main(): - lcd.clear() + lcd_instance.clear() print("WELCOME TO THE I2C COMMAND LINE CENTER") print("Options:", ", ".join(OPTIONS.keys())) @@ -89,17 +85,16 @@ def main(): if action: action() else: - lcd.display_text(ERROR_NOT_FOUND, 1) + lcd_instance.display_text(ERROR_NOT_FOUND, 1) print(ERROR_NOT_FOUND) def destroy(): - lcd.clear() + lcd_instance.clear() os.system("cls" if os.name == "nt" else "clear") if __name__ == "__main__": - os.system("cls" if os.name == "nt" else "clear") try: main() except KeyboardInterrupt: diff --git a/bin/test b/bin/test new file mode 100755 index 0000000..180427d Binary files /dev/null and b/bin/test differ -- cgit v1.2.3-70-g09d2