diff options
| -rw-r--r-- | .DS_Store | bin | 6148 -> 6148 bytes | |||
| -rw-r--r-- | .vscode/settings.json | 22 | ||||
| -rw-r--r-- | assets/text/quotes.txt (renamed from bin/quotes.txt) | 0 | ||||
| -rw-r--r-- | bin/assets/text/quotes.txt | 30 | ||||
| -rw-r--r-- | bin/display_driver.c | 2 | ||||
| -rw-r--r-- | bin/source/hardware_driver.py | 71 | ||||
| -rw-r--r-- | bin/source/main.py | 180 | ||||
| -rw-r--r-- | docs/guide.txt | 13 | ||||
| -rw-r--r-- | templates/api_server.service (renamed from api_server.service) | 0 |
9 files changed, 44 insertions, 274 deletions
| Binary files differ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index dd10108..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "workbench.colorCustomizations": { - "activityBar.activeBackground": "#1a1a1a", - "activityBar.background": "#1a1a1a", - "activityBar.foreground": "#e7e7e7", - "activityBar.inactiveForeground": "#e7e7e799", - "activityBarBadge.background": "#606020", - "activityBarBadge.foreground": "#e7e7e7", - "commandCenter.border": "#e7e7e799", - "sash.hoverBorder": "#1a1a1a", - "statusBar.background": "#000000", - "statusBar.foreground": "#e7e7e7", - "statusBarItem.hoverBackground": "#1a1a1a", - "statusBarItem.remoteBackground": "#000000", - "statusBarItem.remoteForeground": "#e7e7e7", - "titleBar.activeBackground": "#000000", - "titleBar.activeForeground": "#e7e7e7", - "titleBar.inactiveBackground": "#00000099", - "titleBar.inactiveForeground": "#e7e7e799" - }, - "peacock.color": "black" -}
\ No newline at end of file diff --git a/bin/quotes.txt b/assets/text/quotes.txt index a6c9d84..a6c9d84 100644 --- a/bin/quotes.txt +++ b/assets/text/quotes.txt diff --git a/bin/assets/text/quotes.txt b/bin/assets/text/quotes.txt new file mode 100644 index 0000000..9f778ed --- /dev/null +++ b/bin/assets/text/quotes.txt @@ -0,0 +1,30 @@ +“Code is like humor, it’s better if it’s clean.” +“Software is a great combination.” +“Computers are like a bicycle for the mind.” +“Simplicity is the soul of efficiency.” +“Good code is its own best documentation.” +“In programming, clarity is key.” +“Programs must be written for people.” +“Computers are only tools.” +“The best way to predict the future is to invent it.” +“Talk is cheap. Show me the code.” +"It’s not a bug, it’s a feature.” +“The computer is mightier than the pen.” +"Code is the art of telling computers what to do.” +"Make it work, make it right, make it fast.” +“Every problem can be solved with code.” +“The only limit is your imagination.” +“Programming is thinking, not typing.” +"Design is the soul of programming.” +“There’s no place like 127.0.0.1.” +“Without algorithms, there’s no solution.” +“Compilers turn ideas into machine code.” +“A program is only as good as its design.” +"Code never lies, comments sometimes do.” +“Debugging is twice as hard as writing.” +"Computers don’t make mistakes, programmers do.” +“Code fast, debug slow, optimize last.” +“Keep it simple, stupid (KISS).” +“Without testing, code is poetry.” +“Good software comes from great design.” +“The harder you work, the luckier you get.”
\ No newline at end of file diff --git a/bin/display_driver.c b/bin/display_driver.c index 04f2900..adb845a 100644 --- a/bin/display_driver.c +++ b/bin/display_driver.c @@ -29,7 +29,7 @@ static void activate(GtkApplication *app, gpointer user_data) { for (int i = 0; i < features_count; i++) { GtkWidget *button = gtk_button_new_with_label(features[i]); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - gtk_widget_set_size_request(button, 200, 100); + gtk_widget_set_size_request(button, 50, 50); } // Show all widgets diff --git a/bin/source/hardware_driver.py b/bin/source/hardware_driver.py deleted file mode 100644 index 7d48e69..0000000 --- a/bin/source/hardware_driver.py +++ /dev/null @@ -1,71 +0,0 @@ -from smbus import SMBus -from time import sleep - -ALIGN_FUNC = { - 'left': 'ljust', - 'right': 'rjust', - 'center': 'center'} -CLEAR_DISPLAY = 0x01 -ENABLE_BIT = 0b00000100 -LINES = { - 1: 0x80, - 2: 0xC0, - 3: 0x94, - 4: 0xD4} - -LCD_BACKLIGHT = 0x08 -LCD_NOBACKLIGHT = 0x00 - -class LCD(object): - - def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True): - self.address = address - self.bus = SMBus(bus) - self.delay = 0.0005 - self.rows = rows - self.width = width - self.backlight_status = backlight - - self.write(0x33) - self.write(0x32) - self.write(0x06) - self.write(0x0C) - self.write(0x28) - self.write(CLEAR_DISPLAY) - sleep(self.delay) - - def _write_byte(self, byte): - self.bus.write_byte(self.address, byte) - self.bus.write_byte(self.address, (byte | ENABLE_BIT)) - sleep(self.delay) - self.bus.write_byte(self.address,(byte & ~ENABLE_BIT)) - sleep(self.delay) - - def write(self, byte, mode=0): - backlight_mode = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT - self._write_byte(mode | (byte & 0xF0) | backlight_mode) - self._write_byte(mode | ((byte << 4) & 0xF0) | backlight_mode) - - def text(self, text, line, align='left'): - self.write(LINES.get(line, LINES[1])) - text, other_lines = self.get_text_line(text) - text = getattr(text, ALIGN_FUNC.get(align, 'ljust'))(self.width) - for char in text: - self.write(ord(char), mode=1) - if other_lines and line <= self.rows - 1: - self.text(other_lines, line + 1, align=align) - - def backlight(self, turn_on=True): - self.backlight_status = turn_on - self.write(0) - - def get_text_line(self, text): - line_break = self.width - if len(text) > self.width: - line_break = text[:self.width + 1].rfind(' ') - if line_break < 0: - line_break = self.width - return text[:line_break], text[line_break:].strip() - - def clear(self): - self.write(CLEAR_DISPLAY) diff --git a/bin/source/main.py b/bin/source/main.py deleted file mode 100644 index 929db57..0000000 --- a/bin/source/main.py +++ /dev/null @@ -1,180 +0,0 @@ -import time -import os -import speech_recognition as sr -from gpiozero import CPUTemperature -import hardware_driver as lcd - -# Error messages -ERROR_BAD_REQUEST = "400 Bad Request" -ERROR_UNAUTHORIZED = "401 Unauthorized" -ERROR_NOT_FOUND = "404 Not Found" -SPEECH_NOT_RECOGNIZED = "404-1 Speech not recognized" -ERROR_TIMEOUT = "408 Request Timeout" - -# Initialize components -try: - lcd_instance = lcd.LCD() -except Exception as e: - print("Error intializing LCD") -try: - cpu_temp = CPUTemperature() -except Exception as e: - print("Error initializing CPU temperature sensor:", e) - -try: - recognizer = sr.Recognizer() -except Exception as e: - print("Error initialzing voice recognition, its possible the speech recognition module isn't installed") - -try: - microphone = sr.Microphone() -except Exception as e: - print("Error initialzing the microphone \n check if the sound device package is installed") - -# clearing the terminal for a cleaner and program like interaction -def clear_terminal(): - os.system("cls" if os.name == "nt" else "clear") - -# Features -def custom_greeting(): - try: - with open("quotes.txt", "r") as file: - quotes = [quote.strip() for quote in file.readlines()] - except FileNotFoundError: - lcd_instance.text("Quotes file missing", 1) - return - - for quote in quotes: - first_line = quote[:16] - second_line = quote[16:32] - lcd_instance.text(first_line, 1) - lcd_instance.text(second_line, 2) - time.sleep(3) - lcd_instance.clear() - -def pomodoro(): - try: - duration_minutes = int(input("Enter duration in minutes: ")) - duration_seconds = duration_minutes * 60 - print("Pomodoro started for", duration_minutes, "minutes") - lcd_instance.text("Pomodoro Running", 1) - start_count = 0 - count = 0 - while duration_seconds > 0: - lcd_instance.text(f"Time left: {duration_minutes}:{duration_seconds * 60}", 2) - time.sleep(1) - duration_seconds -= 1 - count += 1 - if count == start_count + 60: - start_count = start - duration_minutes -= 1 - - lcd_instance.text("Time's Up!", 1) - time.sleep(3) - except ValueError: - lcd_instance.text("Invalid input", 1) - time.sleep(2) - -def system_readings(): - while True: - load = os.getloadavg()[0] - temperature = cpu_temp.temperature if cpu_temp else "N/A" - lcd_instance.clear() - lcd_instance.text(f"CPU Load: {load:.2f}", 1) - lcd_instance.text(f"Temp: {temperature}C", 2) - time.sleep(5) - -def display_uptime(): - try: - with open("/proc/uptime") as f: - uptime_seconds = float(f.readline().split()[0]) - uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds)) - lcd_instance.text(f"Uptime: {uptime_str}", 1) - time.sleep(3) - except Exception as e: - lcd_instance.text("Error reading uptime", 1) - print("Error:", e) - -def recognize_speech(): - lcd_instance.text("Listening...", 1) - try: - with microphone as source: - recognizer.adjust_for_ambient_noise(source) - audio = recognizer.listen(source) - output = recognizer.recognize_google(audio) - lcd_instance.text("Recognized:", 1) - lcd_instance.text(output[:16], 2) - - print("Speech recognized:", output) - return output - except sr.UnknownValueError: - lcd_instance.text(SPEECH_NOT_RECOGNIZED, 1) - print(SPEECH_NOT_RECOGNIZED) - except sr.RequestError as e: - lcd_instance.text(ERROR_UNAUTHORIZED, 1) - print(ERROR_UNAUTHORIZED, e) - except Exception as e: - lcd_instance.text("Speech Error", 1) - print("Error:", e) - return None - -def save_notes(): - print("Type your notes (type 'stop' to exit):") - while True: - note = input(": ") - if note.lower() in ["stop", "exit", "quit"]: - break - first_line = note[:16] - second_line = note[16:32] - lcd_instance.text(first_line, 1) - lcd_instance.text(second_line, 2) - time.sleep(3) - -# Command center to execute features -def command_center(): - command = recognize_speech().upper() - if command: - command() - else: - lcd_instance.text(ERROR_NOT_FOUND, 1) - print(ERROR_NOT_FOUND) - -# Features dictionary -FEATURES = { - "GREETING": custom_greeting, - "READINGS": system_readings, - "UPTIME": display_uptime, - "SPEECH": recognize_speech, - "NOTE": save_notes, - "COMMAND": command_center, - "POMODORO": pomodoro, - } - -# Main Menu -def main(): - clear_terminal() - print("FEATURES:", ", ".join(FEATURES.keys())) - while True: - user_input = input("Enter command (or 'EXIT' to quit): ").upper() - if user_input in ["QUIT", "EXIT"]: - destroy() - break - action = FEATURES.get(user_input) - if action: - action() - else: - print(ERROR_NOT_FOUND) - -# Clean up on exit -def destroy(): - lcd_instance.clear() - clear_terminal() - print("Goodbye!") - -# Entry point -if __name__ == "__main__": - try: - main() - except KeyboardInterrupt: - destroy() - diff --git a/docs/guide.txt b/docs/guide.txt new file mode 100644 index 0000000..b248f49 --- /dev/null +++ b/docs/guide.txt @@ -0,0 +1,13 @@ +------------------------------------------------------------- + + I2C CONTROLLER GUIDE + +------------------------------------------------------------- + +This program is designed to control an LCD1602 using python. It supports +a GUI and CLI interface and is at the moment only linux compatible. + +You will need to have a couple of dependency's readdy on your device to use the software. + +* sounddevice +* ... diff --git a/api_server.service b/templates/api_server.service index b69c5e4..b69c5e4 100644 --- a/api_server.service +++ b/templates/api_server.service |
