e-paper-display/examples/epd.py

54 lines
1.5 KiB
Python
Raw Normal View History

2022-10-18 08:22:40 +00:00
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
2022-10-18 11:34:33 +00:00
from waveshare_epd import epd2in13bc
2022-10-18 08:22:40 +00:00
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
2022-10-18 12:54:19 +00:00
logging.info("epd2in13bc Demo")
2022-10-18 08:22:40 +00:00
2022-10-18 13:02:54 +00:00
epd = epd2in13bc.EPD()
2022-10-18 08:22:40 +00:00
logging.info("init and Clear")
2022-10-18 15:04:57 +00:00
epd.init()
epd.Clear()
time.sleep(1)
2022-10-18 08:22:40 +00:00
# Drawing on the image
2022-10-18 15:04:57 +00:00
logging.info("Drawing")
font20 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
2022-10-18 08:22:40 +00:00
2022-10-18 15:04:57 +00:00
logging.info("4.read bmp file on window")
blackimage1 = Image.new('1', (epd.height, epd.width), 255) # 298*126
redimage1 = Image.new('1', (epd.height, epd.width), 255) # 298*126
2022-10-18 15:09:00 +00:00
newimage = Image.open(os.path.join(picdir, 'elektrizitat.png'))
2022-10-18 15:04:57 +00:00
blackimage1.paste(newimage, (10,10))
epd.display(epd.getbuffer(blackimage1), epd.getbuffer(redimage1))
2022-10-18 08:22:40 +00:00
logging.info("Clear...")
2022-10-18 15:04:57 +00:00
epd.init()
epd.Clear()
2022-10-18 08:22:40 +00:00
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
2022-10-18 11:34:33 +00:00
epd2in13bc.epdconfig.module_exit()
2022-10-18 08:22:40 +00:00
exit()