This commit is contained in:
Xargana 2025-05-16 19:43:09 +03:00
parent 7ba3bdcda1
commit 0fff2c1007
3 changed files with 44 additions and 6 deletions

View file

@ -2,24 +2,25 @@ 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()

View file

@ -1,2 +0,0 @@
def get_output():
return "Hello from module!"

39
modules/system_info.py Normal file
View file

@ -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)