summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornasrlol <nsrddyn@gmail.com>2024-11-18 21:40:07 +0100
committernasrlol <nsrddyn@gmail.com>2024-11-18 21:40:07 +0100
commit742e86dea54eaed4db8cad82835c7c946f40f8e4 (patch)
tree966eb57bd1df59e631cff70c5703cd1e7a7582f5
parent49046aa2917d871fbfbe9389547410775d360081 (diff)
fixed some minor bugs within the code (sytax bugs)
-rw-r--r--bin/__pycache__/i2c.cpython-312.pycbin0 -> 4218 bytes
-rw-r--r--bin/main.py61
-rwxr-xr-xbin/testbin0 -> 16016 bytes
3 files changed, 28 insertions, 33 deletions
diff --git a/bin/__pycache__/i2c.cpython-312.pyc b/bin/__pycache__/i2c.cpython-312.pyc
new file mode 100644
index 0000000..a2ea22c
--- /dev/null
+++ b/bin/__pycache__/i2c.cpython-312.pyc
Binary files 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
2import os 2import os
3import speech_recognition as speech 3import speech_recognition as speech
4import sounddevice 4import sounddevice
5import i2c as LCD 5import i2c as lcd
6from gpiozero import CPUTemperature 6from gpiozero import CPUTemperature
7 7
8ERROR_BAD_REQUEST = "400 Bad Request" 8ERROR_BAD_REQUEST = "400 Bad Request"
@@ -10,75 +10,71 @@ ERROR_UNAUTHORIZED = "401 Unauthorized"
10ERROR_NOT_FOUND = "404 Not Found" 10ERROR_NOT_FOUND = "404 Not Found"
11ERROR_TIMEOUT = "408 Request Timeout" 11ERROR_TIMEOUT = "408 Request Timeout"
12 12
13lcd = LCD() 13lcd_instance = lcd.LCD()
14cpu_temp = CPUTemperature() 14cpu_temp = CPUTemperature()
15recognizer = speech.Recognizer() 15recognizer = speech.Recognizer()
16microphone = speech.Microphone() 16microphone = speech.Microphone()
17 17
18 18
19def display_cpu_info(): 19def display_cpu_info():
20 lcd.clear() 20 lcd_instance.clear()
21 while True: 21 while True:
22 load = os.getloadavg()[0] 22 load = os.getloadavg()[0]
23 temperature = cpu_temp.temperature 23 temperature = cpu_temp.temperature
24 lcd.clear() 24 lcd_instance.clear()
25 lcd.display_text(f"CPU Load:i {load}", 1) 25 lcd_instance.display_text(f"CPU Load: {load}", 1)
26 lcd.display_text(f"Temp: {temperature:}C", 2) 26 lcd_instance.display_text(f"Temp: {temperature:.1f}C", 2)
27 time.sleep(5) 27 time.sleep(5)
28 28
29 29
30def display_uptime(): 30def display_uptime():
31 lcd.clear() 31 lcd_instance.clear()
32 with open("/proc/uptime") as f: 32 with open("/proc/uptime") as f:
33 uptime_seconds = float(f.readline().split()[0]) 33 uptime_seconds = float(f.readline().split()[0])
34 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) 34 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
35 lcd.clear() 35 lcd_instance.clear()
36 lcd.display_text(f"Uptime: {uptime_str}", 1, "center") 36 lcd_instance.display_text(f"Uptime: {uptime_str}", 1, "center")
37 37
38 38
39def recognize_speech(): 39def recognize_speech():
40 lcd.clear() 40 lcd_instance.clear()
41 try: 41 try:
42 with microphone as source: 42 with microphone as source:
43 recognizer.adjust_for_ambient_noise(source) 43 recognizer.adjust_for_ambient_noise(source)
44 print("Listening...") 44 print("Listening...")
45 audio = recognizer.listen(source) 45 audio = recognizer.listen(source)
46 text = recognizer.recognize_google(audio) 46 text = recognizer.recognize_google(audio)
47 lcd.clear() 47 lcd_instance.clear()
48 lcd.display_text(text, 1) 48 lcd_instance.display_text(text, 1)
49 print("Speech recognized:", text) 49 print("Speech recognized:", text)
50 except speech.UnknownValueError: 50 except speech.UnknownValueError:
51 lcd.display_text(ERROR_BAD_REQUEST, 1) 51 lcd_instance.display_text(ERROR_BAD_REQUEST, 1)
52 print(ERROR_BAD_REQUEST) 52 print(ERROR_BAD_REQUEST)
53 except speech.RequestError: 53 except speech.RequestError:
54 lcd.display_text(ERROR_UNAUTHORIZED, 1) 54 lcd_instance.display_text(ERROR_UNAUTHORIZED, 1)
55 print(ERROR_UNAUTHORIZED) 55 print(ERROR_UNAUTHORIZED)
56 56
57 57
58def save_notes(): 58def save_notes():
59 PRINT_REQUEST = True 59 print("Type your notes (type 'stop' to exit):")
60 EXIT_CODES = ["stop", "break", "quit", "exit"] 60 while True:
61 if PRINT_REQUEST == True: 61 output = input()
62 while True: 62 if output.lower() in ["stop", "break", "quit", "exit"]:
63 OUTPUT = input() 63 break
64 print(OUTPUT) 64 lcd_instance.display_text(output, 1)
65 lcd.display_text(OUTPUT, 1) 65 time.sleep(2)
66 time.sleep(2)
67 for i in EXIT_CODES:
68 if OUTPUT == i:
69 PRINT_REQUEST == False
70 66
71 67
72OPTIONS = { 68OPTIONS = {
73 "CPU_INFO": display_cpu_info(), 69 "CPU_INFO": display_cpu_info,
74 "UPTIME": display_uptime(), 70 "UPTIME": display_uptime,
75 "SPEECH_TRANSCRIBER": recognize_speech(), 71 "SPEECH_TRANSCRIBER": recognize_speech,
76 "NOTES": save_notes(), 72 "NOTES": save_notes,
77} 73}
78 74
79 75
80def main(): 76def main():
81 lcd.clear() 77 lcd_instance.clear()
82 print("WELCOME TO THE I2C COMMAND LINE CENTER") 78 print("WELCOME TO THE I2C COMMAND LINE CENTER")
83 print("Options:", ", ".join(OPTIONS.keys())) 79 print("Options:", ", ".join(OPTIONS.keys()))
84 80
@@ -89,17 +85,16 @@ def main():
89 if action: 85 if action:
90 action() 86 action()
91 else: 87 else:
92 lcd.display_text(ERROR_NOT_FOUND, 1) 88 lcd_instance.display_text(ERROR_NOT_FOUND, 1)
93 print(ERROR_NOT_FOUND) 89 print(ERROR_NOT_FOUND)
94 90
95 91
96def destroy(): 92def destroy():
97 lcd.clear() 93 lcd_instance.clear()
98 os.system("cls" if os.name == "nt" else "clear") 94 os.system("cls" if os.name == "nt" else "clear")
99 95
100 96
101if __name__ == "__main__": 97if __name__ == "__main__":
102 os.system("cls" if os.name == "nt" else "clear")
103 try: 98 try:
104 main() 99 main()
105 except KeyboardInterrupt: 100 except KeyboardInterrupt:
diff --git a/bin/test b/bin/test
new file mode 100755
index 0000000..180427d
--- /dev/null
+++ b/bin/test
Binary files differ