chore: import clock container, design spec and implementation plan

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Sonnet 5.5 committed 2026-10-07 00:17:55 +02:00
commit 817ed3a45f
11 files changed
+2151

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
"""Clock face for the Turing Smart Screen, run as a container on the Coolify server.
Placeholder until the bus departure board replaces it. Drawing lives in render.py;
this file only owns the display and the update loop.
"""
import logging
import os
import signal
import sys
import time
from datetime import datetime
LIB = os.environ.get("LCD_LIB_PATH", "/opt/lcd")
sys.path.insert(0, LIB)
from PIL import Image # noqa: E402
import render # noqa: E402
from library.lcd.lcd_comm import Orientation # noqa: E402
from library.lcd.lcd_comm_rev_a import LcdCommRevA # noqa: E402
# force=True: the screen library configures logging at import, which would swallow ours.
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", force=True)
log = logging.getLogger("clock")
DEVICE = os.environ.get("SCREEN_DEVICE", "AUTO")
ORIENTATION = Orientation[os.environ.get("SCREEN_ORIENTATION", "REVERSE_LANDSCAPE")]
BRIGHTNESS = int(os.environ.get("SCREEN_BRIGHTNESS", "50"))
def main() -> None:
log.info("Opening display on %s (%s)", DEVICE, ORIENTATION.name)
lcd = LcdCommRevA(com_port=DEVICE) if DEVICE != "AUTO" else LcdCommRevA()
lcd.InitializeComm()
lcd.SetOrientation(ORIENTATION)
lcd.SetBrightness(BRIGHTNESS)
fonts = render.load_fonts(LIB)
running = True
def stop(*_):
nonlocal running
running = False
signal.signal(signal.SIGTERM, stop)
signal.signal(signal.SIGINT, stop)
lcd.DisplayPILImage(Image.new("RGB", (render.W, render.H), render.BG), 0, 0) # clear once
log.info("Display ready")
last_second = last_minute = None
while running:
now = datetime.now()
if now.second != last_second:
if now.minute != last_minute: # the digital panel only changes once a minute
lcd.DisplayPILImage(render.render_info(now, fonts), render.DIAL_W, 0)
last_minute = now.minute
lcd.DisplayPILImage(render.render_dial(now), 0, 0)
last_second = now.second
time.sleep(0.05)
lcd.closeSerial()
log.info("Stopped")
if __name__ == "__main__":
main()