-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartial_update_test.py
60 lines (51 loc) · 1.54 KB
/
partial_update_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
#!/usr/bin/python
import os
import logging
from waveshare_epd import epd4in2_V2
from PIL import Image,ImageDraw,ImageFont
#initialize some vars
logging.basicConfig(level=logging.DEBUG)
font18 = ImageFont.truetype('Font.ttc', 11)
text = ""
def init_display():
#initialize and clear display
epd = epd4in2_V2.EPD()
#logging.info("init and Clear")
epd.init()
epd.Clear()
return epd
def init_image(epd):
#logging.info("Draw Image")
draw_image = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
#logging.info("set image object")
draw = ImageDraw.Draw(draw_image)
return draw,draw_image
def partial_update_text(draw, draw_image,text, epd):
logging.info("draw text")
draw.rectangle((0, 0, 400, 300), fill = 255)
draw.text((5, 5), text, font = font18, fill=0)
epd.display_Partial(epd.getbuffer(draw_image))
def cleanup(epd):
# Cleanup and sleep
epd.init()
epd.Clear()
epd.sleep()
epd = init_display() #initialize the display one time.
draw, draw_image = init_image(epd)
while True:
try:
count = 0
while True:
if(count < 10):
str_count = str(count)
text = text + " " + str_count
partial_update_text(draw, draw_image, text, epd)
count = count + 1
break
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in2_V2.epdconfig.module_exit(cleanup=True)
cleanup(epd)
exit()