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
+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