|
|
|
|
@ -44,40 +44,42 @@ def run( |
|
|
|
|
apps: list[meminfo.App] = [] |
|
|
|
|
next_apps_at = float("-inf") |
|
|
|
|
|
|
|
|
|
while not stop.is_set(): |
|
|
|
|
try: |
|
|
|
|
if not connected: |
|
|
|
|
lcd.open() |
|
|
|
|
lcd.set_orientation_portrait() |
|
|
|
|
lcd.set_brightness(cfg.brightness) |
|
|
|
|
connected, failure_reported, last_frame = True, False, None |
|
|
|
|
log.info("Display verbunden (%s)", cfg.port) |
|
|
|
|
|
|
|
|
|
t = monotonic() |
|
|
|
|
if t >= next_apps_at: |
|
|
|
|
apps = top_apps(cfg.top_n) |
|
|
|
|
next_apps_at = t + cfg.apps_interval |
|
|
|
|
|
|
|
|
|
frame = _orient(render(read_memory(), apps, now(), cfg), cfg) |
|
|
|
|
for x, y, w, h in changed_rects(last_frame, frame): |
|
|
|
|
lcd.show(frame.crop((x, y, x + w, y + h)), x, y) |
|
|
|
|
last_frame = frame |
|
|
|
|
stop.wait(cfg.memory_interval) |
|
|
|
|
except OSError as exc: |
|
|
|
|
if connected or not failure_reported: |
|
|
|
|
log.warning("Display nicht erreichbar (%s), neuer Versuch in %.0f s", exc, reconnect_delay) |
|
|
|
|
failure_reported = True |
|
|
|
|
lcd.close() |
|
|
|
|
connected = False |
|
|
|
|
stop.wait(reconnect_delay) |
|
|
|
|
|
|
|
|
|
if connected: |
|
|
|
|
try: |
|
|
|
|
lcd.show(_orient(render_stopped(now()), cfg), 0, 0) |
|
|
|
|
except OSError as exc: |
|
|
|
|
log.warning("Endbildschirm konnte nicht gesendet werden: %s", exc) |
|
|
|
|
lcd.close() |
|
|
|
|
log.info("Beendet") |
|
|
|
|
# finally: auch bei einem unerwarteten Fehler den Endbildschirm zeigen statt den letzten Stand einzufrieren |
|
|
|
|
try: |
|
|
|
|
while not stop.is_set(): |
|
|
|
|
try: |
|
|
|
|
if not connected: |
|
|
|
|
lcd.open() |
|
|
|
|
lcd.set_orientation_portrait() |
|
|
|
|
lcd.set_brightness(cfg.brightness) |
|
|
|
|
connected, failure_reported, last_frame = True, False, None |
|
|
|
|
log.info("Display verbunden (%s)", cfg.port) |
|
|
|
|
|
|
|
|
|
t = monotonic() |
|
|
|
|
if t >= next_apps_at: |
|
|
|
|
apps = top_apps(cfg.top_n) |
|
|
|
|
next_apps_at = t + cfg.apps_interval |
|
|
|
|
|
|
|
|
|
frame = _orient(render(read_memory(), apps, now(), cfg), cfg) |
|
|
|
|
for x, y, w, h in changed_rects(last_frame, frame): |
|
|
|
|
lcd.show(frame.crop((x, y, x + w, y + h)), x, y) |
|
|
|
|
last_frame = frame |
|
|
|
|
stop.wait(cfg.memory_interval) |
|
|
|
|
except OSError as exc: |
|
|
|
|
if connected or not failure_reported: |
|
|
|
|
log.warning("Display nicht erreichbar (%s), neuer Versuch in %.0f s", exc, reconnect_delay) |
|
|
|
|
failure_reported = True |
|
|
|
|
lcd.close() |
|
|
|
|
connected = False |
|
|
|
|
stop.wait(reconnect_delay) |
|
|
|
|
finally: |
|
|
|
|
if connected: |
|
|
|
|
try: |
|
|
|
|
lcd.show(_orient(render_stopped(now()), cfg), 0, 0) |
|
|
|
|
except OSError as exc: |
|
|
|
|
log.warning("Endbildschirm konnte nicht gesendet werden: %s", exc) |
|
|
|
|
lcd.close() |
|
|
|
|
log.info("Beendet") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int: |
|
|
|
|
|