starcontrol/mainloop.py
Nicole O'Connor d4186e0e43 state sync: contains
* adafruit screen test script
* mainloop with threads
* a mostly finished screen thread
* a partly finished blocklist update thread
2024-11-04 19:25:23 -08:00

47 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import logging
import os
import math
import pathlib
import time
import threading
from PIL import Image, ImageDraw
import blocklists
import screen
log = logging.getLogger("main")
if __name__ == "__main__":
screen.screen_init()
screen.scr_light.value = True
img_canvas = Image.new("RGB", (135, 240))
hnd_canvas = ImageDraw.Draw(img_canvas)
hnd_canvas.rectangle((0,0,135,240), (0,0,0))
img_canvas.paste(Image.open("res/image/hourglass.png"),(math.floor(135/2) - math.ceil(49/2),math.floor(240/2) - math.ceil(90/2)))
screen.scr.image(img_canvas)
thr_blocklists = threading.Thread(target=blocklists.blocklist_thread)
thr_screen = threading.Thread(target=screen.screen_thread)
thr_blocklists.start()
thr_screen.start()
ok = True
while ok:
try:
thr_blocklists.join(5.0)
thr_screen.join(5.0)
ok = thr_blocklists.is_alive() and thr_screen.is_alive()
except KeyboardInterrupt:
ok = False
print("KEYBOARD INTERRUPT")
except:
ok = False
screen.running = False
blocklists.running = False
thr_screen.join()
thr_blocklists.join()