| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/usr/bin/env python3
- # -*- coding:utf-8 -*-
- import sys
- import os
- pydir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
- picdir = os.path.join(pydir, 'pic')
- libdir = os.path.join(pydir, 'lib')
- if os.path.exists(libdir):
- sys.path.append(libdir)
- import logging
- from waveshare_epd import epd2in13_V2
- import time
- from PIL import Image,ImageDraw,ImageFont
- from PIL.ImageOps import invert
- import traceback
- logging.basicConfig(level=logging.DEBUG)
- try:
- logging.info("epd2in13_V2 Demo")
- font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
- epd = epd2in13_V2.EPD()
- logging.info("init and Clear")
- epd.init(epd.FULL_UPDATE)
- epd.Clear(0xFF)
- # read bmp file
- logging.info("2.read bmp file...")
- image = Image.open(os.path.join(picdir, '2in13.bmp'))
- draw = ImageDraw.Draw(image)
- epd.displayPartBaseImage(epd.getbuffer(image))
- time.sleep(2)
- logging.info("4.show time...")
- image = Image.new('1', (epd.height, epd.width), 255)
- draw = ImageDraw.Draw(image)
- epd.init(epd.FULL_UPDATE)
- epd.displayPartBaseImage(epd.getbuffer(image))
- epd.init(epd.PART_UPDATE)
- draw.text((120, 60), " ".join(sys.argv[1:]), font = font24, fill = 0)
- num = 0
- while (True):
- draw.rectangle((120, 80, 220, 105), fill = 255)
- draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
- epd.displayPartial(epd.getbuffer(image.rotate(180)))
- num = num + 1
- if(num == 10):
- break
- time.sleep(2)
- logging.info("Goto Sleep...")
- epd.sleep()
- epd.Dev_exit()
- except IOError as e:
- logging.info(e)
- except KeyboardInterrupt:
- logging.info("ctrl + c:")
- epd2in13_V2.epdconfig.module_exit()
- exit()
|