summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2024-11-18 19:23:17 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2024-11-18 19:23:17 +0100
commit2feb019c373c99fa3840d99724f5ee6f7c4dac36 (patch)
tree9bf1d614b602149a0ef27078894d6a15ecb13ff0 /bin
parent3714c08a1233884696e0f5483d73efa890e1a5a1 (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.pycbin5737 -> 0 bytes
-rw-r--r--bin/display.c27
-rw-r--r--bin/i2c.py5
-rw-r--r--bin/main.py109
-rw-r--r--bin/source.py106
5 files changed, 134 insertions, 113 deletions
diff --git a/bin/__pycache__/source.cpython-313.pyc b/bin/__pycache__/source.cpython-313.pyc
deleted file mode 100644
index 79aee1d..0000000
--- a/bin/__pycache__/source.cpython-313.pyc
+++ /dev/null
Binary files differ
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 @@
1#include <gtk/gtk.h>
2
3static void activate(GtkApplication *app, gpointer user_data) {
4 // Create a new application window
5 GtkWidget *window = gtk_application_window_new(app);
6 gtk_window_set_title(GTK_WINDOW(window), "I2C CONTROLLER");
7 gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
8
9 // Show the window
10 gtk_window_present(GTK_WINDOW(window));
11}
12
13int main(int argc, char *argv[]) {
14 // Create a new GtkApplication
15 GtkApplication *app = gtk_application_new("com.example.GTK4Test", G_APPLICATION_FLAGS_NONE);
16
17 // Connect the activate signal
18 g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
19
20 // Run the application
21 int status = g_application_run(G_APPLICATION(app), argc, argv);
22
23 // Clean up
24 g_object_unref(app);
25
26 return status;
27} \ No newline at end of file
diff --git a/bin/i2c.py b/bin/i2c.py
index 75a3509..1afb219 100644
--- a/bin/i2c.py
+++ b/bin/i2c.py
@@ -1,4 +1,4 @@
1from smbus import SMBus 1from smbus2 import SMBus
2from time import sleep 2from time import sleep
3 3
4ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"} 4ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"}
@@ -63,3 +63,6 @@ class LCD(object):
63 63
64 def clear(self): 64 def clear(self):
65 self.write(CLEAR_DISPLAY) 65 self.write(CLEAR_DISPLAY)
66
67 def read(self):
68 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 @@
1import tk 1import time
2import source as main 2import os
3import speech_recognition as speech
4import sounddevice
5import i2c as LCD
6from gpiozero import CPUTemperature
3 7
4source = main() 8ERROR_BAD_REQUEST = "400 Bad Request"
9ERROR_UNAUTHORIZED = "401 Unauthorized"
10ERROR_NOT_FOUND = "404 Not Found"
11ERROR_TIMEOUT = "408 Request Timeout"
5 12
6display = tk.Tk() 13lcd = LCD
7display.title("Kasper") 14cpu_temp = CPUTemperature()
15recognizer = speech.Recognizer()
16microphone = speech.Microphone()
8 17
9display.mainloop() \ No newline at end of file 18
19def display_cpu_info():
20 lcd.clear()
21 while True:
22 load = os.getloadavg()[0]
23 temperature = cpu_temp.temperature
24 lcd.clear()
25 lcd.display_text(f"CPU Load:i {load}", 1)
26 lcd.display_text(f"Temp: {temperature:}C", 2)
27 time.sleep(5)
28
29
30def display_uptime():
31 lcd.clear()
32 with open("/proc/uptime") as f:
33 uptime_seconds = float(f.readline().split()[0])
34 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
35 lcd.clear()
36 lcd.display_text(f"Uptime: {uptime_str}", 1, "center")
37
38
39def recognize_speech():
40 lcd.clear()
41 try:
42 with microphone as source:
43 recognizer.adjust_for_ambient_noise(source)
44 print("Listening...")
45 audio = recognizer.listen(source)
46 text = recognizer.recognize_google(audio)
47 lcd.clear()
48 lcd.display_text(text, 1)
49 print("Speech recognized:", text)
50 except speech.UnknownValueError:
51 lcd.display_text(ERROR_BAD_REQUEST, 1)
52 print(ERROR_BAD_REQUEST)
53 except speech.RequestError:
54 lcd.display_text(ERROR_UNAUTHORIZED, 1)
55 print(ERROR_UNAUTHORIZED)
56
57
58def save_notes():
59 PRINT_REQUEST = True
60 EXIT_CODES = ["stop", "break", "quit", "exit"]
61 if PRINT_REQUEST == True:
62 while True:
63 OUTPUT = input()
64 print(OUTPUT)
65 lcd.display_text(OUTPUT, 1)
66 time.sleep(2)
67 for i in EXIT_CODES:
68 if OUTPUT == i:
69 PRINT_REQUEST == False
70
71
72OPTIONS = {
73 "CPU_INFO": display_cpu_info(),
74 "UPTIME": display_uptime(),
75 "SPEECH_TRANSCRIBER": recognize_speech(),
76 "NOTES": save_notes(),
77}
78
79
80def main():
81 lcd.clear()
82 print("WELCOME TO THE I2C COMMAND LINE CENTER")
83 print("Options:", ", ".join(OPTIONS.keys()))
84
85 while True:
86 user_input = input("Enter command: ").upper()
87 action = OPTIONS.get(user_input)
88
89 if action:
90 action()
91 else:
92 lcd.display_text(ERROR_NOT_FOUND, 1)
93 print(ERROR_NOT_FOUND)
94
95
96def destroy():
97 lcd.clear()
98 os.system("cls" if os.name == "nt" else "clear")
99
100
101if __name__ == "__main__":
102 os.system("cls" if os.name == "nt" else "clear")
103 try:
104 main()
105 except KeyboardInterrupt:
106 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 @@
1import time
2import os
3import speech_recognition as speech
4import sounddevice
5import i2c as LCD
6from gpiozero import CPUTemperature
7
8ERROR_BAD_REQUEST = "400 Bad Request"
9ERROR_UNAUTHORIZED = "401 Unauthorized"
10ERROR_NOT_FOUND = "404 Not Found"
11ERROR_TIMEOUT = "408 Request Timeout"
12
13lcd = LCD
14cpu_temp = CPUTemperature()
15recognizer = speech.Recognizer()
16microphone = speech.Microphone()
17
18
19def display_cpu_info():
20 lcd.clear()
21 while True:
22 load = os.getloadavg()[0] # 1-minute load average
23 temperature = cpu_temp.temperature
24 lcd.clear()
25 lcd.display_text(f"CPU Load:i {load}", 1)
26 lcd.display_text(f"Temp: {temperature:}C", 2)
27 time.sleep(5)
28
29
30def display_uptime():
31 lcd.clear()
32 with open("/proc/uptime") as f:
33 uptime_seconds = float(f.readline().split()[0])
34 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
35 lcd.clear()
36 lcd.display_text(f"Uptime: {uptime_str}", 1, "center")
37
38
39def recognize_speech():
40 lcd.clear()
41 try:
42 with microphone as source:
43 recognizer.adjust_for_ambient_noise(source)
44 print("Listening...")
45 audio = recognizer.listen(source)
46 text = recognizer.recognize_google(audio)
47 lcd.clear()
48 lcd.display_text(text, 1)
49 print("Speech recognized:", text)
50 except speech.UnknownValueError:
51 lcd.display_text(ERROR_BAD_REQUEST, 1)
52 print(ERROR_BAD_REQUEST)
53 except speech.RequestError:
54 lcd.display_text(ERROR_UNAUTHORIZED, 1)
55 print(ERROR_UNAUTHORIZED)
56
57
58def save_notes():
59 PRINT_REQUEST = True
60 EXIT_CODES = ['stop', 'break', 'quit', 'exit']
61 if PRINT_REQUEST == True:
62 while True:
63 OUTPUT = input()
64 print(OUTPUT)
65 lcd.display_text(OUTPUT, 1)
66 time.sleep(2)
67 for i in EXIT_CODES:
68 if OUTPUT == i:
69 PRINT_REQUEST == False
70
71
72
73OPTIONS = {
74 "CPU_INFO": display_cpu_info(),
75 "UPTIME": display_uptime(),
76 "SPEECH_TRANSCRIBER": recognize_speech(),
77 "NOTES": save_notes(),
78}
79
80
81def main():
82 lcd.clear()
83 print("WELCOME TO THE I2C COMMAND LINE CENTER")
84 print("Options:", ", ".join(OPTIONS.keys()))
85
86 while True:
87 user_input = input("Enter command: ").upper()
88 action = OPTIONS.get(user_input)
89
90 if action:
91 action()
92 else:
93 lcd.display_text(ERROR_NOT_FOUND, 1)
94 print(ERROR_NOT_FOUND)
95
96
97def destroy():
98 lcd.clear()
99 os.system("cls" if os.name == "nt" else "clear")
100
101
102if __name__ == "__main__":
103 try:
104 main()
105 except KeyboardInterrupt:
106 destroy()