diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-24 01:31:48 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-24 01:31:48 +0100 |
| commit | 4b7da2645370361dfdb175129a24369e0cc0f977 (patch) | |
| tree | 8f7531ad6b68b5bcc9c1b7f0146fedcd9b15e6f1 | |
| parent | cc8792b3150f7b7f0a5a297dedd78295d4031c68 (diff) | |
worked on the GUI for the application, added a couple of new features, updated the readme, added a quotes file for making a daily quote feature thats going to reset at midnight, also did some small bug fixing
| -rw-r--r-- | bin/display.c | 30 | ||||
| -rw-r--r-- | bin/display_driver.c | 53 | ||||
| -rwxr-xr-x | bin/gtk_app | bin | 0 -> 51400 bytes | |||
| -rw-r--r-- | bin/hardware_driver.py (renamed from bin/i2c.py) | 0 | ||||
| -rw-r--r-- | bin/main.py | 102 | ||||
| -rw-r--r-- | bin/quotes.txt | 30 |
6 files changed, 172 insertions, 43 deletions
diff --git a/bin/display.c b/bin/display.c deleted file mode 100644 index b960ff1..0000000 --- a/bin/display.c +++ /dev/null | |||
| @@ -1,30 +0,0 @@ | |||
| 1 | #include <gtk/gtk.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | |||
| 6 | static void activate(GtkApplication *app, gpointer user_data) { | ||
| 7 | // Create a new application window | ||
| 8 | GtkWidget *window = gtk_application_window_new(app); | ||
| 9 | gtk_window_set_title(GTK_WINDOW(window), "I2C CONTROLLER"); | ||
| 10 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 200); | ||
| 11 | |||
| 12 | // Show the window | ||
| 13 | gtk_window_present(GTK_WINDOW(window)); | ||
| 14 | } | ||
| 15 | |||
| 16 | int main(int argc, char *argv[]) { | ||
| 17 | // Create a new GtkApplication | ||
| 18 | GtkApplication *app = gtk_application_new("com.example.GTK4Test", G_APPLICATION_FLAGS_NONE); | ||
| 19 | |||
| 20 | // Connect the activate signal | ||
| 21 | g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); | ||
| 22 | |||
| 23 | // Run the application | ||
| 24 | int status = g_application_run(G_APPLICATION(app), argc, argv); | ||
| 25 | |||
| 26 | // Clean up | ||
| 27 | g_object_unref(app); | ||
| 28 | |||
| 29 | return status; | ||
| 30 | } | ||
diff --git a/bin/display_driver.c b/bin/display_driver.c new file mode 100644 index 0000000..04f2900 --- /dev/null +++ b/bin/display_driver.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #include <gtk/gtk.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | // Define the features array | ||
| 6 | char *features[] = {"recourses", "greeting", "pomodoro", "weather", "speech", "command center"}; | ||
| 7 | |||
| 8 | // Function to create a button with a label | ||
| 9 | void create_button(const char *label) { | ||
| 10 | GtkWidget *button = gtk_button_new_with_label(label); | ||
| 11 | // You can set the button properties or add it to a container here | ||
| 12 | g_print("Button created: %s\n", label); // For debugging purposes | ||
| 13 | } | ||
| 14 | |||
| 15 | static void activate(GtkApplication *app, gpointer user_data) { | ||
| 16 | // Create the window | ||
| 17 | GtkWidget *window = gtk_application_window_new(app); | ||
| 18 | gtk_window_set_title(GTK_WINDOW(window), "I2C CONTROLLER"); | ||
| 19 | gtk_window_set_default_size(GTK_WINDOW(window), 400, 400); | ||
| 20 | |||
| 21 | // Create a container for buttons (e.g., vertical box) | ||
| 22 | GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); | ||
| 23 | gtk_container_add(GTK_CONTAINER(window), vbox); | ||
| 24 | |||
| 25 | // Calculate the number of features | ||
| 26 | int features_count = sizeof(features) / sizeof(features[0]); | ||
| 27 | |||
| 28 | // Create a button for each feature | ||
| 29 | for (int i = 0; i < features_count; i++) { | ||
| 30 | GtkWidget *button = gtk_button_new_with_label(features[i]); | ||
| 31 | gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); | ||
| 32 | gtk_widget_set_size_request(button, 200, 100); | ||
| 33 | } | ||
| 34 | |||
| 35 | // Show all widgets | ||
| 36 | gtk_widget_show_all(window); | ||
| 37 | } | ||
| 38 | |||
| 39 | int main(int argc, char *argv[]) { | ||
| 40 | // Create the application | ||
| 41 | GtkApplication *app = gtk_application_new("com.example.GTK4Test", G_APPLICATION_FLAGS_NONE); | ||
| 42 | |||
| 43 | // Connect the "activate" signal to the callback function | ||
| 44 | g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); | ||
| 45 | |||
| 46 | // Run the application | ||
| 47 | int status = g_application_run(G_APPLICATION(app), argc, argv); | ||
| 48 | |||
| 49 | // Clean up | ||
| 50 | g_object_unref(app); | ||
| 51 | |||
| 52 | return status; | ||
| 53 | } | ||
diff --git a/bin/gtk_app b/bin/gtk_app new file mode 100755 index 0000000..4d1dc8c --- /dev/null +++ b/bin/gtk_app | |||
| Binary files differ | |||
diff --git a/bin/i2c.py b/bin/hardware_driver.py index 1afb219..1afb219 100644 --- a/bin/i2c.py +++ b/bin/hardware_driver.py | |||
diff --git a/bin/main.py b/bin/main.py index 17b506d..bf556ca 100644 --- a/bin/main.py +++ b/bin/main.py | |||
| @@ -2,12 +2,13 @@ import time | |||
| 2 | import os | 2 | import os |
| 3 | import speech_recognition as speech | 3 | import speech_recognition as speech |
| 4 | import sounddevice | 4 | import sounddevice |
| 5 | import i2c as lcd | 5 | import bin.hardware_driver as lcd |
| 6 | from gpiozero import CPUTemperature | 6 | from gpiozero import CPUTemperature |
| 7 | 7 | ||
| 8 | ERROR_BAD_REQUEST = "400 Bad Request" | 8 | ERROR_BAD_REQUEST = "400 Bad Request" |
| 9 | ERROR_UNAUTHORIZED = "401 Unauthorized" | 9 | ERROR_UNAUTHORIZED = "401 Unauthorized" |
| 10 | ERROR_NOT_FOUND = "404 Not Found" | 10 | ERROR_NOT_FOUND = "404 Not Found" |
| 11 | SPEECH_NOT_RECOGNIZED = "404-1 Speech is not recognized" | ||
| 11 | ERROR_TIMEOUT = "408 Request Timeout" | 12 | ERROR_TIMEOUT = "408 Request Timeout" |
| 12 | 13 | ||
| 13 | lcd_instance = lcd.LCD() | 14 | lcd_instance = lcd.LCD() |
| @@ -16,7 +17,46 @@ recognizer = speech.Recognizer() | |||
| 16 | microphone = speech.Microphone() | 17 | microphone = speech.Microphone() |
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | def display_cpu_info(): | 20 | # greeting that starts upon the boot of the device: |
| 21 | # shows a hello line; shorter than 16 chars | ||
| 22 | # and some small information on the second line | ||
| 23 | def custom_greeting(): | ||
| 24 | with open('quotes.txt', 'r') as file: | ||
| 25 | quotes = file.readlines() | ||
| 26 | |||
| 27 | # Strip newline characters and use the quotes | ||
| 28 | quotes = [quote.strip() for quote in quotes] | ||
| 29 | |||
| 30 | # Print the quotes | ||
| 31 | for quote in quotes: | ||
| 32 | print(quote) | ||
| 33 | first_line = "" | ||
| 34 | second_line = "" | ||
| 35 | count = 0 | ||
| 36 | for i in quote: | ||
| 37 | if count < 16: | ||
| 38 | first_line += i | ||
| 39 | count += 1 | ||
| 40 | else: | ||
| 41 | second_line += i | ||
| 42 | lcd.text(first_line,1) | ||
| 43 | lcd.text(secon_line,2) | ||
| 44 | def pomodoro(): | ||
| 45 | time = input("How long do you want to wait? : ") | ||
| 46 | print("Okay \nStarting Now...") | ||
| 47 | while time > 0: | ||
| 48 | time.sleep(1) | ||
| 49 | print(time + "Seconds") | ||
| 50 | lcd.text(time + " Seconds remaining...", 1) | ||
| 51 | time -= 1 | ||
| 52 | |||
| 53 | |||
| 54 | def weather(): | ||
| 55 | pass | ||
| 56 | |||
| 57 | |||
| 58 | # ram usage, internet speed, | ||
| 59 | def system_readings(): | ||
| 20 | lcd_instance.clear() | 60 | lcd_instance.clear() |
| 21 | while True: | 61 | while True: |
| 22 | load = os.getloadavg()[0] | 62 | load = os.getloadavg()[0] |
| @@ -37,6 +77,7 @@ def display_uptime(): | |||
| 37 | 77 | ||
| 38 | 78 | ||
| 39 | def recognize_speech(): | 79 | def recognize_speech(): |
| 80 | |||
| 40 | lcd_instance.clear() | 81 | lcd_instance.clear() |
| 41 | try: | 82 | try: |
| 42 | with microphone as source: | 83 | with microphone as source: |
| @@ -46,6 +87,7 @@ def recognize_speech(): | |||
| 46 | text = recognizer.recognize_google(audio) | 87 | text = recognizer.recognize_google(audio) |
| 47 | lcd_instance.clear() | 88 | lcd_instance.clear() |
| 48 | lcd_instance.text(text, 1) | 89 | lcd_instance.text(text, 1) |
| 90 | |||
| 49 | print("Speech recognized:", text) | 91 | print("Speech recognized:", text) |
| 50 | except speech.UnknownValueError: | 92 | except speech.UnknownValueError: |
| 51 | lcd_instance.text(ERROR_BAD_REQUEST, 1) | 93 | lcd_instance.text(ERROR_BAD_REQUEST, 1) |
| @@ -54,6 +96,8 @@ def recognize_speech(): | |||
| 54 | lcd_instance.text(ERROR_UNAUTHORIZED, 1) | 96 | lcd_instance.text(ERROR_UNAUTHORIZED, 1) |
| 55 | print(ERROR_UNAUTHORIZED) | 97 | print(ERROR_UNAUTHORIZED) |
| 56 | 98 | ||
| 99 | return text | ||
| 100 | |||
| 57 | 101 | ||
| 58 | def save_notes(): | 102 | def save_notes(): |
| 59 | print("Type your notes (type 'stop' to exit):") | 103 | print("Type your notes (type 'stop' to exit):") |
| @@ -61,32 +105,64 @@ def save_notes(): | |||
| 61 | while True: | 105 | while True: |
| 62 | line = 1 | 106 | line = 1 |
| 63 | output = input(":") | 107 | output = input(":") |
| 108 | output_length = len(output) | ||
| 64 | if output.lower() in ["stop", "break", "quit", "exit"]: | 109 | if output.lower() in ["stop", "break", "quit", "exit"]: |
| 65 | break | 110 | break |
| 66 | if output == "line=1": | 111 | if output == "line=1": |
| 67 | line = 1 | 112 | line = 1 |
| 68 | elif output == "line=2": | 113 | elif output == "line=2": |
| 69 | line = 2 | 114 | line = 2 |
| 70 | lcd_instance.text(output, line) | 115 | |
| 71 | time.sleep(2) | 116 | if output_length < 16: |
| 117 | lcd_instance.text(output, line) | ||
| 118 | time.sleep(2) | ||
| 119 | else: | ||
| 120 | output_list = output.split("") | ||
| 121 | first_line = "" | ||
| 122 | second_line = "" | ||
| 123 | for i in output_list: | ||
| 124 | count = 0 | ||
| 125 | if count > 16: | ||
| 126 | first_line += output_list[i] | ||
| 127 | count += 1 | ||
| 128 | else: | ||
| 129 | second_line += output_list[i] | ||
| 130 | lcd.text(first_line,1) | ||
| 131 | lcd.text(secon_line,2) | ||
| 132 | |||
| 133 | def command_center(commands): | ||
| 134 | # checking if we can reconize commands within the user speech | ||
| 135 | # requires -> | ||
| 136 | # converting the commands to human readable text | ||
| 137 | # no under scars | ||
| 138 | command = recognize_speech() | ||
| 139 | list = [] | ||
| 140 | try: | ||
| 141 | for i in commands: | ||
| 142 | if i == command: | ||
| 143 | print("I think i found what you ment...") | ||
| 144 | command() | ||
| 145 | except: | ||
| 146 | print("ERROR 404 - COMMAND NOT RECOGNIZED") | ||
| 72 | 147 | ||
| 73 | 148 | ||
| 74 | OPTIONS = { | 149 | FEATURES = { |
| 75 | "CPU_INFO": display_cpu_info, | 150 | "READINGS": system_readings, |
| 76 | "UPTIME": display_uptime, | 151 | "UPTIME": display_uptime, |
| 77 | "SPEECH_TRANSCRIBER": recognize_speech, | 152 | "SPEECH_TRANSCRIBER": recognize_speech, |
| 78 | "NOTES": save_notes, | 153 | "NOTES": save_notes, |
| 79 | } | 154 | "COMMAND CENTER": command_center, |
| 155 | } | ||
| 80 | 156 | ||
| 81 | 157 | ||
| 82 | def main(): | 158 | def main(): |
| 83 | lcd_instance.clear() | 159 | lcd_instance.clear() |
| 84 | print("WELCOME TO THE I2C COMMAND LINE CENTER") | 160 | os.system("cls" if os.name == "nt" else "clear") |
| 85 | print("Options:", ", ".join(OPTIONS.keys())) | 161 | print("FEATURES:", ", ".join(FEATURES.keys())) |
| 86 | 162 | ||
| 87 | while True: | 163 | while True: |
| 88 | user_input = input("Enter command: ").upper() | 164 | user_input = input("Enter command: ").upper() |
| 89 | action = OPTIONS.get(user_input) | 165 | action = FEATURES.get(user_input) |
| 90 | 166 | ||
| 91 | if action: | 167 | if action: |
| 92 | action() | 168 | action() |
diff --git a/bin/quotes.txt b/bin/quotes.txt new file mode 100644 index 0000000..a6c9d84 --- /dev/null +++ b/bin/quotes.txt | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | “Code is like humor, it’s better if it’s clean.” | ||
| 2 | “Software is a great combination.” | ||
| 3 | “Computers are like a bicycle for the mind.” | ||
| 4 | “Simplicity is the soul of efficiency.” | ||
| 5 | “Good code is its own best documentation.” | ||
| 6 | “In programming, clarity is key.” | ||
| 7 | “Programs must be written for people.” | ||
| 8 | “Computers are only tools.” | ||
| 9 | “The best way to predict the future is to invent it.” | ||
| 10 | “Talk is cheap. Show me the code.” | ||
| 11 | "It’s not a bug, it’s a feature.” | ||
| 12 | “The computer is mightier than the pen.” | ||
| 13 | "Code is the art of telling computers what to do.” | ||
| 14 | "Make it work, make it right, make it fast.” | ||
| 15 | “Every problem can be solved with code.” | ||
| 16 | “The only limit is your imagination.” | ||
| 17 | “Programming is thinking, not typing.” | ||
| 18 | "Design is the soul of programming.” | ||
| 19 | “There’s no place like 127.0.0.1.” | ||
| 20 | “Without algorithms, there’s no solution.” | ||
| 21 | “Compilers turn ideas into machine code.” | ||
| 22 | “A program is only as good as its design.” | ||
| 23 | "Code never lies, comments sometimes do.” | ||
| 24 | “Debugging is twice as hard as writing.” | ||
| 25 | "Computers don’t make mistakes, programmers do.” | ||
| 26 | “Code fast, debug slow, optimize last.” | ||
| 27 | “Keep it simple, stupid (KISS).” | ||
| 28 | “Without testing, code is poetry.” | ||
| 29 | “Good software comes from great design.” | ||
| 30 | “The harder you work, the luckier you get.” | ||
