|
|
@@ -1,39 +1,58 @@
|
|
|
|
|
|
+import os as _os
|
|
|
+fontpath = _os.path.realpath(_os.path.join(__file__,"..","..","wavesharelib","pic", 'Font.ttc'))
|
|
|
+
|
|
|
+def update_qr(args):
|
|
|
+ from waveshare_epd import epd2in13_V2
|
|
|
+ from PIL import Image,ImageDraw
|
|
|
+ import qrcode
|
|
|
+ epd = epd2in13_V2.EPD()
|
|
|
+ epd.init(epd.FULL_UPDATE)
|
|
|
+ image = Image.new('1', (epd.height, epd.width), 0)
|
|
|
+ qr = qrcode.QRCode(version=1, box_size=3, border=1)
|
|
|
+ qr.add_data(args.text)
|
|
|
+ qr.make()
|
|
|
+ pic = qr.make_image().get_image()
|
|
|
+ image.paste(pic, (int(epd.height-pic.width),0), pic)
|
|
|
+ epd.display(epd.getbuffer(image))
|
|
|
+ epd.sleep()
|
|
|
+ epd.Dev_exit()
|
|
|
+
|
|
|
def update_quote(args):
|
|
|
import logging
|
|
|
from waveshare_epd import epd2in13_V2
|
|
|
- import time
|
|
|
from PIL import Image,ImageDraw
|
|
|
import simpilib
|
|
|
|
|
|
- import os
|
|
|
- fontpath = os.path.realpath(os.path.join(__file__,"..","..","wavesharelib","pic", 'Font.ttc'))
|
|
|
-
|
|
|
-
|
|
|
- text = simpilib.getQuote()
|
|
|
+ quote = simpilib.getQuote()
|
|
|
+ if not quote:
|
|
|
+ return
|
|
|
+ pic = simpilib.convert_qr(quote)
|
|
|
+ text = quote["content"]
|
|
|
|
|
|
epd = epd2in13_V2.EPD()
|
|
|
logging.info("init and Clear")
|
|
|
epd.init(epd.FULL_UPDATE)
|
|
|
- epd.Clear(0xFF)
|
|
|
- image = Image.new('1', (epd.height, epd.width), 255)
|
|
|
+ # epd.Clear(0xFF)
|
|
|
+ image = Image.new('1', (epd.height, epd.width), 0)
|
|
|
+ image.paste(pic, (int(epd.height-pic.width),0), pic)
|
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
- text, longline = simpilib.wrapText(text)
|
|
|
+ text, longline = simpilib.wrapText(text, line_width_factor=3)
|
|
|
font = simpilib.loadFontSize(text, draw, image, fontpath)
|
|
|
|
|
|
w, h = draw.textsize(text, font=font)
|
|
|
|
|
|
# epd parameters are rotated 90°
|
|
|
center = [
|
|
|
- int((epd.height-w)/2),
|
|
|
- int((epd.width-h)/2)
|
|
|
+ int((epd.height - pic.width - w)/2),
|
|
|
+ int((epd.width-h)/2),
|
|
|
]
|
|
|
# leave some space for low characters
|
|
|
- center[1] = center[1] - 5
|
|
|
+ center[1] = center[1] - 3
|
|
|
|
|
|
- print("Drawing:", (w, h), (epd.height, epd.width))
|
|
|
- draw.text(center, text, align="center", font = font, fill = 0)
|
|
|
+ print("Drawing:", (w, h), (epd.height, epd.width), center)
|
|
|
+ draw.text(center, text, align="center", font = font, fill = 255)
|
|
|
|
|
|
# epd.display(epd.getbuffer(image.rotate(180)))
|
|
|
epd.display(epd.getbuffer(image))
|