diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-18 19:23:17 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-18 19:23:17 +0100 |
| commit | 2feb019c373c99fa3840d99724f5ee6f7c4dac36 (patch) | |
| tree | 9bf1d614b602149a0ef27078894d6a15ecb13ff0 /bin | |
| parent | 3714c08a1233884696e0f5483d73efa890e1a5a1 (diff) | |
started switching to c, started the web gui, started the gtk gui, ending the swift version
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/__pycache__/source.cpython-313.pyc | bin | 5737 -> 0 bytes | |||
| -rw-r--r-- | bin/display.c | 27 | ||||
| -rw-r--r-- | bin/i2c.py | 5 | ||||
| -rw-r--r-- | bin/main.py | 109 | ||||
| -rw-r--r-- | bin/source.py | 106 |
5 files changed, 134 insertions, 113 deletions
diff --git a/bin/__pycache__/source.cpython-313.pyc b/bin/__pycache__/source.cpython-313.pyc Binary files differdeleted file mode 100644 index 79aee1d..0000000 --- a/bin/__pycache__/source.cpython-313.pyc +++ /dev/null diff --git a/bin/display.c b/bin/display.c new file mode 100644 index 0000000..51a0873 --- /dev/null +++ b/bin/display.c @@ -0,0 +1,27 @@ +#include <gtk/gtk.h> + +static void activate(GtkApplication *app, gpointer user_data) { + // Create a new application window + GtkWidget *window = gtk_application_window_new(app); + gtk_window_set_title(GTK_WINDOW(window), "I2C CONTROLLER"); + gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); + + // Show the window + gtk_window_present(GTK_WINDOW(window)); +} + +int main(int argc, char *argv[]) { + // Create a new GtkApplication + GtkApplication *app = gtk_application_new("com.example.GTK4Test", G_APPLICATION_FLAGS_NONE); + + // Connect the activate signal + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); + + // Run the application + int status = g_application_run(G_APPLICATION(app), argc, argv); + + // Clean up + g_object_unref(app); + + return status; +}
\ No newline at end of file @@ -1,4 +1,4 @@ -from smbus import SMBus +from smbus2 import SMBus from time import sleep ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"} @@ -63,3 +63,6 @@ class LCD(object): def clear(self): self.write(CLEAR_DISPLAY) + + def read(self): + self._read_i2c_block_data diff --git a/bin/main.py b/bin/main.py index 2231547..921082f 100644 --- a/bin/main.py +++ b/bin/main.py @@ -1,9 +1,106 @@ -import tk -import source as main +import time +import os +import speech_recognition as speech +import sounddevice +import i2c as LCD +from gpiozero import CPUTemperature -source = main() +ERROR_BAD_REQUEST = "400 Bad Request" +ERROR_UNAUTHORIZED = "401 Unauthorized" +ERROR_NOT_FOUND = "404 Not Found" +ERROR_TIMEOUT = "408 Request Timeout" -display = tk.Tk() -display.title("Kasper") +lcd = LCD +cpu_temp = CPUTemperature() +recognizer = speech.Recognizer() +microphone = speech.Microphone() -display.mainloop()
\ No newline at end of file + +def display_cpu_info(): + lcd.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) + time.sleep(5) + + +def display_uptime(): + lcd.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") + + +def recognize_speech(): + lcd.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) + print("Speech recognized:", text) + except speech.UnknownValueError: + lcd.display_text(ERROR_BAD_REQUEST, 1) + print(ERROR_BAD_REQUEST) + except speech.RequestError: + lcd.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 + + +OPTIONS = { + "CPU_INFO": display_cpu_info(), + "UPTIME": display_uptime(), + "SPEECH_TRANSCRIBER": recognize_speech(), + "NOTES": save_notes(), +} + + +def main(): + lcd.clear() + print("WELCOME TO THE I2C COMMAND LINE CENTER") + print("Options:", ", ".join(OPTIONS.keys())) + + while True: + user_input = input("Enter command: ").upper() + action = OPTIONS.get(user_input) + + if action: + action() + else: + lcd.display_text(ERROR_NOT_FOUND, 1) + print(ERROR_NOT_FOUND) + + +def destroy(): + lcd.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: + destroy() diff --git a/bin/source.py b/bin/source.py deleted file mode 100644 index 485cc03..0000000 --- a/bin/source.py +++ /dev/null @@ -1,106 +0,0 @@ -import time -import os -import speech_recognition as speech -import sounddevice -import i2c as LCD -from gpiozero import CPUTemperature - -ERROR_BAD_REQUEST = "400 Bad Request" -ERROR_UNAUTHORIZED = "401 Unauthorized" -ERROR_NOT_FOUND = "404 Not Found" -ERROR_TIMEOUT = "408 Request Timeout" - -lcd = LCD -cpu_temp = CPUTemperature() -recognizer = speech.Recognizer() -microphone = speech.Microphone() - - -def display_cpu_info(): - lcd.clear() - while True: - load = os.getloadavg()[0] # 1-minute load average - temperature = cpu_temp.temperature - lcd.clear() - lcd.display_text(f"CPU Load:i {load}", 1) - lcd.display_text(f"Temp: {temperature:}C", 2) - time.sleep(5) - - -def display_uptime(): - lcd.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") - - -def recognize_speech(): - lcd.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) - print("Speech recognized:", text) - except speech.UnknownValueError: - lcd.display_text(ERROR_BAD_REQUEST, 1) - print(ERROR_BAD_REQUEST) - except speech.RequestError: - lcd.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 - - - -OPTIONS = { - "CPU_INFO": display_cpu_info(), - "UPTIME": display_uptime(), - "SPEECH_TRANSCRIBER": recognize_speech(), - "NOTES": save_notes(), -} - - -def main(): - lcd.clear() - print("WELCOME TO THE I2C COMMAND LINE CENTER") - print("Options:", ", ".join(OPTIONS.keys())) - - while True: - user_input = input("Enter command: ").upper() - action = OPTIONS.get(user_input) - - if action: - action() - else: - lcd.display_text(ERROR_NOT_FOUND, 1) - print(ERROR_NOT_FOUND) - - -def destroy(): - lcd.clear() - os.system("cls" if os.name == "nt" else "clear") - - -if __name__ == "__main__": - try: - main() - except KeyboardInterrupt: - destroy() |
