-
Notifications
You must be signed in to change notification settings - Fork 589
/
epd_1in54_V2_test.py
96 lines (81 loc) · 2.97 KB
/
epd_1in54_V2_test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/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
from waveshare_epd import epd1in54_V2
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd1in54_V2 Demo")
epd = epd1in54_V2.EPD()
logging.info("init and Clear")
epd.init(0)
epd.Clear(0xFF)
time.sleep(1)
# Drawing on the image
logging.info("1.Drawing on the image...")
image = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
draw.rectangle((0, 10, 200, 34), fill = 0)
draw.text((8, 12), 'hello world', font = font, fill = 255)
draw.text((8, 36), u'微雪电子', font = font, fill = 0)
draw.line((16, 60, 56, 60), fill = 0)
draw.line((56, 60, 56, 110), fill = 0)
draw.line((16, 110, 56, 110), fill = 0)
draw.line((16, 110, 16, 60), fill = 0)
draw.line((16, 60, 56, 110), fill = 0)
draw.line((56, 60, 16, 110), fill = 0)
draw.arc((90, 60, 150, 120), 0, 360, fill = 0)
draw.rectangle((16, 130, 56, 180), fill = 0)
draw.chord((90, 130, 150, 190), 0, 360, fill = 0)
epd.display(epd.getbuffer(image.rotate(90)))
time.sleep(2)
# read bmp file
logging.info("2.read bmp file...")
image = Image.open(os.path.join(picdir, '1in54.bmp'))
epd.display(epd.getbuffer(image))
time.sleep(2)
# read bmp file on window
logging.info("3.read bmp file on window...")
epd.Clear(0xFF)
image1 = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
bmp = Image.open(os.path.join(picdir, '100x100.bmp'))
image1.paste(bmp, (50,50))
epd.display(epd.getbuffer(image1))
time.sleep(2)
# partial update
logging.info("4.show time...")
time_image = image1
# Image.new('1', (epd.width, epd.height), 255)
epd.displayPartBaseImage(epd.getbuffer(time_image))
epd.init(1) # into partial refresh mode
time_draw = ImageDraw.Draw(time_image)
num = 0
while (True):
time_draw.rectangle((10, 10, 120, 50), fill = 255)
time_draw.text((10, 10), time.strftime('%H:%M:%S'), font = font, fill = 0)
newimage = time_image.crop([10, 10, 120, 50])
time_image.paste(newimage, (10,10))
epd.displayPart(epd.getbuffer(time_image))
num = num + 1
if(num == 20):
break
logging.info("Clear...")
epd.init(0)
epd.Clear(0xFF)
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd1in54_V2.epdconfig.module_exit(cleanup=True)
exit()