diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-13 08:28:29 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-13 08:28:29 +0100 |
| commit | 9ebcbfc83a64b8a27d0725dbd12f6a8fdb042934 (patch) | |
| tree | f6a053d80f44265ffb28d0b932cb12571f315543 /bin | |
| parent | 545d44d84a3b61977ffbd55952e62a0f9bee8d9d (diff) | |
| parent | 1b9748da64281bc6fe5a808e744922ecc72fc6ba (diff) | |
Merge branch 'main' of https://github.com/nasrlol/I2C
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/kasper_gui.py | 7 | ||||
| -rw-r--r-- | bin/kasper_source.py | 46 |
2 files changed, 32 insertions, 21 deletions
diff --git a/bin/kasper_gui.py b/bin/kasper_gui.py index d94784d..e5edc6a 100644 --- a/bin/kasper_gui.py +++ b/bin/kasper_gui.py @@ -1,11 +1,6 @@ import tkinter -from tkinter import PhotoImage display = tkinter.Tk() display.title("Kasper") -photo = PhotoImage(file="icon.png") -display.iconphoto(False, photo) -# making 2 versions IOS AND DESKTOP -# with swiftUI -display.mainloop() +display.mainloop()
\ No newline at end of file diff --git a/bin/kasper_source.py b/bin/kasper_source.py index f4f7947..8067997 100644 --- a/bin/kasper_source.py +++ b/bin/kasper_source.py @@ -1,8 +1,9 @@ -from smbus2 import SMBus +from smbus import SMBus from gpiozero import CPUTemperature -import speech_recognition as sr +import speech_recognition as speech import os import time +from time import sleep # LCD Constants LCD_BACKLIGHT = 0x08 @@ -17,9 +18,9 @@ ERROR_UNAUTHORIZED = "401 Unauthorized" ERROR_NOT_FOUND = "404 Not Found" ERROR_TIMEOUT = "408 Request Timeout" - # LCD Control Class class LCD: + def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True): self.address = address self.bus = SMBus(bus) @@ -62,36 +63,41 @@ class LCD: self.backlight_status = turn_on self.write(0) - # Initialize components lcd = LCD() cpu_temp = CPUTemperature() -recognizer = sr.Recognizer() -microphone = sr.Microphone() +recognizer = speech.Recognizer() +microphone = speech.Microphone() # Display Functions def display_cpu_info(): + # clearing the display before accessing it + lcd.clear() """Display CPU load and temperature on the LCD.""" while True: load = os.getloadavg()[0] # 1-minute load average temperature = cpu_temp.temperature lcd.clear() - lcd.display_text(f"CPU Load: {load:.2f}", line=1) - lcd.display_text(f"Temp: {temperature:.1f}C", line=2) + lcd.display_text(f"CPU Load: {load:.2f}", 1) + lcd.display_text(f"Temp: {temperature:.1f}C", 2) time.sleep(5) def display_uptime(): + # clearing the display before accessing it + lcd.clear() """Display system uptime on the LCD.""" 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}", line=1) + lcd.display_text(f"Uptime: {uptime_str}", 1) def recognize_speech(): + # clearing the display before accessing it + lcd.clear() """Capture and transcribe speech input.""" try: with microphone as source: @@ -100,25 +106,35 @@ def recognize_speech(): audio = recognizer.listen(source) text = recognizer.recognize_google(audio) lcd.clear() - lcd.display_text(text, line=1) + lcd.display_text(text, 1) print("Speech recognized:", text) - except sr.UnknownValueError: - lcd.display_text(ERROR_BAD_REQUEST, line=1) + except speech.UnknownValueError: + lcd.display_text(ERROR_BAD_REQUEST, 1) print(ERROR_BAD_REQUEST) - except sr.RequestError: - lcd.display_text(ERROR_UNAUTHORIZED, line=1) + except speech.RequestError: + lcd.display_text(ERROR_UNAUTHORIZED, 1) print(ERROR_UNAUTHORIZED) +def notes(): + while True: + OUTPUT = input() + print(OUTPUT) + lcd.display_text(OUTPUT, 1) + sleep(2) + # Main Program Options OPTIONS = { "CPU_INFO": display_cpu_info, "UPTIME": display_uptime, "SPEECH_TRANSCRIBER": recognize_speech, + "NOTES": notes, } def main(): + # clearing the display before doing anything + lcd.clear() # Main program loop to accept user commands. print("WELCOME TO THE I2C COMMAND LINE CENTER") print("Options:", ", ".join(OPTIONS.keys())) @@ -130,7 +146,7 @@ def main(): if action: action() else: - lcd.display_text(ERROR_NOT_FOUND, line=1) + lcd.display_text(ERROR_NOT_FOUND, 1) print(ERROR_NOT_FOUND) |
