refactor: basic logging

This commit is contained in:
2026-11-05 22:09:19 +01:00
parent 82ccc1d2e8
commit d2d2095081
4 changed files with 21 additions and 4 deletions
+3
View File
@@ -1,4 +1,5 @@
import argparse
import logging
import time
from .display import get_display
@@ -21,6 +22,8 @@ def main_loop() -> None:
def main() -> None:
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument(
"--mode", default="default", choices=["default", "gen-img", "debug-img"]
+9 -4
View File
@@ -1,3 +1,4 @@
import logging
import sys
import typing
@@ -6,6 +7,8 @@ from luma.core.interface.serial import i2c
from luma.oled.device import device, sh1106
from PIL import Image
log = logging.getLogger(__name__)
class I2C:
def __init__(self) -> None:
@@ -28,15 +31,17 @@ class I2C:
# Initialize the device. If using SH1106, change ssd1306 to sh1106
self.__device = sh1106(serial_interface, width=128, height=64, rotate=0)
except DeviceNotFoundError:
print("Fatal: OLED not found at 0x3C. Check wiring and run i2cdetect -y 1")
log.critical(
"Fatal: OLED not found at 0x3C. Check wiring and run i2cdetect -y 1"
)
sys.exit(1)
except OSError as e:
if e.errno == 121:
print(
log.critical(
"Fatal: Remote I/O error. I2C bus is locked or physically disconnected."
)
else:
print(f"Fatal OS Error: {e}")
log.critical(f"Fatal OS Error: {e}")
sys.exit(1)
def update_display(self, image: Image.Image) -> None:
@@ -45,5 +50,5 @@ class I2C:
self.__device.display(image)
except OSError as e:
if e.errno == 121:
print("Runtime Error: I2C bus dropped. Check physical connections.")
log.error("Runtime Error: I2C bus dropped. Check physical connections.")
raise
+4
View File
@@ -1,8 +1,11 @@
import logging
from PIL import Image, ImageDraw
from ..display import get_display
from ..forge_data import ForgeData
log = logging.getLogger(__name__)
def debug_image(im: Image.Image) -> None:
im = im.resize((1280, 640)).convert("RGB")
@@ -15,6 +18,7 @@ def debug_image(im: Image.Image) -> None:
draw2.line((0, y * 10, 1280, y * 10), fill=(50, 50, 50))
im.resize((1280, 640)).save("debug.png")
log.info("Debug image saved as debug.png")
def main():
+5
View File
@@ -1,3 +1,5 @@
import logging
from PIL import ImageDraw
from ..constants import (
@@ -6,6 +8,7 @@ from ..constants import (
)
from ..display import BLANK_IMG, FONT_1, FONT_2
log = logging.getLogger(__name__)
def generate_loading_image() -> None:
im = BLANK_IMG.copy()
@@ -16,6 +19,7 @@ def generate_loading_image() -> None:
draw.rectangle((24, 35, 104, 40), outline="white", fill="black")
im.save(LOADING_IMG_PATH)
log.info(f"Generated {LOADING_IMG_PATH}")
def generate_background_image() -> None:
@@ -53,6 +57,7 @@ def generate_background_image() -> None:
draw.circle((71, 61), 2, outline="white", fill="black")
im.save(BACKGROUND_IMG_PATH)
log.info(f"Generated {BACKGROUND_IMG_PATH}")
def main():