diff options
| author | nasrlol <nsrddyn@gmail.com> | 2024-12-03 02:18:08 +0100 |
|---|---|---|
| committer | nasrlol <nsrddyn@gmail.com> | 2024-12-03 02:18:08 +0100 |
| commit | b497d9dc0793684c0154d85b3b09e68743afe071 (patch) | |
| tree | 20a885b2664d17780836f6a7c24eea5c8f688d23 /source | |
| parent | 276696553946550412c10e3557966a685b5095c2 (diff) | |
changed gthe lcd intilization from lcd_instance to "L"
Diffstat (limited to 'source')
| -rw-r--r-- | source/features.py | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/source/features.py b/source/features.py index e06bacb..40ba922 100644 --- a/source/features.py +++ b/source/features.py | |||
| @@ -19,7 +19,7 @@ ERROR_TIMEOUT = "the request took too long check youre internet connection" | |||
| 19 | # try initializingthe lcd | 19 | # try initializingthe lcd |
| 20 | # if initializations fail they should disale they're function | 20 | # if initializations fail they should disale they're function |
| 21 | 21 | ||
| 22 | lcd_instance = lcd.LCD() | 22 | L = lcd.LCD() |
| 23 | 23 | ||
| 24 | # try initializing the temperature readings | 24 | # try initializing the temperature readings |
| 25 | try: | 25 | try: |
| @@ -66,16 +66,16 @@ class feat: | |||
| 66 | with open("quotes.txt", "r") as file: | 66 | with open("quotes.txt", "r") as file: |
| 67 | quotes = [quote.strip() for quote in file.readlines()] | 67 | quotes = [quote.strip() for quote in file.readlines()] |
| 68 | except FileNotFoundError: | 68 | except FileNotFoundError: |
| 69 | lcd_instance.text("Quotes file missing", 1) | 69 | L.text("Quotes file missing", 1) |
| 70 | return | 70 | return |
| 71 | 71 | ||
| 72 | for quote in quotes: | 72 | for quote in quotes: |
| 73 | first_line = quote[:16] | 73 | first_line = quote[:16] |
| 74 | second_line = quote[16:32] | 74 | second_line = quote[16:32] |
| 75 | lcd_instance.text(first_line, 1) | 75 | L.text(first_line, 1) |
| 76 | lcd_instance.text(second_line, 2) | 76 | L.text(second_line, 2) |
| 77 | time.sleep(3) | 77 | time.sleep(3) |
| 78 | lcd_instance.clear() | 78 | L.clear() |
| 79 | 79 | ||
| 80 | def pomodoro(self): | 80 | def pomodoro(self): |
| 81 | 81 | ||
| @@ -98,13 +98,11 @@ class feat: | |||
| 98 | duration_minutes -= 1 | 98 | duration_minutes -= 1 |
| 99 | time_passed_seconds == 0 | 99 | time_passed_seconds == 0 |
| 100 | print(f"\ryou have {duration_minutes}:{duration_seconds} left", end="") | 100 | print(f"\ryou have {duration_minutes}:{duration_seconds} left", end="") |
| 101 | lcd_instance.text( | 101 | L.text(f"\ryou have {duration_minutes}:{duration_seconds} left", 1) |
| 102 | f"\ryou have {duration_minutes}:{duration_seconds} left", 1 | ||
| 103 | ) | ||
| 104 | sleep(1) | 102 | sleep(1) |
| 105 | 103 | ||
| 106 | except ValueError: | 104 | except ValueError: |
| 107 | lcd_instance.text("Invalid input", 1) | 105 | L.text("Invalid input", 1) |
| 108 | time.sleep(2) | 106 | time.sleep(2) |
| 109 | 107 | ||
| 110 | def temperature(self): | 108 | def temperature(self): |
| @@ -112,9 +110,9 @@ class feat: | |||
| 112 | while True: | 110 | while True: |
| 113 | load = os.getloadavg()[0] | 111 | load = os.getloadavg()[0] |
| 114 | temperature = cpu_temp.temperature if cpu_temp else "N/A" | 112 | temperature = cpu_temp.temperature if cpu_temp else "N/A" |
| 115 | lcd_instance.clear() | 113 | L.clear() |
| 116 | lcd_instance.text(f"CPU Load: {load:.2f}", 1) | 114 | L.text(f"CPU Load: {load:.2f}", 1) |
| 117 | lcd_instance.text(f"Temp: {temperature}C", 2) | 115 | L.text(f"Temp: {temperature}C", 2) |
| 118 | time.sleep(5) | 116 | time.sleep(5) |
| 119 | 117 | ||
| 120 | def display_uptime(self): | 118 | def display_uptime(self): |
| @@ -123,34 +121,34 @@ class feat: | |||
| 123 | with open("/proc/uptime") as f: | 121 | with open("/proc/uptime") as f: |
| 124 | uptime_seconds = float(f.readline().split()[0]) | 122 | uptime_seconds = float(f.readline().split()[0]) |
| 125 | uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) | 123 | uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) |
| 126 | lcd_instance.text(f"Uptime: {uptime_str}", 1) | 124 | L.text(f"Uptime: {uptime_str}", 1) |
| 127 | time.sleep(3) | 125 | time.sleep(3) |
| 128 | except Exception as e: | 126 | except Exception as e: |
| 129 | lcd_instance.text("Error reading uptime", 1) | 127 | L.text("Error reading uptime", 1) |
| 130 | print("Error:", e) | 128 | print("Error:", e) |
| 131 | 129 | ||
| 132 | def recognize_speech(self, recognizer_): | 130 | def recognize_speech(self, recognizer_): |
| 133 | self.clear_terminal_lcd() | 131 | self.clear_terminal_lcd() |
| 134 | 132 | ||
| 135 | lcd_instance.text("Listening...", 1) | 133 | L.text("Listening...", 1) |
| 136 | try: | 134 | try: |
| 137 | with microphone as source: | 135 | with microphone as source: |
| 138 | recognizer.adjust_for_ambient_noise(source) | 136 | recognizer.adjust_for_ambient_noise(source) |
| 139 | audio = recognizer.listen(source) | 137 | audio = recognizer.listen(source) |
| 140 | output = recognizer.recognize_google(audio) | 138 | output = recognizer.recognize_google(audio) |
| 141 | lcd_instance.text("Recognized:", 1) | 139 | L.text("Recognized:", 1) |
| 142 | lcd_instance.text(output[:16], 2) | 140 | L.text(output[:16], 2) |
| 143 | 141 | ||
| 144 | print("Speech recognized:", output) | 142 | print("Speech recognized:", output) |
| 145 | return output | 143 | return output |
| 146 | except sr.UnknownValueError: | 144 | except sr.UnknownValueError: |
| 147 | lcd_instance.text(SPEECH_NOT_RECOGNIZED, 1) | 145 | L.text(SPEECH_NOT_RECOGNIZED, 1) |
| 148 | print(SPEECH_NOT_RECOGNIZED) | 146 | print(SPEECH_NOT_RECOGNIZED) |
| 149 | except sr.RequestError as e: | 147 | except sr.RequestError as e: |
| 150 | lcd_instance.text(ERROR_UNAUTHORIZED, 1) | 148 | L.text(ERROR_UNAUTHORIZED, 1) |
| 151 | print(ERROR_UNAUTHORIZED, e) | 149 | print(ERROR_UNAUTHORIZED, e) |
| 152 | except Exception as e: | 150 | except Exception as e: |
| 153 | lcd_instance.text("Speech Error", 1) | 151 | L.text("Speech Error", 1) |
| 154 | print("Error:", e) | 152 | print("Error:", e) |
| 155 | return None | 153 | return None |
| 156 | 154 | ||
| @@ -163,8 +161,8 @@ class feat: | |||
| 163 | break | 161 | break |
| 164 | first_line = note[:16] | 162 | first_line = note[:16] |
| 165 | second_line = note[16:32] | 163 | second_line = note[16:32] |
| 166 | lcd_instance.text(first_line, 1) | 164 | L.text(first_line, 1) |
| 167 | lcd_instance.text(second_line, 2) | 165 | L.text(second_line, 2) |
| 168 | time.sleep(3) | 166 | time.sleep(3) |
| 169 | 167 | ||
| 170 | # Command center to execute features | 168 | # Command center to execute features |
| @@ -184,5 +182,5 @@ class feat: | |||
| 184 | elif command == "temperature": | 182 | elif command == "temperature": |
| 185 | self.temperature() | 183 | self.temperature() |
| 186 | else: | 184 | else: |
| 187 | lcd_instance.text(ERROR_NOT_FOUND, 1) | 185 | L.text(ERROR_NOT_FOUND, 1) |
| 188 | print(ERROR_NOT_FOUND) | 186 | print(ERROR_NOT_FOUND) |
