Files
weather-base-station/display/__init__.py
T

50 lines
1.3 KiB
Python

# display/__init__.py
import logging
from datetime import datetime
from PIL import Image
from .epd4in2 import EPD, epdconfig
from .image_maker import eInkImage
logging.getLogger(__name__)
class Display:
def __init__(self) -> None:
self.image = eInkImage()
self.e_Paper = self._start_up()
def _start_up(self) -> EPD:
try:
epd = EPD()
epd.init()
epd.Clear()
return epd
except Exception as e:
logging.error(f"eInk Display not found! | {e}")
@staticmethod
def _wait_until(timestamp: str, absolute_date: datetime) -> None:
while (
not timestamp in datetime.today().time().strftime("%H:%M:%S")
and absolute_date >= datetime.today()
):
pass
return
@staticmethod
def exit():
epdconfig.module_exit()
def refresh(self, image: Image.Image, date: datetime, first: bool) -> None:
try:
self.e_Paper.Init_4Gray()
if not first:
self._wait_until(":00", date)
self.e_Paper.display_4Gray(self.e_Paper.getbuffer_4Gray(image))
self.e_Paper.sleep()
except Exception as e:
logging.error(f"Failed displaying image - ERROR: {e}")