h
This commit is contained in:
parent
7ba3bdcda1
commit
0fff2c1007
9
main.py
9
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()
|
|
@ -1,2 +0,0 @@
|
|||
def get_output():
|
||||
return "Hello from module!"
|
39
modules/system_info.py
Normal file
39
modules/system_info.py
Normal 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)
|
Loading…
Reference in a new issue