summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2024-11-13 08:28:29 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2024-11-13 08:28:29 +0100
commit9ebcbfc83a64b8a27d0725dbd12f6a8fdb042934 (patch)
treef6a053d80f44265ffb28d0b932cb12571f315543
parent545d44d84a3b61977ffbd55952e62a0f9bee8d9d (diff)
parent1b9748da64281bc6fe5a808e744922ecc72fc6ba (diff)
Merge branch 'main' of https://github.com/nasrlol/I2C
-rw-r--r--bin/kasper_gui.py7
-rw-r--r--bin/kasper_source.py46
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 @@
1import tkinter 1import tkinter
2from tkinter import PhotoImage
3 2
4display = tkinter.Tk() 3display = tkinter.Tk()
5display.title("Kasper") 4display.title("Kasper")
6photo = PhotoImage(file="icon.png")
7display.iconphoto(False, photo)
8 5
9# making 2 versions IOS AND DESKTOP 6display.mainloop() \ No newline at end of file
10# with swiftUI
11display.mainloop()
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 @@
1from smbus2 import SMBus 1from smbus import SMBus
2from gpiozero import CPUTemperature 2from gpiozero import CPUTemperature
3import speech_recognition as sr 3import speech_recognition as speech
4import os 4import os
5import time 5import time
6from time import sleep
6 7
7# LCD Constants 8# LCD Constants
8LCD_BACKLIGHT = 0x08 9LCD_BACKLIGHT = 0x08
@@ -17,9 +18,9 @@ ERROR_UNAUTHORIZED = "401 Unauthorized"
17ERROR_NOT_FOUND = "404 Not Found" 18ERROR_NOT_FOUND = "404 Not Found"
18ERROR_TIMEOUT = "408 Request Timeout" 19ERROR_TIMEOUT = "408 Request Timeout"
19 20
20
21# LCD Control Class 21# LCD Control Class
22class LCD: 22class LCD:
23
23 def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True): 24 def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
24 self.address = address 25 self.address = address
25 self.bus = SMBus(bus) 26 self.bus = SMBus(bus)
@@ -62,36 +63,41 @@ class LCD:
62 self.backlight_status = turn_on 63 self.backlight_status = turn_on
63 self.write(0) 64 self.write(0)
64 65
65
66# Initialize components 66# Initialize components
67lcd = LCD() 67lcd = LCD()
68cpu_temp = CPUTemperature() 68cpu_temp = CPUTemperature()
69recognizer = sr.Recognizer() 69recognizer = speech.Recognizer()
70microphone = sr.Microphone() 70microphone = speech.Microphone()
71 71
72 72
73# Display Functions 73# Display Functions
74def display_cpu_info(): 74def display_cpu_info():
75 # clearing the display before accessing it
76 lcd.clear()
75 """Display CPU load and temperature on the LCD.""" 77 """Display CPU load and temperature on the LCD."""
76 while True: 78 while True:
77 load = os.getloadavg()[0] # 1-minute load average 79 load = os.getloadavg()[0] # 1-minute load average
78 temperature = cpu_temp.temperature 80 temperature = cpu_temp.temperature
79 lcd.clear() 81 lcd.clear()
80 lcd.display_text(f"CPU Load: {load:.2f}", line=1) 82 lcd.display_text(f"CPU Load: {load:.2f}", 1)
81 lcd.display_text(f"Temp: {temperature:.1f}C", line=2) 83 lcd.display_text(f"Temp: {temperature:.1f}C", 2)
82 time.sleep(5) 84 time.sleep(5)
83 85
84 86
85def display_uptime(): 87def display_uptime():
88 # clearing the display before accessing it
89 lcd.clear()
86 """Display system uptime on the LCD.""" 90 """Display system uptime on the LCD."""
87 with open("/proc/uptime") as f: 91 with open("/proc/uptime") as f:
88 uptime_seconds = float(f.readline().split()[0]) 92 uptime_seconds = float(f.readline().split()[0])
89 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) 93 uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
90 lcd.clear() 94 lcd.clear()
91 lcd.display_text(f"Uptime: {uptime_str}", line=1) 95 lcd.display_text(f"Uptime: {uptime_str}", 1)
92 96
93 97
94def recognize_speech(): 98def recognize_speech():
99 # clearing the display before accessing it
100 lcd.clear()
95 """Capture and transcribe speech input.""" 101 """Capture and transcribe speech input."""
96 try: 102 try:
97 with microphone as source: 103 with microphone as source:
@@ -100,25 +106,35 @@ def recognize_speech():
100 audio = recognizer.listen(source) 106 audio = recognizer.listen(source)
101 text = recognizer.recognize_google(audio) 107 text = recognizer.recognize_google(audio)
102 lcd.clear() 108 lcd.clear()
103 lcd.display_text(text, line=1) 109 lcd.display_text(text, 1)
104 print("Speech recognized:", text) 110 print("Speech recognized:", text)
105 except sr.UnknownValueError: 111 except speech.UnknownValueError:
106 lcd.display_text(ERROR_BAD_REQUEST, line=1) 112 lcd.display_text(ERROR_BAD_REQUEST, 1)
107 print(ERROR_BAD_REQUEST) 113 print(ERROR_BAD_REQUEST)
108 except sr.RequestError: 114 except speech.RequestError:
109 lcd.display_text(ERROR_UNAUTHORIZED, line=1) 115 lcd.display_text(ERROR_UNAUTHORIZED, 1)
110 print(ERROR_UNAUTHORIZED) 116 print(ERROR_UNAUTHORIZED)
111 117
118def notes():
119 while True:
120 OUTPUT = input()
121 print(OUTPUT)
122 lcd.display_text(OUTPUT, 1)
123 sleep(2)
124
112 125
113# Main Program Options 126# Main Program Options
114OPTIONS = { 127OPTIONS = {
115 "CPU_INFO": display_cpu_info, 128 "CPU_INFO": display_cpu_info,
116 "UPTIME": display_uptime, 129 "UPTIME": display_uptime,
117 "SPEECH_TRANSCRIBER": recognize_speech, 130 "SPEECH_TRANSCRIBER": recognize_speech,
131 "NOTES": notes,
118} 132}
119 133
120 134
121def main(): 135def main():
136 # clearing the display before doing anything
137 lcd.clear()
122 # Main program loop to accept user commands. 138 # Main program loop to accept user commands.
123 print("WELCOME TO THE I2C COMMAND LINE CENTER") 139 print("WELCOME TO THE I2C COMMAND LINE CENTER")
124 print("Options:", ", ".join(OPTIONS.keys())) 140 print("Options:", ", ".join(OPTIONS.keys()))
@@ -130,7 +146,7 @@ def main():
130 if action: 146 if action:
131 action() 147 action()
132 else: 148 else:
133 lcd.display_text(ERROR_NOT_FOUND, line=1) 149 lcd.display_text(ERROR_NOT_FOUND, 1)
134 print(ERROR_NOT_FOUND) 150 print(ERROR_NOT_FOUND)
135 151
136 152