Added background images and configured stats

main
parent c06fbfde4c
commit 63543d6c1e

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

@ -8,7 +8,9 @@
from secrets import * from secrets import *
pluginpath="plugin/DisplayLayerProgress/values" pluginpath="plugin/DisplayLayerProgress/values"
printerpath="api/printer"
fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}" fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}"
fullurltwo=f"{octoprint}/{printerpath}?apikey={apikey}"
# CODED FOR WAVESHARE 4.2" 400x300 B&W ePaper Display # CODED FOR WAVESHARE 4.2" 400x300 B&W ePaper Display
# Requires the DisplayLayerProgress plugin # Requires the DisplayLayerProgress plugin
@ -16,8 +18,7 @@ fullurl=f"{octoprint}/{pluginpath}?apikey={apikey}"
import sys import sys
import os import os
import json import requests,datetime
import requests
imgdir = "/home/pi/epaper/img"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img')#dontask imgdir = "/home/pi/epaper/img"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'img')#dontask
libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') libdir = "/home/pi/epaper/lib"#os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir): if os.path.exists(libdir):
@ -34,56 +35,82 @@ from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
#logging.basicConfig(level=logging.INFO)
def timestr(time):
return f"{datestr(time)} {time.hour:02}:{time.minute:02}"
def datestr(time):
return f"{time.year}-{time.month:02}-{time.day:02}"
def getData(): def getData():
jsondata=requests.get(fullurl, verify=False).json() jsondata=requests.get(fullurl, verify=False).json()
jsondatatwo=requests.get(fullurltwo, verify=False).json()
jobdata={ jobdata={
"file":jsondata["currentFilename"], "file":jsondata["currentFilename"].split('/')[-1],
"layer":jsondata["layer"]["current"], "layer":jsondata["layer"]["current"],
"layers":jsondata["layer"]["total"], "layers":jsondata["layer"]["total"],
"lastlayertime":jsondata["layer"]["lastLayerDuration"], "lastlayertime":jsondata["layer"]["lastLayerDuration"],
"percent":jsondata["print"]["progress"], "percent":jsondata["print"]["progress"],
"eta":jsondata["print"]["timeLeft"], "eta":jsondata["print"]["timeLeft"],
"remaining":jsondata["print"]["timeLeftInSeconds"] } "remaining":jsondata["print"]["timeLeftInSeconds"],
return jobdata "bedtemp":jsondatatwo["temperature"]["bed"]["actual"],
"bedtarget":jsondatatwo["temperature"]["bed"]["target"],
"temp":jsondatatwo["temperature"]["tool0"]["actual"],
"target":jsondatatwo["temperature"]["tool0"]["target"],
}
return (jobdata,datetime.datetime.now())
print(getData())
sys.exit(0)
try: try:
logging.info("Octopi print monitor starting...") logging.info("Octopi print monitor starting...")
# INIT
epd = epd4in2.EPD() epd = epd4in2.EPD()
logging.info("init and Clear") logging.info("init and Clear")
epd.init() epd.init()
epd.Clear() epd.Clear()
font14 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 14)
font16 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 16)
font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18) font18 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 18)
font20 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 20)
font24 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 24) font24 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 24)
font35 = ImageFont.truetype(os.path.join(imgdir, 'Font.ttc'), 35) # LOCS
# filename (60,6) file
# Drawing on the Horizontal image # percent (125,45) percent
logging.info("1.Drawing on the Horizontal image...") # eta (265,45) eta
Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame # layer (125,85) layer
draw = ImageDraw.Draw(Himage) # total (125,125) layers
draw.text((10, 0), 'hello world', font = font24, fill = 0) # lastlayer (125,162) lastlayertime
draw.text((10, 20), '4.2inch e-Paper', font = font24, fill = 0) # lastupdate (117,250)
draw.text((150, 0), u'微雪电子', font = font24, fill = 0) # lastrefresh (117,278)
draw.line((20, 50, 70, 100), fill = 0)
draw.line((70, 50, 20, 100), fill = 0) # MONITOR LOOP
draw.rectangle((20, 50, 70, 100), outline = 0) while True:
draw.line((165, 50, 165, 100), fill = 0) (jobdata,lastupdate)=getData()
draw.line((140, 75, 190, 75), fill = 0) paper = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
draw.arc((140, 50, 190, 100), 0, 360, fill = 0) draw = ImageDraw.Draw(paper)
draw.rectangle((80, 50, 130, 100), fill = 0) # LOAD OUR BACKGROUND
draw.chord((200, 50, 250, 100), 0, 360, fill = 0) bg = Image.open(os.path.join(imgdir, 'backgroundv2.bmp'))
epd.display(epd.getbuffer(Himage)) paper.paste(bg, (0, 0))
time.sleep(2) # ADD OUR TEXT
if len(jobdata['file']) < 20:
# logging.info("3.read bmp file") draw.text((60, 6), jobdata['file'], font = font18, fill = 0)
# Himage = Image.open(os.path.join(imgdir, '4in2.bmp')) else:
# epd.display(epd.getbuffer(Himage)) draw.text((60, 1), jobdata['file'][0:35], font = font18, fill = 0)
# time.sleep(2) draw.text((60, 17), jobdata['file'][35:70], font = font18, fill = 0)
draw.text((125,42), f"{jobdata['percent']}%", font=font24, fill=0)
draw.text((268,42),jobdata['eta'],font=font24,fill=0)
draw.text((125,82),jobdata['layer'],font=font24,fill=0)
draw.text((125,122),jobdata['layers'],font=font24,fill=0)
draw.text((125,162),jobdata['lastlayertime'],font=font20,fill=0)
draw.text((117,250),timestr(lastupdate),font=font14,fill=0)
draw.text((117,278),timestr(datetime.datetime.now()),font=font14,fill=0)
# (240,82) under ETA
draw.text((25,228),f"{jobdata['bedtemp']}°c/{jobdata['bedtarget']}°c {jobdata['temp']}°c/{jobdata['target']}°c",font=font14,fill=0)
# DISPLAY OUR MASTERPIECE
epd.display(epd.getbuffer(paper))
epd.sleep()
#time.sleep(30)
sys.exit(0)
# logging.info("4.read bmp file on window") # logging.info("4.read bmp file on window")
# Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame # Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
# bmp = Image.open(os.path.join(imgdir, '100x100.bmp')) # bmp = Image.open(os.path.join(imgdir, '100x100.bmp'))
@ -91,9 +118,6 @@ logging.info("Octopi print monitor starting...")
# epd.display(epd.getbuffer(Himage2)) # epd.display(epd.getbuffer(Himage2))
# time.sleep(2) # time.sleep(2)
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e: except IOError as e:
logging.info(e) logging.info(e)

Loading…
Cancel
Save