diff --git a/main.py b/main.py index d4e26ed..c333b7f 100644 --- a/main.py +++ b/main.py @@ -2,28 +2,29 @@ import time from display.oled_display import OLEDDisplay from display.font_manager import FontManager from utils.network import get_ip -from modules import example_module +from modules.system_info import SystemInfoModule def main(): oled = OLEDDisplay() font_mgr = FontManager(size=10) + system_info = SystemInfoModule() while True: oled.clear() # Top HUD info (IP) - ip = f"IP: {get_ip()}" + ip = f"{get_ip()}" font_mgr.draw_multiline_text(oled.draw, ip, 0, 0, oled.display.width, 10) # Divider line oled.draw.line((0, 14, oled.display.width, 14), fill=255) # Main module output - output = example_module.get_output() + output = system_info.get_display_text() font_mgr.draw_multiline_text(oled.draw, output, 0, 18, oled.display.width, oled.display.height - 18) oled.render() time.sleep(2) if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/modules/example_module.py b/modules/example_module.py deleted file mode 100644 index 7d3b8a2..0000000 --- a/modules/example_module.py +++ /dev/null @@ -1,2 +0,0 @@ -def get_output(): - return "Hello from module!" diff --git a/modules/system_info.py b/modules/system_info.py new file mode 100644 index 0000000..f6bcf77 --- /dev/null +++ b/modules/system_info.py @@ -0,0 +1,39 @@ +import os +import psutil +from modules.base_module import DisplayModule + +class SystemInfoModule(DisplayModule): + def get_display_text(self): + lines = [] + + # CPU temperature + try: + with open("/sys/class/thermal/thermal_zone0/temp", "r") as f: + temp_str = f.read() + cpu_temp = round(int(temp_str) / 1000.0, 1) + lines.append(f"CPU Temp: {cpu_temp}°C") + except FileNotFoundError: + lines.append("CPU Temp: N/A") + + # CPU usage + cpu_usage = psutil.cpu_percent(interval=0.2) + lines.append(f"CPU Usage: {cpu_usage}%") + + # Memory usage + mem = psutil.virtual_memory() + mem_used = round(mem.used / (1024 * 1024)) + mem_total = round(mem.total / (1024 * 1024)) + lines.append(f"Mem: {mem_used}/{mem_total}MB") + + # IP address + ip_address = "No IP" + for interface, addrs in psutil.net_if_addrs().items(): + for addr in addrs: + if addr.family == 2 and not addr.address.startswith("127."): + ip_address = addr.address + break + if ip_address != "No IP": + break + lines.append(f"IP: {ip_address}") + + return "\n".join(lines)