-
Notifications
You must be signed in to change notification settings - Fork 0
/
ink_display.py
63 lines (51 loc) · 1.75 KB
/
ink_display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import os
from globals import *
import logging.config
from lib import epd7in3f
import time
import json
from PIL import Image, ImageDraw, ImageFont
LOGGER = logging.getLogger(__name__)
config_file = "logging.json"
with open(config_file) as f:
config = json.load(f)
logging.config.dictConfig(config)
class InkDisplay:
def __init__(self) -> None:
self.ink = epd7in3f.EPD()
self.draw_image = self.blank_image()
def init(self) -> None:
LOGGER.info("initialising")
if os.path.exists(LIB_DIR):
sys.path.append(LIB_DIR)
self.ink.init()
def clear(self) -> None:
LOGGER.info("clearing screen")
self.ink.Clear()
def sleep(self) -> None:
LOGGER.info("putting to sleep")
self.ink.sleep()
def exit(self) -> None:
LOGGER.info("ctrl + c:")
epd7in3f.epdconfig.module_exit()
def display_image(self, image) -> None:
LOGGER.info("displaying image")
Himage = Image.open(os.path.join(IMG_DIR, image))
self.ink.display(self.ink.getbuffer(Himage))
def blank_image(self) -> Image:
LOGGER.info("creating new draw image")
return Image.new("RGB", (self.ink.width, self.ink.height), self.ink.WHITE)
def draw(self, image) -> ImageDraw:
return ImageDraw.Draw(image)
def draw_text(self, location, text, font, size, color, draw) -> None:
LOGGER.info("drawing text to draw image: %s", text)
draw.text(
(location),
text=text,
font=ImageFont.truetype(os.path.join(FONT_DIR, font), size),
fill=color,
)
def display_draw(self, image) -> None:
LOGGER.info("displaying draw image")
self.ink.display(self.ink.getbuffer(image))