diff options
| author | nasrlol <nsrddyn@gmail.com> | 2024-11-13 00:46:32 +0100 |
|---|---|---|
| committer | nasrlol <nsrddyn@gmail.com> | 2024-11-13 00:46:32 +0100 |
| commit | 924cde73d031e0019ca364c97f1d3d291fc0b98e (patch) | |
| tree | dd1d46e508406e4ba1cdb32513d2fe685b7fb6b4 | |
| parent | 16c71d8ddc79efff880346c39e918cf07c8abfdf (diff) | |
added a notes function, removed the accesive line statement in the lcd.display setting
| -rw-r--r-- | bin/kasper_source.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/bin/kasper_source.py b/bin/kasper_source.py index b7d8060..e1110a1 100644 --- a/bin/kasper_source.py +++ b/bin/kasper_source.py | |||
| @@ -3,6 +3,7 @@ from gpiozero import CPUTemperature | |||
| 3 | import speech_recognition as speech | 3 | import speech_recognition as speech |
| 4 | import os | 4 | import os |
| 5 | import time | 5 | import time |
| 6 | from time import sleep | ||
| 6 | 7 | ||
| 7 | # LCD Constants | 8 | # LCD Constants |
| 8 | LCD_BACKLIGHT = 0x08 | 9 | LCD_BACKLIGHT = 0x08 |
| @@ -78,8 +79,8 @@ def display_cpu_info(): | |||
| 78 | load = os.getloadavg()[0] # 1-minute load average | 79 | load = os.getloadavg()[0] # 1-minute load average |
| 79 | temperature = cpu_temp.temperature | 80 | temperature = cpu_temp.temperature |
| 80 | lcd.clear() | 81 | lcd.clear() |
| 81 | lcd.display_text(f"CPU Load: {load:.2f}", line=1) | 82 | lcd.display_text(f"CPU Load: {load:.2f}", 1) |
| 82 | lcd.display_text(f"Temp: {temperature:.1f}C", line=2) | 83 | lcd.display_text(f"Temp: {temperature:.1f}C", 2) |
| 83 | time.sleep(5) | 84 | time.sleep(5) |
| 84 | 85 | ||
| 85 | 86 | ||
| @@ -91,7 +92,7 @@ def display_uptime(): | |||
| 91 | uptime_seconds = float(f.readline().split()[0]) | 92 | uptime_seconds = float(f.readline().split()[0]) |
| 92 | uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) | 93 | uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) |
| 93 | lcd.clear() | 94 | lcd.clear() |
| 94 | lcd.display_text(f"Uptime: {uptime_str}", line=1) | 95 | lcd.display_text(f"Uptime: {uptime_str}", 1) |
| 95 | 96 | ||
| 96 | 97 | ||
| 97 | def recognize_speech(): | 98 | def recognize_speech(): |
| @@ -105,21 +106,29 @@ def recognize_speech(): | |||
| 105 | audio = recognizer.listen(source) | 106 | audio = recognizer.listen(source) |
| 106 | text = recognizer.recognize_google(audio) | 107 | text = recognizer.recognize_google(audio) |
| 107 | lcd.clear() | 108 | lcd.clear() |
| 108 | lcd.display_text(text, line=1) | 109 | lcd.display_text(text, 1) |
| 109 | print("Speech recognized:", text) | 110 | print("Speech recognized:", text) |
| 110 | except speech.UnknownValueError: | 111 | except speech.UnknownValueError: |
| 111 | lcd.display_text(ERROR_BAD_REQUEST, line=1) | 112 | lcd.display_text(ERROR_BAD_REQUEST, 1) |
| 112 | print(ERROR_BAD_REQUEST) | 113 | print(ERROR_BAD_REQUEST) |
| 113 | except speech.RequestError: | 114 | except speech.RequestError: |
| 114 | lcd.display_text(ERROR_UNAUTHORIZED, line=1) | 115 | lcd.display_text(ERROR_UNAUTHORIZED, 1) |
| 115 | print(ERROR_UNAUTHORIZED) | 116 | print(ERROR_UNAUTHORIZED) |
| 116 | 117 | ||
| 118 | def notes(): | ||
| 119 | while True: | ||
| 120 | OUTPUT = input() | ||
| 121 | print(OUTPUT) | ||
| 122 | lcd.display_text() | ||
| 123 | sleep(2) | ||
| 124 | |||
| 117 | 125 | ||
| 118 | # Main Program Options | 126 | # Main Program Options |
| 119 | OPTIONS = { | 127 | OPTIONS = { |
| 120 | "CPU_INFO": display_cpu_info, | 128 | "CPU_INFO": display_cpu_info, |
| 121 | "UPTIME": display_uptime, | 129 | "UPTIME": display_uptime, |
| 122 | "SPEECH_TRANSCRIBER": recognize_speech, | 130 | "SPEECH_TRANSCRIBER": recognize_speech, |
| 131 | "NOTES": notes, | ||
| 123 | } | 132 | } |
| 124 | 133 | ||
| 125 | 134 | ||
| @@ -137,7 +146,7 @@ def main(): | |||
| 137 | if action: | 146 | if action: |
| 138 | action() | 147 | action() |
| 139 | else: | 148 | else: |
| 140 | lcd.display_text(ERROR_NOT_FOUND, line=1) | 149 | lcd.display_text(ERROR_NOT_FOUND, 1) |
| 141 | print(ERROR_NOT_FOUND) | 150 | print(ERROR_NOT_FOUND) |
| 142 | 151 | ||
| 143 | 152 | ||
